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;


后面答案敬请期待

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