需要来自 SQL 之神的帮助
表 1 - DistinctQuotes
此表包含有关报价的信息说。
所以我们有
+-------+-----------+--------------+------+-----------------+
|REGION | SubRegion | Market Route | Type | Quotations Count|
+-------+-----------+--------------+------+-----------------+
|EMEA | Germany | Direct | DS1 | 12 |
|EMEA | Germany | NonDirect | DS1 | 22 |
|EMEA | Germany | Direct | DS1 | 2 |
|EMEA | Germany | NOnDirect | DS1 | 4 |
|EMEA | France | Direct | DS1 | 4 |
|EMEA | UK | Direct | DS1 | 4 |
+-------+-----------+--------------+------+-----------------+
因此,我想显示来自 DS1 类型且 Market Route 为 Direct 的每个子区域的报价计数。
现在下面的这个查询是错误的,因为报价计数来自匹配行的报价计数的总和,而不是来自匹配 [Market Route] = 'Direct' AND [Type] = 'DS1' 的行计数。
谁能帮我更改下面的查询以获取我需要的内容?
SELECT
[Region] ,[SubRegion]
,SUM (CASE WHEN [Market Route] = 'Direct' AND [Type] = 'DS1'
THEN 1 ELSE 0 END) as [Count of Direct quotes from DS1]
FROM [dbo].[V_DistinctQuotes]
GROUP by [SubRegion],[Region]