我的db-hadoop,hive我试图在select上运行一个带有子查询的查询,但没有运行。请查找下面的查询
谢谢你的帮助
select
to_date(timestamp) as date,
count(*),
(select count(*) from table1 where to_date(timestamp)=current_date() and arrivaltime IS null) as count_null
FROM table1
WHERE to_date(ingest_timestamp) =current_date()
GROUP BY date, count_null
1条答案
按热度按时间uidvcgyl1#
将子查询转换为案例。你也不能分组
count_null
列。如果你真的需要分组count_null
然后在此查询之上构建一个查询。下面sql将返回total_count
,count_null
,和count_not_null
```select
to_date(timestamp) as date,
count(*) total_count,
SUM(CASE WHEN arrivaltime IS null then 1 else 0 END) as count_null,
SUM(CASE WHEN arrivaltime IS null then 0 else 1 END) as count_not_null,
SUM(CASE WHEN arrivaltime IS null then 0 else 1 END) - SUM(CASE WHEN arrivaltime IS null then 1 else 0 END)
as diff_not_null_and_null
FROM
table1
WHERE to_date(timestamp)=current_date
GROUP BY to_date(timestamp)
Flightid, timestamp, arrivaltime
Flight1, 2021-01-29,2021-01-29 10:00:00
Flight2, 2021-01-29,
Flight4, 2021-01-29,2021-01-29 11:00:00
Flight5, 2021-01-29,2021-01-29 10:30:00
Flight9, 2021-01-29,
timestamp, total_count, count_null, count_not_null, diff_not_null_and_null
2021-01-29, 5, 2, 3, 1