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

  • Home
  • SEARCH
  • 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 7861835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:53:50+00:00 2026-06-02T22:53:50+00:00

Let say, I’ve a table in my database like this be it in POSTGRESQL

  • 0

Let say, I’ve a table in my database like this be it in POSTGRESQL or MYSQL :-

video_clip_name | bad | so_so | good|
video 1         | 20  | 13    | 3   |
video 2         | 12  | 20    | 33  |
video 3         | 40  | 34    | 33  |
video 4         | 20  | 23    | 13  |
video 5         | 20  | 13    | 37  |

I want to determine which video is rated as bad or so_so or good based on highest score after comparison is made between the three column (bad,so_so and good). Let say, video 1 has bad rating which is higher than the other two columns..this mean that video 1 has been rated as bad.

So my question is how to write such SQL statement in POSTGRESQL/MYSQL to output the overall rating for each video based on comparison between the three columns’ value?

thank you

  • 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-02T22:53:58+00:00Added an answer on June 2, 2026 at 10:53 pm

    Here is another way using CASE expression. I use SQL Server and not MySQL or PostGreSQL but I think this ANSI SQL compliant. The sample data and output uses various values. However, it they are all equal it currently will pick the rating in the order bad, *so_so* and good.

    Script:

    CREATE TABLE dbo.VideoRatings 
    (
            video_clip_name VARCHAR(10) NOT NULL
        ,   bad             INT         NOT NULL
        ,   so_so           INT         NOT NULL
        ,   good            INT         NOT NULL
    );
    
    INSERT INTO  dbo.VideoRatings (video_clip_name, bad, so_so, good) VALUES
        ('video a', 1, 2, 3),
        ('video b', 2, 3, 1),
        ('video c', 3, 2, 1),
        ('video d', 2, 1, 1),
        ('video e', 1, 2, 2),
        ('video f', 1, 1, 2),
        ('video g', 2, 2, 2);
    
    SELECT  video_clip_name
        ,   CASE 
                WHEN bad    >= so_so    AND bad     >= good     THEN 'bad'
                WHEN so_so  >= bad      AND so_so   >= good     THEN 'so_so'
                WHEN good   >= bad      AND good    >= so_so    THEN 'good'
            END AS Rating
    FROM    dbo.VideoRatings;
    

    Output:

    video_clip_name rating
    --------------- ------
    video a         good
    video b         so_so
    video c         bad
    video d         bad
    video e         so_so
    video f         good
    video g         bad
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have Customers table in a database. I'd like to create List
Let say if i've database row settings [id,user,pass,sos] I've the following mysql statement $username
Let say I have this table, A B ------- 1 A 2 C 3
Let say i've a huge database of 100,000 entries my_table (id,name) and i'd like
let say have element like this <div class=watch-me style=display: none;>Watch Me Please</div> as we
let say i have table look like below actionTable ----------- id, user, actionName, time
Let say that I have xml like this: <root> <node light=somevalue>message1</node> <node dark=somevalue>message2</node> <node>message3</node>
Let say I have an array like this: Band of Horses - Is There
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let say I have an array like: Array ( [0] => Array ( [Data]

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.