| Author |
Topic |
|
coolrefche
Starting Member
4 Posts |
Posted - 2008-07-15 : 03:45:14
|
| Hi,My brain has completely frozen... I need some help.I have written a basic query to extract some details from a database:select datecreated, count(*) as "No of Items" from Sale_Items (nolock) where customerid = 2 group by datecreated order by datecreated descDate/Time Created, No Items2005-10-26 14:31:27.000, 12005-10-20 16:57:18.000, 12005-10-20 16:55:15.000, 12005-10-20 16:53:49.000, 12005-10-20 16:53:19.000, 12005-10-20 16:52:38.000, 12005-10-20 16:51:59.000, 1I want to group these results by date, get a sum of how many items are sold per day.I would appreciate any help...Regards |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-15 : 03:48:46
|
[code]SELECT DATEADD(DAY, DATEDIFF(DAY, 0, datecreated), 0), COUNT(*) AS "No of Items"FROM Sale_Items (NOLOCK)WHERE customerid = 2GROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, datecreated), 0) ORDER BY datecreated DESC[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-15 : 03:49:05
|
[code]DECLARE @Sample TABLE (Created DATETIME, Items INT)INSERT @SampleSELECT '2005-10-26 14:31:27.000', 1 UNION ALLSELECT '2005-10-20 16:57:18.000', 1 UNION ALLSELECT '2005-10-20 16:55:15.000', 1 UNION ALLSELECT '2005-10-20 16:53:49.000', 1 UNION ALLSELECT '2005-10-20 16:53:19.000', 1 UNION ALLSELECT '2005-10-20 16:52:38.000', 1 UNION ALLSELECT '2005-10-20 16:51:59.000', 1SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', Created), '19000101') AS Created, SUM(Items) AS ItemsFROM @SampleGROUP BY DATEDIFF(DAY, '19000101', Created)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 03:49:53
|
| select dateadd(day,datediff(day,0,datecreated),0) as datecreated, count(*) as "No of Items" from Sale_Items (nolock) where customerid = 2 group by dateadd(day,datediff(day,0,datecreated),0) order by dateadd(day,datediff(day,0,datecreated),0) descMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 03:50:41
|
MadhivananFailing to plan is Planning to fail |
 |
|
|
coolrefche
Starting Member
4 Posts |
Posted - 2008-07-15 : 03:52:13
|
| Thank you very much...Its working.When you know it, its easy... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-15 : 03:56:43
|
Why are you both using COUNT?What did I miss? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-15 : 04:05:16
|
OP wanted "No of Items" so it is a count(*) of the sales items table KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-15 : 04:13:02
|
Oh, so the supplied data is NOT sample data? It is expected output, or his attempt to output? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-15 : 04:15:12
|
output of existing query KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|