Can we use group by and where condition with same fieldname

前端 未结 2 1382
天命终不由人
天命终不由人 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:45

    Absolutely. It will result in filtering the records on your date range and then grouping it by each day where there is data.

    It should be noted that you will only be able to select the startdate and then whatever aggregates you're calculating. Otherwise, it should work perfectly fine.

    For example, this query will give you a count of employees for each startdate:

    SELECT startdate, count(*)
    FROM employees 
    WHERE startdate >= '15-jan-2011' 
          AND startdate <= '20-aug-2011'
    GROUP BY startdate
    

提交回复
热议问题