I have a bunch of product orders and I'm trying to group by the date and sum the quantity for that date. How can I group by the month/day/year without taking the time part into consideration?
3/8/2010 7:42:00
should be grouped with 3/8/2010 4:15:00
9条答案
按热度按时间pod7payv1#
Cast/Convert the values to a
Date
type for your group by.xxe27gdn2#
Or in SQL Server 2008 onwards you could simply cast to
Date
as @Oded suggested:p8ekf7hl3#
In pre Sql 2008 By taking out the date part:
sqxo8psd4#
CAST datetime field to date
edqdpe6u5#
ff29svar6#
Here's an example that I used when I needed to count the number of records for a particular date without the time portion:
0wi1tuuw7#
Here is the example works fine in oracle
vojdkbi08#
Well, for me it was pretty much straight, I used cast with groupby:
Example:
Note: I am using this on MSSQL 2016.
l2osamch9#
I believe you need to group by , in that day of the month of the year . so why not using TRUNK_DATE functions . The way it works is described below :