Hot answers tagged

1 vote

Comparing 2 count columns with case

You can use subquery or cte to make it more readable, but you don't have to. Version with subquery : select a.* , case when [30% cost]>[40% of size] then 'Y' else 'N' end as [Y/N] from ( ...
a1ex07's user avatar
  • 8,990
1 vote

Set variable on multiple case within each group

You can use MIN and MAX to check if flag 0 and 1 exists. IF MIN(flg) = 0 this means that flag 0 exists IF MAX(flg) = 1 this means that flag 1 exists. DECLARE @flg0Exists BIT = 1; DECLARE @flg1Exists ...
Sabin B's user avatar
  • 4,391
1 vote

MySQL - multiple CASE ordering with joined table

SELECT events.Name FROM events LEFT JOIN events_meta ON events.ID = events_meta.EventId GROUP BY 1 ORDER BY MIN(CASE WHEN events_meta.MetaKey = 'date' THEN events_meta.MetaValue ...
Akina's user avatar
  • 19.7k

Only top scored, non community-wiki answers of a minimum length are eligible