Help: a little flower SQL problem

Table structure description:

Employee ID (Wei Yi), meal time
P0001 2013/10/29 9:00:00
P0002 2013/10/29 9:00:00
P0003 2013/10/29 9:00:00
P0001 2013/10/29 15:00:00
P0002 2013/10/29 15:00:00
P0003 2013/10/29 15:00:00
P0001 2013/10/30 9:00:00
P0002 2013/10/30 9:00:00
P0003 2013/10/30 9:00:00

Requirement: three meals a day, no matter he is today to eat a few meals, eat, on a total of +1 as a meal in days, and ultimately obtained all the people, eating days in a period of time.
Kneel to thank

Started by Amanda at November 12, 2016 - 12:20 PM

SELECT [Te_user],Min([Te_time]) As the first meal time, COUNT (*) as meal times
FROM [Te_Eat]
group by [Te_user], year([Te_time]),datepart(dayofyear,[Te_time])

Posted by Matthew at November 16, 2016 - 12:26 PM

Select ID staff, count (dinner time) as from dinner group by staff dining days ID having between and meal time start time end time
Among them, dinner (temporarily take) is your this table table name, start time and end time is you define.

Posted by Colbert at November 18, 2016 - 12:30 PM

count(distinct CONVERT(varchar(12),Meal time,112)) ,
Employee ID (from ubox_double_record only)
Where > XXX and lunch; lunch<XXX
Group by ID (staff only)

In fact, thinking is not difficult, to convert the time unified only date format, then distinct can remove the number does not repeat

Posted by Luke at November 27, 2016 - 1:17 PM