第三模块: 窗口练习 使用到的表: website_url_info 、website_pv_info -- 13、求停留时间最长的url,并给出停留时长,按照停留时长倒叙排序 -- 14、求2018-04-11到2018-04-15 之间,每天的pv 和 uv 数量,并按照日期升序,pv降序排序 -- 15、求2018年4月每个时段的,pv、uv 数量、按照uv转化率取top5. -- uv 转化率 = 转化人数/uv数量 ,假设现在转化人数是 1
时间: 2023-12-14 20:38:51 浏览: 122
13、求停留时间最长的url,并给出停留时长,按照停留时长倒叙排序
```sql
SELECT url, SUM(duration) AS total_duration
FROM website_url_info
GROUP BY url
ORDER BY total_duration DESC
LIMIT 1;
```
14、求2018-04-11到2018-04-15 之间,每天的pv 和 uv 数量,并按照日期升序,pv降序排序
```sql
SELECT date, SUM(pv) AS total_pv, COUNT(DISTINCT user_id) AS total_uv
FROM website_pv_info
WHERE date BETWEEN '2018-04-11' AND '2018-04-15'
GROUP BY date
ORDER BY date ASC, total_pv DESC;
```
15、求2018年4月每个时段的,pv、uv 数量、按照uv转化率取top5
```sql
SELECT
DATE_FORMAT(date, '%Y-%m-%d %H') AS hour,
SUM(pv) AS total_pv,
COUNT(DISTINCT user_id) AS total_uv,
SUM(CASE WHEN is_conversion = 1 THEN 1 ELSE 0 END) AS total_conversion,
SUM(CASE WHEN is_conversion = 1 THEN 1 ELSE 0 END)/COUNT(DISTINCT user_id) AS conversion_rate
FROM website_pv_info
WHERE date BETWEEN '2018-04-01' AND '2018-04-30'
GROUP BY DATE_FORMAT(date, '%Y-%m-%d %H')
ORDER BY conversion_rate DESC
LIMIT 5;
```
其中,is_conversion 表示该次访问是否有转化行为。在此假设转化人数是 1。
阅读全文