需求--统计hive某张表type字段不同取值的数据量
我们已知某张表的type的取值是1,2,3,4,5,想要统计不同type的数据量,并清晰的展现出来。可以通过union all 的方式,sql如下:
SELECT "1",COUNT(*) FROM table_name WHERE type = "1" UNION ALL SELECT "2",COUNT(*) FROM table_name WHERE type = "2" UNION ALL SELECT "3",COUNT(*) FROM table_name WHERE type = "3" UNION ALL SELECT "4",COUNT(*) FROM table_name WHERE type = "4" UNION ALL SELECT "5",COUNT(*) FROM table_name WHERE type = "5"
得到的结果如下:
type | count(*) |
1 | 324 |
2 | 123 |
3 | 345 |
4 | 156 |
5 | 343 |