第三模块: 窗口练习 使用到的表: 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
时间: 2024-01-21 15:16:31 浏览: 115
RyZeN-Kernel-Website::high_voltage: RYZEN-KERNEL-WEBSITE:artist_palette: 使用 Bootstrap-V5 构建:red_heart:谢谢 https
13、求停留时间最长的url,并给出停留时长,按照停留时长倒叙排序
```sql
SELECT
website_url_info.url,
SUM(website_pv_info.stay_time) AS total_stay_time
FROM
website_pv_info
JOIN website_url_info
ON website_pv_info.url_id = website_url_info.id
GROUP BY
website_url_info.url
ORDER BY
total_stay_time DESC
LIMIT 1;
```
14、求2018-04-11到2018-04-15 之间,每天的pv 和 uv 数量,并按照日期升序,pv降序排序
```sql
SELECT
DATE(website_pv_info.create_time) AS date,
COUNT(DISTINCT website_pv_info.user_id) AS uv,
COUNT(*) AS pv
FROM
website_pv_info
WHERE
website_pv_info.create_time BETWEEN '2018-04-11' AND '2018-04-15'
GROUP BY
DATE(website_pv_info.create_time)
ORDER BY
date ASC,
pv DESC;
```
15、求2018年4月每个时段的,pv、uv 数量、按照uv转化率取top5
```sql
SELECT
DATE_FORMAT(website_pv_info.create_time, '%H:00-%H:59') AS time_range,
COUNT(*) AS pv,
COUNT(DISTINCT website_pv_info.user_id) AS uv,
CAST(COUNT(CASE WHEN website_pv_info.is_conversion = 1 THEN 1 ELSE NULL END) / COUNT(DISTINCT website_pv_info.user_id) AS DECIMAL(10,2)) AS uv_conversion_rate
FROM
website_pv_info
WHERE
website_pv_info.create_time BETWEEN '2018-04-01' AND '2018-04-30'
GROUP BY
time_range
ORDER BY
uv_conversion_rate DESC
LIMIT 5;
```
注:上述SQL语句仅供参考,具体情况下需根据实际数据表结构和业务需求进行调整。
阅读全文