Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL/HIVE如何将具有不同where语句的两个查询组合到一个查询中?_Sql_Hive - Fatal编程技术网

SQL/HIVE如何将具有不同where语句的两个查询组合到一个查询中?

SQL/HIVE如何将具有不同where语句的两个查询组合到一个查询中?,sql,hive,Sql,Hive,我有下面的查询,其中我试图计算数据集“1234”中columnA为Y或N的所有实例 select data_set as DATA_SET, sum(case when columnA <> '' and columnA = ‘Y’ then 1 else 0 end) as YES, sum(case when columnA <> '' and columnA = ’N’ then 1 else 0 end) as NO from myTable1 where dat

我有下面的查询,其中我试图计算数据集“1234”中columnA为Y或N的所有实例

select
data_set as DATA_SET,
sum(case when columnA <> '' and columnA = ‘Y’ then 1 else 0 end) as YES,
sum(case when columnA <> '' and columnA = ’N’ then 1 else 0 end) as NO
from myTable1
where data_set = 1234
group by data_set;
现在,我想做的是如何在同一个查询中查找两个不同的数据集(ds1=1234,ds2=4321),并返回如下内容:

Column |  ds1.count | ds2.count
Y      |  134,543   | 153,678
N      |  5,080     | 989,820

我想我已经明白了,以下几点对我很有用:

select
columnA,
sum(case when columnA <> '' and data_set = 1234 then 1 else 0 end) as PREVIOUS_COUNT,
sum(case when columnA <> '' and data_set = 4321 then 1 else 0 end) as CURRENT_COUNT
from myTable1
where data_set in (1234, 4321)
group by columnA
order by columnA ASC;
选择
专栏,
求和(当列“”和数据集=1234时,则为1,否则为0结束)作为上一个计数,
求和(当列“”和数据集=4321时,则为1,否则为0结束)作为当前计数
从我的表1
其中设置了数据_(12344321)
按列分组a
按ASC专栏排序;

多个数据集与您的是/否计算有何关联?
select
columnA,
sum(case when columnA <> '' and data_set = 1234 then 1 else 0 end) as PREVIOUS_COUNT,
sum(case when columnA <> '' and data_set = 4321 then 1 else 0 end) as CURRENT_COUNT
from myTable1
where data_set in (1234, 4321)
group by columnA
order by columnA ASC;