问题601:X市建了一个新的体育馆,每日人流量信息被记录在这三列信息中:序号id
、日期visit_date
、人流量people
。请编写一个查询语句,找出人流量的高峰期。高峰期时,至少连续三行记录中的人流量不少于100
。例如,表 stadium:
对于上面的示例数据,输出为:
完整代码:
SELECT DISTINCT tab1.id, tab1.visit_date, tab1.people
FROM stadium AS tab1, stadium AS tab2, stadium AS tab3
WHERE (tab1.id+1 = tab2.id AND tab1.id+2 = tab3.id
OR tab1.id-1 = tab2.id AND tab1.id+1 = tab3.id
OR tab1.id-1 = tab2.id AND tab1.id-2 = tab3.id)
AND tab1.people >= 100
AND tab2.people >= 100
AND tab3.people >= 100
ORDER BY tab1.id;
运行结果: