New answers tagged case
1
You can't reference a column alias within the same SELECT clause as it was created in. In other words sum("total_time") is referencing something that doesn't exist yet. You'll either need to copy your previous CASE statement into your SUM() function call like this:
SUM
(
CASE when lunch = 1 then round(Cast (( JulianDay(clock_out) - JulianDay(...
1
This is probably the easiest way. You could also use a Common Table Expression, but it would make no real difference; it's a matter of style preference.
SELECT
x.name,
x.database_id,
x.create_date,
x.diff,
CASE
WHEN x.diff >= -50 AND x.diff < 0 THEN '-50+'
WHEN x.diff >= 0 AND x.diff < 50 THEN '0+'
...
Top 50 recent answers are included
Related Tags
case × 157sql-server × 51
mysql × 30
oracle × 26
postgresql × 17
t-sql × 13
group-by × 11
query × 9
join × 8
select × 7
update × 7
order-by × 6
null × 6
sum × 6
performance × 5
sql-server-2008 × 5
stored-procedures × 5
sql-server-2008-r2 × 4
db2 × 4
datetime × 4
date × 4
where × 4
sql-server-2014 × 3
sql-server-2016 × 3
oracle-12c × 3