I have a question about mysql date!

Asked 2 years ago, Updated 2 years ago, 37 views

Hello, incumbent a newcomer to the society as a planning service 21 years old!

I am studying mysql at the company and learning to manage data such as sales.

We are currently creating a data table that can be used to determine output.

I have a question because of the early morning delivery.

In the case of local sales in the code I wrote, it is the same-day delivery, so it can be done as serve_at (time provided to the user).

However, in the case of early morning delivery, we can't get proper sales because the serve_at is + day 1.

In addition, I think it's a little more twisted because I'm trying to distinguish it by day through the having clause.

What I'm curious about is that only early morning delivery

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

Can you do it?

select 

concat (year(serve_at),
'-', '-', month(serve_at),
'-',day(serve_at)) as date,

case dayofweek(serve_at)
When "1" then "Work"
When "2" then "Wol"
When "3" then "Hwa"
When "4" then "Su"
When "5" then "Throat"
When "6" then "Gold"
When '7' then 'to' -- day of the week


end as week,

sum(om.total_price)as revenue
,sum(if(ua.area = 'Seoul-1', total_price, null)) as Gangnam sales
,sum (if(ua.area = 'SE-SC-SC-1', total_price, null)) as Seocho Sales
,sum (if(ua.area = 'SE-GN-YS-1', total_price, null)) as reverse ginseng sales
,sum(if(ua.area = 'Seoul-2', total_price, null)) as Songpa sales
,sum (if(ua.area = 'SE-SP-MJ-1', total_price, null)) as correction sales
,sum(if(ua.area = 'kurly', total_price, null)) as early morning sales



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 = "Wall"

order by serve_at desc limit 3



mysql

2022-09-21 19:27

1 Answers

I think you can add boolean logic to the where door.

WHERE 
(Dawn delivery AND serve_at between 2014-04-0900:00:00' and now() + interval 1 day) 
OR 
(NOT dawn delivery AND serve_at between 2014-04-0900:00' and now()

How about this?


2022-09-21 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.