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 8329113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:39:49+00:00 2026-06-09T01:39:49+00:00

I have a table, called gcrunarrays with the columns {run_id, time_id, co2}. I have

  • 0

I have a table, called gcrunarrays with the columns {run_id, time_id, co2}. I have several thousand runs with distinct run_id’s, each with 58 time-dependent values for co2. I have a procedure to obtain the median co2 of all runs at a given time. Now, I need a select statement that will obtain the medians for each time. So far, I have

select DISTINCT A.time_id, M.co2 from gcrunarrays A, call getMedian(1, A.time_id) M
GO

Which gets a syntax error. I am fairly new at SQL and I’m working in MYSQL. I’ve tried about a dozen different ways of wording this statement but now I’m at the point where I feel like I’ve done something inherently wrong. I think it might work better if median were a function but I’m not sure even how to get the median without using a select statement. Any suggestions are greatly appreciated.

For greater clarification:

Table gcrunarrays

run_id | time_id | co2
1      | 1       | 
1      | 2       | 
...
1      | 58      | 
2      | 1       | 
...    
2      | 58      | 
3 ...

Median Procedure

CREATE PROCEDURE getMedian (IN e INT, t INT)
BEGIN
SELECT count(*), x.co2
FROM (SELECT B.exp_id, A.* FROM gcRunArrays A JOIN gcRuns B ON A.run_id=B.run_id WHERE B.exp_id=e and A.time_id=t) x, 
     (SELECT B.exp_id, A.* FROM gcRunArrays A JOIN gcRuns B ON A.run_id=B.run_id WHERE B.exp_id=e and A.time_id=t) y
GROUP BY x.co2
HAVING SUM(SIGN(1-SIGN(y.co2-x.co2))) = CEILING((COUNT(*)+1)/2);
END
GO
  • 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-06-09T01:39:51+00:00Added an answer on June 9, 2026 at 1:39 am

    Use a temp table can easily solve the issue.
    And it is not possible to use procedure results as table directly.

    Can a stored procedure/function return a table?

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

Sidebar

Related Questions

I have table called posts in my DB. Each post has field called social_network
I have a table called sellerparams with a number of columns, one of them
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have table called Direccion other called Cliente each one defined like this public
I have a table called Movies i want to select some columns from it
I have table called Reporting with following columns OutletId CampaignId ItemId Qty 10 1
Assuming I have table called events with the columns INT id DATETIME start_time DATETIME
In my oracle database I have table called PERSON with columns code, surname, forename.
I have a table called Foo and I have two columns: Lorem and Ipsum,
I have table called articles_tags which have two columns: article_id tag_id (has_and_belongs_to_many association) (I

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.