我有一个查询,我需要它只返回同一个模型/序列号上同一日期发生事件多次的结果 - 在此查询中,只要特定的函数和 eventdetails 参数在一天内出现多次。这是查询 -
SELECT DISTINCT store, tintermodel, tinterserial, eventdetails, trunc(datetime)
FROM tinter_events
WHERE tintermodel = 'FM 8000DE'
AND (datetime >= to_timestamp('2017-05-01', 'YYYY-MM-DD')
AND datetime < to_timestamp('2017-08-31', 'YYYY-MM-DD'))
AND function = 'Set Colorant Level'
AND eventdetails = 'B1[550]'
GROUP BY store, tintermodel, tinterserial, eventdetails, trunc(datetime)
ORDER BY store, SUBSTR(eventdetails,1,2), trunc(datetime);
是否像添加HAVING COUNT(*)&gt;一样简单GROUP BY短语结尾处的1?
答案 0 :(得分:1)
通过查看每个模型的每个日期的计数来检查它,从那里您将知道哪些记录只应显示在您的查询
SELECT trunc(datetime),
tintermodel,
COUNT(*)
FROM tinter_events
WHERE tintermodel = 'FM 8000DE'
AND function = 'Set Colorant Level'
AND eventdetails = 'B1[550]
GROUP BY trunc(datetime),
tintermodel
ORDER BY trunc(datetime)