0

欠陥データベースからクエリを作成したいと考えています。各欠陥には、送信日とステータス (オープン、クローズ、延期など) があります。結果セットに 3 つの列が必要です。

Date, # bugs w/ Open status, # bugs with Closed status
2012-05-31, 3, 1
2012-06-01, 2, 0
2012-06-02, 3, 2

このクエリを超えて、必要なものを取得する方法がわかりません。

select 
    DEFECT.SUBMITTED_DATE as "Opened", 
    count (DEFECT.SUBMITTED_DATE), 
    DEFECT.STATUS as "Status"
from 
     DEFECT
where 
     DEFECT.STATUS='Open' or DEFECT.STATUS='Fixed'
group by 
     DEFECT.SUBMITTED_DATE

提案を探しています。

4

3 に答える 3

1

MySQLでは、

SELECT  DATE(DEFECT.SUBMITTED_DATE) as `DATE_SUBMITTED`, 
        SUM(CASE WHEN DEFECT.STATUS='Open' THEN 1 ELSE 0 END) `# bugs w/ Open status`,
        SUM(CASE WHEN DEFECT.STATUS='Fixed' THEN 1 ELSE 0 END) `# bugs with Closed status`,
FROM     DEFECT
GROUP BY DATE(DEFECT.SUBMITTED_DATE)

TSQL で

SELECT  CAST(DEFECT.SUBMITTED_DATE as DATE) as [DATE_SUBMITTED], 
        SUM(CASE WHEN DEFECT.STATUS='Open' THEN 1 ELSE 0 END) [# bugs w/ Open status],
        SUM(CASE WHEN DEFECT.STATUS='Fixed' THEN 1 ELSE 0 END) [# bugs with Closed status],
FROM     DEFECT
GROUP BY CAST(DEFECT.SUBMITTED_DATE as DATE)
于 2013-01-11T14:52:38.747 に答える
1

試す :

SELECT DEFECT.SUBMITTED_DATE as DATE_SUBMITTED,
    SUM(CASE WHEN DEFECT.STATUS = 'Open' THEN 1 ELSE 0 END) AS `# bugs w/ Open status`,
    SUM(CASE WHEN DEFECT.STATUS = 'Fixed' THEN 1 ELSE 0 END) AS `# bugs w/ Open status`
FROM DEFECT
WHERE DEFECT.STATUS IN ('Open', 'Fixed')
GROUP BY DEFECT.SUBMITTED_DATE
于 2013-01-11T14:52:47.717 に答える
0

MS SQL Server の場合:

SELECT DEFECT.SUBMITTED_DATE as [Date]
,SUM(CASE WHEN DEFECT.STATUS = 'Open' THEN 1 ELSE 0 END) AS number_open
,SUM(CASE WHEN DEFECT.STATUS = 'Fixed' THEN 1 ELSE 0 END) AS number_fixed
FROM DEFECT 
WHERE DEFECT.STATUS IN ('Open' ,'Fixed')
GROUP BY DEFECT.SUBMITTED_DATE
于 2013-01-11T14:54:40.880 に答える