Description:
A $900 order labeled Medium? Check the order of your WHENs.
SELECT OrderID,
Amount,
CASE WHEN Amount GE 700 THEN 'Large'
WHEN Amount GE 300 THEN 'Medium'
ELSE 'Small' END AS SizeBand,
IIF(Status = 'Shipped', 'Yes', 'No') AS IsShipped
FROM dbo.Orders;
(YouTube blocks angle brackets. In SSMS, type GE as GE with no space.)
CASE stops at the first WHEN that's true. Check the biggest band first.
IIF is a one-line CASE for simple yes/no labels.
SQL function 10 of 15 every data analyst should know.
Full video: 15 SQL Server Functions Every Data Analyst Should Know (on the Query Detective channel)
#sql #sqlserver #dataanalyst #learnsql #querydetective #casewhen #iif
Share this link via
Or copy link
























