假设有一张桌子 - 餐厅
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]
现在我想要在过去5天内获得最高的比尔支付。我应该使用什么查询?
答案应该是3000而不是4000 请帮帮我。
答案 0 :(得分:1)
select *
from Restaurant
where bill = (select MAX(bill) from Restaurant
where date_time BETWEEN DATE_SUB(NOW(),INTERVAL 5 DAY) AND NOW() );
答案 1 :(得分:0)
假设您在当前日期前五天计算
SELECT MAX(bill) FROM restaurant_table
WHERE DATE_TIME BETWEEN
DATE_SUB(NOW(), INTERVAL 5 DAY)
AND NOW();
答案 2 :(得分:0)
假设您想要从当前日期开始的前五天数据
SELECT MAX(BIL) FROM resturant
WHERE DATE_TIME
BETWEEN
DATE_SUB(NOW(), INTERVAL 5 DAY) AND
NOW();
答案 3 :(得分:0)
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;
我希望它能奏效。