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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:00:26+00:00 2026-06-11T00:00:26+00:00

SELECT ROUND(AVG(((total – `order`) / total) * 100), 2) AS score FROM rankings INNER

  • 0
SELECT ROUND(AVG(((total - `order`) / total) * 100), 2) AS score 
FROM rankings
INNER JOIN ranking_data 
    ON ranking_id = rankings.id 
    AND opinion_id = {$opinion_id} 
    AND `type` = '{$type}'
INNER JOIN (
    SELECT rankings.id, COUNT(*) as total 
    FROM rankings
    INNER JOIN ranking_data 
        ON ranking_id = rankings.id AND `type` = '{$type}'
    WHERE case_id = {$case_id}
) AS total_table ON total_table.id = rankings.id
WHERE case_id = {$case_id};

MySQL Tables: http://pastebin.com/jKvUrrNi

Short Explanation:

The issue here is that there are two parts I need to perform this grading calculation. One row, and a total of related rows. The COUNT() function is messing up my selections. In the sub-query its not allowing me to select ON the current rankings.id (of the outer query) because the COUNT function reduces the results to one row before the filtering takes place. What I need is to somehow pass the id as a parameter in the sub-query’s WHERE clause. This is only one idea to get the desired results, but there might be a better way if you understand the application (explained below).

Long Explanation:

Thie application allows users to rank opinions related to medical cases, for statistical purposes. There are two types of ranking which are computed the same way – pre-reference and post-reference. That reflects how the user chose to rank the opinions before they saw the reference (in the cases table) and afterward. opinion_list wer are not using at this time.

The rankings table stores one instance of a user going through the ranking process, and the ranking_data table stores the actual submitted data. The ranking page asks users to order opinions in order of preference, top being the best. This query is supposed to calculate the Collabograde score, which would be the amount people favored their opinion over others.

Users who enter the app first login, then submit their own opinion to the case, then rank their opinion against the others already submitted. Everyone does the same.
For example, lets say I just submitted my opinion and started ranking. There are 4 opinions including my own in the system and no other rankings yet (although there would be one ranking per opinion typically). If I ranked my opinion at second best, then my Collabograde score would be 2/4. When user2 goes through the same ranking process and ranks my opinion at first best, then it becomes 3/8.

So for the query, order is 0 for best and so on. The query is supposed to calculate the Collabograde score for one user and one case. The opinion_id of the user’s submission in the case is retrieved in a previous query. I first try to get the position of that opinion_id in all rankings, and then I get the total number of ranking_data rows for the currently selected rankings row. I use those values to calculate the result.
So I am calculating one ‘score’ per rankings row, and then averaging them together to create the score for the entire case.

Geniuses far and wide, what can I do?

  • 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-11T00:00:27+00:00Added an answer on June 11, 2026 at 12:00 am

    You want to group the subquery by rankings.id, so add GROUP BY rankings.id:

    SELECT ROUND(AVG(((total - `order`) / total) * 100), 2) AS score 
    FROM rankings
    INNER JOIN ranking_data 
        ON ranking_id = rankings.id 
        AND opinion_id = {$opinion_id} 
        AND `type` = '{$type}'
    INNER JOIN (
        SELECT rankings.id, COUNT(*) as total 
        FROM rankings
        INNER JOIN ranking_data 
            ON ranking_id = rankings.id AND `type` = '{$type}'
        WHERE case_id = {$case_id}
        GROUP BY rankings.id
    ) AS total_table ON total_table.id = rankings.id
    WHERE case_id = {$case_id};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT DATE(DTM) AS 'Dia', ROUND(AVG(TMP)-10) AS 'Graus Dia', (SELECT ROUND(AVG(TMP),1) FROM dados_meteo WHERE HOUR(DTM)>=18
(SELECT * FROM table1 INNER JOIN table2 ON table1.id = table2.id) AS t1 JOIN
select round(product_qty * 100) - product_qty as test, id, product_qty from stock_move where product_id=63
This is my MySQL query: SELECT ROUND( AVG(p.votes), 2) AS 'votes', games.* FROM games
How to round with no trailing zeros in SQL Server 2005? select round(100.5555, 2)
Is trunc and round the same with negative arguments? SQL> select round(123456.76,-4) from dual;
I'm trying to introduce a join to this query: SELECT `n`.*, round((`n`.`rgt` - `n`.`lft`
SELECT Id,Date,Name FROM people WHERE DATEPART(hh,Date) >= 7 AND DATEPART(hh,Date) <= 8 Order by
This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from
i am trying this query SELECT round( avg( DATEDIFF( CURRENT_DATE, age ) /365 )

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.