sql server - SQL different aggregates in single query -
i trying work out query have table representing following:
and need result indicate earliest start time (blue), latest end time (green), , sum of lunch breaks (yellow):
i got blue , green blocks right, struggling yellow aggregation.
my (partial) query looks like:
select name, min(starttime) starttime, max(endtime) endtime, sum( <please here alternative aggregation> ) lunch sometable group name
when use normal subquery, sql complains column not contained in either "group by" or aggregate, , cannot use subquery inside aggregate.
please point me direction "lunch" column.
this on sql server.
assuming value time, sum little challenging. suggest converting minutes:
select name, min(starttime) starttime, max(endtime) endtime, sum(case when activity = 'lunch' datediff(minute, 0, duration) end) lunch_minutes sometable group name
Comments
Post a Comment