Help from the SQL Gods Required
Table 1 – DistinctQuotes
This tables holds information about quotes say .
So we have
+-------+-----------+--------------+------+-----------------+
|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 |
+-------+-----------+--------------+------+-----------------+
So I want to display the count per Subregion of quotes that have come from type DS1 and Market Route is Direct.
Now this query below is wrong as the count of quotes comes from the sum of the Quotation Count from the matching rows, and not from the count of rows that match
[Market Route] = ‘Direct’ AND [Type] = ‘DS1’.
Can anyone help me change the query below to capture what I need ?
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]
Just change
THEN 1 ELSE 0toTHEN [Quotations Count] ELSE 0?