hive> describe hivecustomers;
OK
cust_id int
cust_fname string
cust_lname string
cust_email string
cust_password string
cust_street string
cust_city string
cust_state string
cust_zipcode string
hive> describe hiveorders;
OK
ord_id int
ord_dt string
ord_cust_id int
ord_stat string
hive> select * from hiveorders limit 3;
OK
1 2013-07-25 00:00:00.0 11599 CLOSED
2 2013-07-25 00:00:00.0 256 PENDING_PAYMENT
3 2013-07-25 00:00:00.0 12111 COMPLETE
hive> select * from hivecustomers limit 3;
OK
1 Richard Hernandez XXXXXXXXX XXXXXXXXX 6303 Heather Plaza Brownsville TX 78521
2 Mary Barrett XXXXXXXXX XXXXXXXXX 9526 Noble Embers Ridge Littleton CO 80126
3 Ann Smith XXXXXXXXX XXXXXXXXX 3422 Blue Pioneer Bend Caguas PR 00725
基于以上两个表,我需要输出如下在配置单元中,我如何才能写查询到这个工作?
+-----------+---------------+---------------+--------------+-----+
|Cust Name | Cust Address | Total Orders | Order Status |Count|
+-----------+---------------+---------------+--------------+-----+
|Andrew |London |15 |Complete |8 |
|Andrew |London |15 |Pending |3 |
|Andrew |London |15 |Processing |4 |
|Andrew |London |15 |On-Hold |1 |
+-----------+---------------+---------------+--------------+-----+
1条答案
按热度按时间holgip5t1#
最后将数据用作cte(公共表表达式)并对其进行了测试。cuctomer 1有两个待处理的付款订单,共4个,所有其他每个状态有一个订单,每个状态共3个:
输出:
只需删除cte并使用普通表即可。