Hi i am trying to implement sub-query in the select itself
Document 1:
{
“Date”: “2016/12/01”,
“IpAddress”: “192.168.0.1”,
“Region”: “Sout-Asia”,
“Country”: “India”,
“State”: “Gujarat”,
“City”: “Ahmedabad”,
“UserAgent”: “Mozilla”,
“Device”: “”,
“Impression”: “0”,
“Click”: “1”,
“Platform”: “Desktop”,
“Channel”: “B2B”,
“PageRegion”: “Header”,
“Zone”: “Head”,
“Advertisement”: “Advt2”,
“Advertiser”: “Advt1”,
“CampaignPlacmentId”: “1”,
“Url”: “abc”,
“Id”: 1
}
Document 2:
{
“Date”: “2016/12/02”,
“IpAddress”: “192.168.0.1”,
“Region”: “Sout-Asia”,
“Country”: “India”,
“State”: “Gujarat”,
“City”: “Ahmedabad”,
“UserAgent”: “Mozilla”,
“Device”: “”,
“Impression”: “1”,
“Click”: “1”,
“Platform”: “Desktop”,
“Channel”: “B2B”,
“PageRegion”: “Header”,
“Zone”: “Head”,
“Advertisement”: “Advt1”,
“Advertiser”: “Advt1”,
“CampaignPlacmentId”: “1”,
“Url”: “abc”,
“Id”: 2
}
Document 3
{
“Date”: “2016/12/01”,
“IpAddress”: “192.168.0.1”,
“Region”: “Sout-Asia”,
“Country”: “India”,
“State”: “Gujarat”,
“City”: “Ahmedabad”,
“UserAgent”: “Mozilla”,
“Device”: “”,
“Impression”: “1”,
“Click”: “1”,
“Platform”: “Desktop”,
“Channel”: “B2B”,
“PageRegion”: “Header”,
“Zone”: “Head”,
“Advertisement”: “Advt1”,
“Advertiser”: “Advt1”,
“CampaignPlacmentId”: “1”,
“Url”: “abc”,
“Id”: 3
}
And I have written query as below but its not working
SELECT
DISTINCT s.Platform,
COUNT(DISTINCT s.Channel) AS Channels,
COUNT(DISTINCT s.Advertisement) AS Advertisements,
SUM(CASE WHEN s.Click == “1” THEN 1 ELSE 0 END) AS TotalClicks,
SUM(CASE WHEN s.Impression == “1” THEN 1 ELSE 0 END) AS TotalImpressions,
(SELECT COUNT(DISTINCT IpAddress) AS UniqueClicks FROM default
WHERE Platform = s.Platform AND Click = “1”) AS UniqueClicks
FROM
default
AS s
GROUP BY
s.Platform
ORDER BY Platform
Or any other way the same output can be archived.
Any help is appreciated.
Regards,
Siddharth