我有下表。
"customers_dishes"
id - customer id, STRING
date - date of arriving at the restaurant, DATE
bill - total bill, DOUBLE
我试图输出所有的事件的客户,他们的帐单是大于他们的第一次约会访问餐厅的帐单
id, date, bill
Alen, 2018-03-01, 50
Alen, 2018-03-02, 48
Alen, 2019-03-01, 60
Bob, 2018-03-04, 45
Bob, 2018-03-06, 55
Bob, 2019-03-01, 50
输出应为:
id, date, bill
Alen, 2019-03-01, 60
Bob, 2018-03-06, 55
Bob, 2019-03-01, 50
试过这样做:
SELECT (*) FROM customers_dishes
WHERE date NOT IN (
SELECT date FROM customers_dishes ORDER BY id, date ASC LIMIT 1)
AND id NOT IN(
SELECT id FROM customers_dishes ORDER BY id, date ASC LIMIT 1)
有什么建议吗?
2条答案
按热度按时间qmelpv7a1#
你可以用
first_value()
:也可以使用相关子查询:
kxe2p93d2#