79563416

Date: 2025-04-09 03:46:29
Score: 0.5
Natty:
Report link

There are multiple issues with the sql snippet you provided (which I ASSUME is going to be used in javascript during a mysql call?), given your desired result. As I understand it you would like to see a count of the rows that have a specific value for the 'code' column. Assuming you do not need the id returned as well, and only need the count:

SELECT 
  COUNT(DISTINCT CASE WHEN Code = 'S03' THEN ID END) AS CodeFound,
  COUNT(DISTINCT CASE WHEN Code != 'S03' THEN ID END) AS NoCode
FROM A

That should be enough to return it to you. If you needed to check multiple codes at the same time then it would be a good idea to use 'in' or 'not in', but I would add that you will need parentheses around the value(s) such as

not in ('S03')
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: KRoscoe45