Table [Sales_price]
Sales_price 테이블의 칼럼...
daily_code varChar 일별매출번호
timestamp datetime 매출 시간
menu_name varChar 메뉴 이름
menu_price int 메뉴가격
pay_type int 결제 타입 -- 1=카드 , 2=현금영수증 , 3 = 현금
매출이 생기면 이 테이블에 데이터가 쌓이는 형식입니다.
지금 날짜 별로는 불러올수 있는데
아래가 쿼리문 입니다.
select * from
(select count(daily_code) as card_cnt ,sum(pay_price) as card_total from Sales_price where timestamp BETWEEN '2016-09-02' AND '2016-09-02 23:59' and pay_type=1) card,
(select count(daily_code) as cr_cnt ,sum(pay_price) as cr_total from Sales_price where timestamp BETWEEN '2016-09-02' AND '2016-09-02 23:59' and pay_type=2 ) cr,
(select count(daily_code) as c, sum(pay_price) as c_total from Sales_price where timestamp BETWEEN '2016-09-02' AND '2016-09-02 23:59' and pay_type=3) c
근데 여기서 일정 시간대별을 보고 싶어요
예를 들어서 09시~12시
13시~14시 뒤에 조건을 어떻게 두어야지 일정 시간대 별로 데이터를 뽑아 올수 있나요?
날짜는 한달, 일주일, 오늘 , 어제 이렇게 지정하고, 시간대는
BETWEEN 09:00 and 12:00 이런식으로
날짜별 기간동안 , 지정한 특정시간대 데이터만 뽑아와서 보고 싶은데
뒤에 조건을 어떻게 주어야 하나요?
답변 부탁드립니다.
|