mysql - Query DB to show count of records done in the morning and the afternoon -


i have simple table (walkin2012) following fields:

id |    date    |    store   | timestamp            | custname 1  | 2013-05-08 | plainfield | 2013-05-08 10:38:40  | cust1 2  | 2013-05-08 | plainfield | 2013-05-08 13:38:40  | cust2 3  | 2013-05-09 | bayport    | 2013-05-09 20:38:40  | cust3 4  | 2013-05-10 | plainfield | 2013-05-10 17:38:40  | cust4 5  | 2013-05-10 | bayport    | 2013-05-10 11:38:40  | cust4 

i query table show number of record done between 10am-1pm morning , after afternoon per date per store give me result:

date       | store      | morning | afternoon 2013-05-08 | plainfield | 1       | 1 2013-05-09 | bayport    | 0       | 1 2013-05-10 | bayport    | 1       | 0 2013-05-10 | plainfield | 0       | 1 

i got date,store , morning work i'm confused on how subquery afternoon part. here query far:

select date, store, count(walkinid) morning  walkin2012  timestamp between concat_ws(' ',date,'10:00:00') , concat_ws(' ',date,'13:00:00')   group date,store 

any appreciated. thank much.

select  date,          store,          sum(timestamp between date + interval 10 hour ,                                date + interval 13 hour) morning,         sum(timestamp between date + interval 13 hour ,                                date + interval 24 hour) afternoon    walkin2012    group   date, store 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -