有一个直播主播收入表,还有一个被封禁的主播列表,请写一个 sql 输出每个未封禁 的主播的收入总和。 主播收入表名称:user_income
SQL面试题-主播收入统计_数据库
封禁的主播表名称:banned_user
SQL面试题-主播收入统计_sql_02

hive> select * from user_income;
OK
112 1 30
112 2 800
117 1 100
118 1 10
118 2 20
119 1 30
120 2 40
Time taken: 0.598 seconds, Fetched: 7 row(s)
hive> select * from banned_user;
OK
118 1521390018
120 1489248600
Time taken: 0.22 seconds, Fetched: 2 row(s)
hive> select t1.uid,sum(t1.income_money) from (select t.uid,t.income_money from user_income t where uid not in (select uid from banned_user)) t1 group by t1.uid;
OK
112 830
117 100
119 30
Time taken: 166.931 seconds, Fetched: 3 row(s)

SQL:

select t1.uid,sum(t1.income_money) from (select t.uid,t.income_money from user_income t where uid not in (select uid from banned_user)) t1 group by t1.uid;