【发布时间】:2020-08-21 04:11:24
【问题描述】:
预订表
id status
1 booked
1 booked
3 cancelled
2 cancelled
2 booked
1 cancelled
1 cancelled
1 booked
select id, count(status) as tot_cancel
from tbl_booking
where id=1 and status='cancelled';
结果是
id tot_cancel
1 2
但我需要用户 id = 1 的最后 5 条记录,并且取消计数不是取消的总表记录
【问题讨论】:
-
最好举一个你想要的结果的例子
-
没有任何排序数据可以让我们了解哪些记录是最后的。
-
@airmax 。 . .您可能应该问一个新 问题。您的问题没有定义“最后一个”——SQL 表代表 unordered 集,因此除非列定义了排序,否则没有“最后一个”。此外,您应该显示您想要的结果集。
标签: mysql sql group-by count sql-order-by