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

The Archive Base Latest Questions

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

basically on the following lines where I have the two cases, it keeps returning

  • 0

basically on the following lines where I have the two cases, it keeps returning the ELSES even though track_id is matched in the driver stats table for that driver_id as that is what I am grouping the query by. If I am doing this wrong, then what I need is if there are no rows in the driver_stats table then it gets the value from the drivers table and the growth is set to 0. Any help is greatly appreciated.

Case s.value When track_id = (SELECT MAX(track_id) FROM driver_stats) Then s.value Else  d.value End AS value,
Case s.growth When track_id = (SELECT MAX(track_id) FROM driver_stats) Then s.growth Else 0 End AS growth,

**//FULL QUERY**
SELECT d.drivers_id, d.drivername, t.code,
Case s.value When track_id = (SELECT MAX(track_id) FROM driver_stats) Then s.value Else  d.value End AS value,
Case s.growth When track_id = (SELECT MAX(track_id) FROM driver_stats) Then s.growth Else 0 End AS growth,
SUM(IF(qual_pos = '1', 1,0)) AS poles,
SUM(IF(race_pos <= '3', 1,0)) AS podiums,
SUM(IF(race_pos = '1', 1,0)) AS victories,
COALESCE(SUM(overtakes),0) AS overtakes,
SUM(Case When s.track_id = (SELECT MAX(track_id) FROM driver_stats) Then points Else 0 End) lastracepoints,
COALESCE(SUM(points),0) AS points
FROM drivers d
Left Join driver_stats s
On s.drivers_id = d.drivers_id
Left Join teams t
On t.team_id = d.team_id
Group By d.drivers_id
ORDER BY d.drivers_id

Just for knowledge the table driver_stats has a row for each driver_id and for each track_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-29T19:03:30+00:00Added an answer on May 29, 2026 at 7:03 pm

    When you add the value between case and when, you should only add the value, and not the comparison.
    Else MySQL will compare s.value to true, and it will be always false.

    You have two options:

    Case When track_id = (SELECT MAX(track_id) FROM driver_stats) Then s.value Else  d.value End AS value,
    

    or

    Case s.value When (SELECT MAX(track_id) FROM driver_stats) Then s.value Else d.value End AS value,
    

    Anyway, in mySQL the next query would be easier to read:

    if(s.value=SELECT MAX(track_id) FROM driver_stats, s.value, d.value) as value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, basically it is performing two operations. First one being
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I basically have the following string in the format: A,B,C:D,E,F What I am trying
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
Basically, I have the following so far: class Foo { public override bool Equals(object
I currently have the following lines of code in a script: set -A ARRAY
I tried the following: Basically, it should say: If there's no cookie, get lang
I want to build a bot that basically does the following: Listens to the
The following seems strange.. Basically, the somedata attribute seems shared between all the classes
EDIT: I am basically running into the following documented issue . I am using

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.