i counting number of distinct customers , grouping column .i result return zeros if no customers found in group. following code, don't zeros in results. can please help?
select download_date,resolution,count(distinct customer_id) test.sample group download_date,resolution; what gives me following:
---------------------------------------- | 2011-06-09| hd | 1 | ---------------------------------------- | 2011-06-09| sd | 1 | ---------------------------------------- | 2012-06-10| sd | 1 | ---------------------------------------- whereas looking following:
---------------------------------------- | 2011-06-09| hd | 1 | ---------------------------------------- | 2011-06-09| sd | 1 | ---------------------------------------- | 2012-06-10| hd | 1 | ---------------------------------------- | 2012-06-10| sd | 0 | ---------------------------------------- here table structure :
create table test.sample ( `customer_id` varchar(15) null default null, `download_date` date null default null, `resolution` varchar(2) null default null, `total_units` int(11) null default null); insert test.sample(`customer_id`,`download_date`,`resolution`,`total_units`) values('1','2012-06-10','hd',40),('1','2012-06-10','hd',20), ('2','2011-06-09','sd',10),('2','2011-06-09','hd',20);
select dr.download_date, r.resolution,count(distinct customer_id) (select distinct download_date sample) dr cross join (select distinct resolution sample) r left join sample s on s.download_date = dr.download_date , r.resolution = s.resolution group dr.download_date, r.resolution;
Comments
Post a Comment