I'm trying to extract how many times a particular thing happened on each day of the week. Here is what I tried:
SELECT Source , Event, Qty, DateName(WEEKDAY,( TranDate )) As DayOfWk
FROM OurDB
GROUP BY Source, Event, DateName(WEEKDAY,( TranDate )), Qty
But it isn't grouping by Source (which only has two possible values). If I take out the DateName function, then everything groups correctly. Basically I'm looking to get:
EDIT: Added row data
OurDB:
Desired Output:
SELECT Source , Event, max(Qty) --or min of qty
,DateName(WEEKDAY,( TranDate )) As DayOfWk
FROM OurDB
GROUP BY Source, Event, DateName(WEEKDAY,( TranDate ))
Your query didnot have a aggregate
function. From the expected result, it looks like you have to use a aggregate
function on Qty column.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.