当前位置:网站首页>Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators

Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators

2022-06-23 05:40:00 Socialphobia_ FOGO

Index analysis of communication operators

Table 1 is available : Users in various cities ARPU value
 Insert picture description here
Table two : User package fee table
 Insert picture description here
Business requirements :

1. Number of users in each city 、 The total cost (ARPU The sum of the ) How much is the ?

2. Users in various cities arpu Cities in the value table ARPU(0,30),[30,50),[50-80),[80 above ) What are the number of users ?

3. Users have duplicate records in the user package expense table , Find duplicate users

#1. Number of users in each city 、 The total cost (ARPU The sum of the ) How much is the ?
SELECT  City ,COUNT(DISTINCT  user id) AS  Number of users in each city ,SUM(ARPU value ) AS  The total cost 
FROM  Users in various cities arpu value 
GROUP BY  City 

give the result as follows :
 Insert picture description here

#2. Users in various cities arpu Cities in the value table ARPU(0,30),[30,50),[50-80),[80 above ) What are the number of users ?
SELECT  City ,
SUM(CASE WHEN ARPU value >0 AND ARPU value <30 THEN 1 ELSE 0 END) AS '(0,30) The number of users ',
SUM(CASE WHEN ARPU value >=30 AND ARPU value <50 THEN 1 ELSE 0 END) AS '[30,50) The number of users ',
SUM(CASE WHEN ARPU value >=50 AND ARPU value <80 THEN 1 ELSE 0 END) AS '[50-80) The number of users ',
SUM(CASE WHEN ARPU value >=80 THEN 1 ELSE 0 END) AS '[80 above ) The number of users '
FROM  Users in various cities arpu value 
GROUP BY  City 

give the result as follows :
 Insert picture description here

#3. Users have duplicate records in the user package expense table , Find duplicate users 
SELECT  user id
FROM  User package fee table 
GROUP BY  user id
HAVING COUNT( user id)>1

give the result as follows :
 Insert picture description here

原网站

版权声明
本文为[Socialphobia_ FOGO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230355226715.html