Can we use group by and where condition with same fieldname

前端 未结 2 1384
天命终不由人
天命终不由人 2021-02-15 06:00

I have a requirement like have to pull all records in the date range the user selected, selecting all employees who started from 15-Jan-2011 to 20-Aug-2011 and group by date.

2条回答
  •  既然无缘
    2021-02-15 06:47

    You can, but the "GROUP BY" clause is used for grouping together sets of rows, so it does not make sense for your question (or anything that involves a "SELECT *").

    To answer your question though:

    SELECT DATEADD(dd, 0, DATEDIFF(dd,0,StartDate)) AS 'StartDate', 
    FROM   Employees
    WHERE  StartDate BETWEEN '15-Jan-2011' AND '20-Jan-2011'
    ORDER BY StartDate
    

    Note: the stripping of the time from the date came from here

提交回复
热议问题