Home > Blockchain >  SQL: Making a conditional WHERE clause?
SQL: Making a conditional WHERE clause?

Time:05-13

I'm pretty new to SQL and am struggling to get the syntax/logic correct for what I need.

Right now I have a query ending in a where statement:

WHERE business IN ('A','B','C')
AND
CASE
     WHEN queue = 'Q1' THEN (queue = 'Q1' AND queue_type = 'Y')
END

Basically I need all the results, except for data points that have queue = 'Q1'. For those instances only, I need the results to filter down to where queue_type ='Y'.

As the code stands right now, I only get results where queue = 'Q1' and queue_type = 'Y'.

Thanks for the help!

CodePudding user response:

SELECT * FROM mtable
WHERE business IN ('A','B','C')
AND (queue = 'Q1' AND queue_type = 'Y') OR (queue != 'Q1')
  •  Tags:  
  • sql
  • Related