sql server - SQL different aggregates in single query -


i trying work out query have table representing following:

enter image description here

and need result indicate earliest start time (blue), latest end time (green), , sum of lunch breaks (yellow):

enter image description here

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

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -