sql - Get a count of a number of records with same create date -
i have table containing records create date. want select records created in january 2014 , have count of how many created each day. i've gotten far selecting records created month i'm unsure how proceed output of days month , count of how many records created.
select type ,part_id ,desired_qty ,received_qty ,create_date work_order datepart(year,create_date) = 2014 , datepart(month,create_date) = 01 order create_date asc
the information i'm selecting in statement isn't important, it's there in query i'm selecting something.
is looking for? aggregation query count:
select cast(create_date date) date, count(*) work_order datepart(year, create_date) = 2014 , datepart(month, create_date) = 01 group cast(create_date date) order cast(create_date date) ;
the cast()
needed if create_date
have time component. reason query uses cast()
same structure work on multiple months.
i want add, better write query this:
select cast(create_date date) date, count(*) work_order create_date >= '2014-01-01' , create_date < '2014-02-01' group cast(create_date date) order cast(create_date date) ;
the difference here where
clause. formulation can make use of index on create_date
. formulation has functions around arguments, not use index.
Comments
Post a Comment