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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:03:14+00:00 2026-05-28T01:03:14+00:00

Basically I need to create output TOP table where users are arranged by comparing

  • 0

Basically I need to create output TOP table where users are arranged by comparing their points with admin’s points.
For example:

User3 | 0 //Everything was as admin had.
User5 | 3 //One song had 2 points different from admin and one was off by one
ect.

In my database I have three tables:

Table: rating

+------------+---------+----------+---------+ 
| rating_id  | user_id | song_id  | points  | 
+------------+---------+----------+---------+ 
| 1          | 1       | 4        | 0       | 
| 2          | 1       | 3        | 1       | 
| 3          | 3       | 2        | 3       | 
| 4          | 4       | 2        | 2       | 
| 5          | 2       | 1        | 4       |


Table: songs

+---------------+------------+ 
| song_name_id  | song_name  | 
+---------------+------------+ 
| 1             | Song1      | 
| 2             | Song2      | 
| 3             | Song3      | 
| 4             | Song4      | 
| 5             | Song5      | 

Table: users

+----------+----------+----------+
| id       | username | password |
+----------+----------+----------+
| 1        | User1    | passw    |
| 2        | User2    | wordp    |
| 3        | User3    | somet    |
| 4        | User4    | hings    |

It should be something like this (not in any programming language):

Compare user_id > 1 with user_id=1 //Let's say that the comparable admin is user_id=1
$result= ABS(user.points-admin.points)++;

And put this to array as:

username => result

Then when I sort this array by result, I can print it as top table – who got the closest result to admin!

I tryed several different solutions but never got the right result.

Can anybody help me?

UPDATE:

Thanks!

With JOIN the result is:

+------------+---------+----------+---------+-----------+
| song_id    |song_name| user_id  |username |rating_diff|
+------------+---------+----------+---------+-----------+ 
| 1          | Song1   | 1        | admin   | 0         | 
| 2          | Song2   | 1        | admin   | 0         |
...etc...

With LEFT JOIN the result is:

+------------+---------+----------+---------+-----------+
| song_id    |song_name| user_id  |username |rating_diff|
+------------+---------+----------+---------+-----------+ 
| 1          | Song1   | 11       | user2   | NULL      | 
| 1          | Song1   | 10       | user1   | NULL      |
| 1          | Song1   | 12       | user3   | NULL      |
| 1          | Song1   | 1        | admin   | 0         |
| 2          | Song2   | 11       | user2   | NULL      | 
| 2          | Song2   | 10       | user1   | NULL      |
| 2          | Song2   | 12       | user3   | NULL      |
| 2          | Song2   | 1        | admin   | 0         |

..etc..

So.. Something is wrong, the rating_diff does not work.

  • 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-28T01:03:14+00:00Added an answer on May 28, 2026 at 1:03 am

    Assuming you want this comparison on a song-by-song basis (instead of a total or average across all songs), try:

    select r.song_id,
           s.song_name,
           r.user_id,
           u.username,
           abs(r.points - r1.points) rating_diff
    from rating r
    join songs s on r.song_id = s.song_name_id
    join users u on r.user_id = u.id
    join rating r1 on r.song_id = r1.song_id and r1.user_id = 1
    order by s.song_name, abs(r.points - r1.points)
    

    This should sort the output by the song name, and then by the difference between the admin’s points and the users’ points. (Change the join on rating r1 to be a left join if you can’t guarantee an admin rating for every song.)

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

Sidebar

Related Questions

Basically I need a hosted solution, where one can create an account for a
I have a need to basically create a matrix of values in my Silverlight
Basically I need to create a quickfix buffer listing all lines that match a
Basically need to generate custom(some different then yes no) messeges(alert) in JS , how
basically need to change the value that - admin_url() returns any idea?
I basically need to highlight a particular word in a block of text. For
I basically need to show a wait window to the user. For this i
I basically need to know how to import SQL code into Access. I've tried
I basically need to check if there is an easier way to do this
I want to filter the selectable dates on a datepicker. I basically need to

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.