我正在努力寻找如何在仅1列中放置where条件的情况。
总而言之,我想在数据库中有一列所有票证,并在另一列中包含给定日期的所有票证。
我的SQl请求:
SELECT
i.created AS creation, l.label AS activite,
COUNT(l.label) AS nbTicket, COUNT(l.label) AS nbEntree
FROM label AS l INNER JOIN
jiraissue AS i
ON (l.issue = i.id) AND i.issuetype <> 3
GROUP BY activite
所以在这里,我有数据库中的所有票证,但是如果我有带日期的where条件:
SELECT l.label AS activite, SUM(i.timespent/3600/8) AS consomme, SUM(i.timeestimate/3600/8) AS raf, COUNT(l.label) AS nbTicket,
SUM(i.timeoriginalestimate/3600/8) AS chargeProvisoire, COUNT(l.label) AS nbEntree
FROM label AS l INNER JOIN jiraissue AS i ON (l.issue = i.id)
WHERE l.label IN ('Devis','TGC1','TGC2','TGC3','TGC4','TGC5','TGC5-Bis','TGC6','TGC7','TGC8','TGC8-Bis','TGC9','TGC10','TGC10-Bis','TGC12','TGC13','TGC13-Bis','TGC14','TGC50','TGC60')
AND i.issuetype <> 3 AND i.created LIKE "2014-01-%" GROUP BY activite
我只有2019年1月的机票。
将所有票证包含在==> nbTicket列中并将所有具有'where'子句的票证包含在==> nbEntree中是一种解决方案吗?
答案 0 :(得分:0)
您可以在第一个查询中使用条件SUM()
,如下所示:
SELECT
max(i.created) AS creation,
l.label AS activite,
COUNT(*) AS nbTicket,
SUM(case when i.created LIKE "2019-01-%" then 1 end) AS nbEntree
FROM label AS l INNER JOIN
jiraissue AS i
ON (l.issue = i.id) AND i.issuetype <> 3
GROUP BY activite