mysql 날짜 관련 질문 드립니다!

조회수 665회

안녕하세요 21살 서비스기획자로 재직중인 사회 초년생입니다!

회사에서 mysql을 공부하며 매출 등 데이터를 관리하는 일을 배우고 있습니다.

현재 생산량을 결정할 때 참고할 수 있는 데이터 테이블을 만들고 있으며

새벽 배송때문에 질문 드리게 되었습니다.

제가 작성한 코드에 지역 매출같은 경우에는 당일 배송이라 serve_at(유저에게 제공된 시간)으로 할 수 있습니다.

하지만 새벽 배송 같은경우는 serve_at 이 + day 1 이기 때문에 제대로된 매출을 잡을 수 없습니다.

게다가 having절을 통해서 요일별로 구분하려 하기 때문에 좀 더 꼬인 것 같습니다.

제가 궁금한점은 새벽 배송에게만

where serve_at between '2014-04-09 00:00:00' and now() + interval 1 day를

해줄 수 있을까요?

select 

concat (year(serve_at),
'-', month(serve_at),
'-',day(serve_at)) as 날짜,

case dayofweek(serve_at)
when '1' then '일'
when '2' then '월'
when '3' then '화'
when '4' then '수'
when '5' then '목'
when '6' then '금'
when '7' then '토' -- 요일


end as week,

sum(om.total_price)as 매출
,sum(if(ua.area = 'seoul-1', total_price, null)) as 강남매출
,sum(if(ua.area = 'SE-SC-SC-1', total_price, null)) as 서초매출
,sum(if(ua.area = 'SE-GN-YS-1', total_price, null)) as 역삼매출
,sum(if(ua.area = 'seoul-2', total_price, null)) as 송파매출
,sum(if(ua.area = 'SE-SP-MJ-1', total_price, null)) as 문정매출
,sum(if(ua.area = 'kurly', total_price, null)) as 새벽매출



from order_meta  as om

join user_address as ua on om.address_idx = ua.idx

where serve_at between '2014-04-09 00:00:00' and now()

group by concat(year(serve_at),
'-', month(serve_at),
'-', day(serve_at))

having week = '월'

order by serve_at desc limit 3



1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)