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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -