sql 面試題 客源量 帶看量

需要原題練習,請聯繫我

SQL題目
一、請獲取2019年3月31日錄入的城市的客源量,客源狀態爲有效客源或者共享池客源,取出信息包括城市名稱,客源量(電話號碼去重)。
在這裏插入圖片描述

create table custdel_all_info_da
(

cust_id int not null,
cust_name varchar(20) not null,
cust_phone1 varchar(20) not null,
cust_city_name varchar(30) not null,
status_name varchar(20) not null,
keyin_agent_id int not null,
keyin_date varchar(30) not null
);

後面答案敬請期待

二、請從客源表和帶看錶中,取出2019年3月每個城市新增客戶(客戶狀態爲有效或者共享池客源),帶看量最多的10個客戶及其首次帶看時間。輸出:城市名稱、客戶編號、客戶姓名、帶看量、首次帶看時間、排名。
在這裏插入圖片描述

在這裏插入圖片描述
這裏有窗口函數的問題,下面是我的練習;
select * ,rank() over(partition by cust_city_name order by cust_phone1 desc) from custdel_all_info_da ;
select * ,sum(cust_phone1),
rank() over(partition by cust_city_name order by cust_phone1 desc),
count(cust_id) over (partition by cust_city_name
rows between UNBOUNDED PRECEDING AND CURRENT ROW) ,
sum(cust_phone1) over(rows between UNBOUNDED PRECEDING AND CURRENT ROW),
sum(cust_phone1) over(partition by cust_city_name rows between UNBOUNDED PRECEDING AND CURRENT ROW) aa
from custdel_all_info_da
group by cust_city_name;


後面答案敬請期待

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章