Suppose there is a table- Restaurant
id | order | date_time | bill(Rs.)
[1] [Fish] [2018-06-17 17:06:28] [2000]
[2] [Meat] [2018-06-16 18:08:28] [3000]
[3] [Rice] [2018-05-22 21:09:28] [4000]
Now I want the highest Bill Paid in last 5 day. What query should I use?
The answer should be 3000 not 4000.
Please help me out.
select *
from Restaurant
where bill = (select MAX(bill) from Restaurant
where date_time BETWEEN DATE_SUB(NOW(),INTERVAL 5 DAY) AND NOW() );
assuming that you are calculating five days before current date
SELECT MAX(bill) FROM restaurant_table
WHERE DATE_TIME BETWEEN
DATE_SUB(NOW(), INTERVAL 5 DAY)
AND NOW();
Assuming that you want previous five days data from current date
SELECT MAX(BIL) FROM resturant
WHERE DATE_TIME
BETWEEN
DATE_SUB(NOW(), INTERVAL 5 DAY) AND
NOW();
select id,order,date_time,max(sum(bill)) as paid_bill from restaurant
where date_time between (NOW(), INTERVAL 5 DAY) and NOW()
group by order;
i hope it will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.