Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 228925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:43:23+00:00 2026-05-11T19:43:23+00:00

I have a MySQL table of correlation data that I need to extract. I

  • 0

I have a MySQL table of correlation data that I need to extract. I am running this query to find the correlation between x and y given the id; however, I need to run x.id=1 against y.id=2, 3, 4, 5… Currently, I am just running the below command multiple times for each pairing. Is there a way to speed up the query so that I can just run the query once like the second equation?

SELECT @correlation := (COUNT(x.value)*SUM(x.value*y.value) -
  sum(x.value)*sum(y.value))/SQRT((COUNT(x.value)*SUM(x.value*x.value) -
  sum(x.value)*sum(x.value))*(COUNT(y.value)*SUM(y.value*y.value) -
  sum(y.value)*sum(y.value))) AS correlation 
FROM tbl_expressions x, tbl_expressions y 
WHERE x.id=1 AND y.id=2 AND x.expressionnumber=y.expressionnumber;

SELECT @correlation := (COUNT(x.value)*SUM(x.value*y.value) -
  sum(x.value)*sum(y.value))/SQRT((COUNT(x.value)*SUM(x.value*x.value) -
  sum(x.value)*sum(x.value))*(COUNT(y.value)*SUM(y.value*y.value) -
  sum(y.value)*sum(y.value))) AS correlation 
FROM tbl_expressions x, tbl_expressions y 
WHERE x.id=1 AND y.id IN (2, 3, 4, 5, 6, 7) AND x.expressionnumber=y.expressionnumber;

I want the result to be something like this:
correlation
.83
.82
.74
.64
…

but right now the query only outputs one row (the correlation between x.id and the last y.id)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:43:23+00:00Added an answer on May 11, 2026 at 7:43 pm

    It’s hard to answer this because it’s not clear from your description what you need the query to do.

    But I would guess that you might be able to use GROUP BY to achieve what you want. I’m sorry I can’t show an example because I can’t tell what you intend the result to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL Table that looks like this: The SQL to create the
I have a MYSQL table that holds events information. I need a mechanism that
I have mysql table with data like this. record will have server with total
I have MySQL table that doesn't have AUTO_INCREMENT field. In PHP I run this
I have MySql table that has 250 fields, and i need to do an
I have a MySql table with sample data like this: +---------+---------+--------+---------------------+ | id |
I have mysql table that has a column that stores xml as a string.
I have MySQL InnoDB table utf-8 encoded. This table has only id and name
I have a MySQL table called accounts . Within this table is a field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.