Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
inq_ah
Starting Member
3 Posts |
Posted - 2011-09-11 : 12:13:58
|
| HiWell maybe it is not a simple query but i am pretty much giving up now.I have the following table - "order_transactions":Order_type_id Order_Date1001 8/24/20111004 8/24/20111003 8/11/20111004 8/24/20111001 8/11/20111002 8/22/20111002 8/22/20111004 8/15/2011I need to count how many order_types for a specific date were there:Basically expecting this:Order_Date Order_type_id Count_Of_Order_Types_Per_Date8/11/2011 1001 18/11/2011 1003 18/15/2011 1004 18/22/2011 1002 28/24/2011 1001 18/24/2011 1004 2I really appreciate any insight.Thank you,AlexAlex Melamed |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2011-09-11 : 12:19:22
|
| [code]select order_date, order_type_id, count(*) as count_of_order_types_per_datefrom order_transactionsgroup by order_date, order_type_idorder by order_date, order_type_id[/code] |
 |
|
|
inq_ah
Starting Member
3 Posts |
Posted - 2011-09-11 : 12:28:03
|
Thank you very much!I think i even tried this before - but now i see where my mistake is - I really appreciate - THANK YOU SO MUCH!!!!!I now will need to somehow truncate (I am on SQL Server) - the actual order_date, because it counts each date as distinct due to the date/time format:8/23/2011 11:07 1001 18/23/2011 14:09 1001 18/23/2011 14:11 1001 1And in my case i just need:8/23/2011 1001 1Have a Great Date!Alexquote: Originally posted by singularity
select order_date, order_type_id, count(*) as count_of_order_types_per_datefrom order_transactionsgroup by order_date, order_type_idorder by order_date, order_type_id
Alex Melamed |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-09-11 : 12:42:50
|
| http://sqlinthewild.co.za/index.php/2007/11/05/datetime-manipulation/--Gail ShawSQL Server MVP |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-11 : 12:59:11
|
| [code]select dateadd(dd,datediff(dd,0,order_date),0) as OrderDtWOTime, order_type_id, count(*) as count_of_order_types_per_datefrom order_transactionsgroup by dateadd(dd,datediff(dd,0,order_date),0), order_type_idorder by OrderDtWOTime, order_type_id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
inq_ah
Starting Member
3 Posts |
Posted - 2011-09-11 : 13:28:33
|
THANK YOU ALL!SQL folks - you are very very helpful!I hope i can do the same one day and help others...AlexP.S. I promise i will also always help with my new skills as i learn more and more..quote: Originally posted by visakh16
select dateadd(dd,datediff(dd,0,order_date),0) as OrderDtWOTime, order_type_id, count(*) as count_of_order_types_per_datefrom order_transactionsgroup by dateadd(dd,datediff(dd,0,order_date),0), order_type_idorder by OrderDtWOTime, order_type_id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Alex Melamed |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-11 : 13:37:17
|
welcome you sure can shortly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|