[英]access: IIF statement and COUNT
這是我的代碼,感謝Jim b:
SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]
HAVING ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0)
ORDER BY Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) DESC;
它返回此:
1.1 Specimen Mislabeled 159
1.3 QNS-Quantity Not Sufficient 84
1.9 QNS- Specimen Spilled in transit 72
1.6 Test Requisition Missing 17
1.11 Other 3
1.11 Other 3
1.1 Specimen Mislabeled-new ID # given 2
1.11 Other 2
1.11 Other 2
1.1 Specimen Mislabeled & 1.6 Test Requisition Missing 1
1.11 Other 1
1.11 Other 1
1.11 Other 1
1.11 Other 1
1.11 Other 1
? Nothing in comments portion of QuikLab 1
1.11 Other 1
1.11 Other 1
1.4 Tests Missed/ Wrong Test Ordered 1
1.4 Tests Missed/Wrong Test Ordered 1
1.6 Test Requisition Missing & 1.7 Specimen Lost 1
1.8 Specimen not handled/processed correctly & 1.10 Operator Error(?) 1
1.11 Other 1
1.11 Other 1
這正是我所需要的,不過有一點小問題。 我需要將其計算為“ 1.11其他”
我該怎么做? 換句話說,這是我需要的輸出:
? Nothing in comments portion of QuikLab 1
1.1 Specimen Mislabeled 159
1.1 Specimen Mislabeled & 1.6 Test Requisition Missing 1
1.1 Specimen Mislabeled-new ID # given 2
1.11 Other 19
1.3 QNS-Quantity Not Sufficient 84
1.4 Tests Missed/ Wrong Test Ordered 1
1.4 Tests Missed/Wrong Test Ordered 1
1.6 Test Requisition Missing 17
1.6 Test Requisition Missing & 1.7 Specimen Lost 1
1.8 Specimen not handled/processed correctly & 1.10 Operator Error(?) 1
1.9 QNS- Specimen Spilled in transit 72
如您所見,只有一次出現1.11 Other
,總數為19
JIM B建議這樣做:
Use your IIF statement all the way through your group by and having clauses – Jim B
但是我不知道如何實現它。 請幫忙!
您在column語句中使用的解決方案也需要包含在count函數中。 因為您希望它基於修訂后的列數據而不是原始列數據進行計數。
更多有關sql server的家伙,所以我不確定是否可以執行此操作,但您是否嘗試過:
SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
HAVING ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0)
ORDER BY Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) DESC;
也許是這樣的嗎?
SELECT IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [Occurrence Code], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![Meeting_Reasons_Frequency]![Text4] And [Forms]![Meeting_Reasons_Frequency]![Text2]))
GROUP BY IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])
HAVING ((Count(IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])))<>0)
ORDER BY Count(IIf([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)] Like '*1.11 Other*','1.11 Other',[Lab Occurrence Form].[1 0 Preanalytical (Before Testing)])) DESC;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.