我尝试编写SQL查询以从表中排除某些参数。这是我的疑问:
SELECT RULE_NAME AS "Rule Name", COUNT( RULE_NAME ) AS "Event_cnt"
FROM EVENTS_VW
WITH (NOLOCK)
WHERE RULE_NAME LIKE
('Reporting_%')
AND EVENT_DT >= '2016-12-01 00:00:00.0' AND EVENT_DT <= '2016-12-31 00:00:00.0'
GROUP BY RULE_NAME ORDER BY EVENT_CNT DESC
我想在上述查询中排除的规则是:
Reporting_deleted_mail
Reporting_fwd_mail
如何修改上述查询以适应我试图排除的两条规则?
答案 0 :(得分:5)
将此添加到WHERE子句中(在GROUP BY子句之前):
AND RULE_NAME NOT IN ('Reporting_deleted_mail', 'Reporting_fwd_mail')
答案 1 :(得分:4)
WHERE RULE_NAME LIKE ('Reporting_%')
AND RULE_NAME NOT IN ('Reporting_deleted_mail', 'Reporting_fwd_mail')
答案 2 :(得分:0)
我感谢您的快速反馈。最终的解决方案是:
SELECT
RULE_NAME AS "Rule Name",
COUNT( RULE_NAME ) AS "Event_cnt"
FROM
EVENTS_VW WITH (NOLOCK)
WHERE
RULE_NAME LIKE ('Reporting_%')
AND RULE_NAME NOT IN ('Reporting_deleted_mail', 'Reporting_fwd_mail')
AND EVENT_DT >= '2016-12-01 00:00:00.0' AND EVENT_DT <= '2016-12-31 00:00:00.0'
GROUP BY
RULE_NAME
ORDER BY
EVENT_CNT DESC
谢谢你!
萨姆