全站第 38/1262

解决了 43/335 题

中等: 2/76
入门: 24/77
困难: 0/29
简单: 14/114
草履虫: 3/39

过去1年一共提交 85

Sep
Oct
Nov
Dec
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

勋章 ①金银铜:在竞赛中获得第一二三名;②好习惯:自然月10天提交;③里程碑:解决1/2/5/10/20/50/100/200题;④每周打卡挑战:完成每周5题,每年1月1日清零。

达成1题里程碑2025-02-11
达成2题里程碑2025-02-11
达成5题里程碑2025-02-22
达成10题里程碑2025-02-28
达成20题里程碑2025-08-04
完成w27打卡2025-08-08
完成w28打卡2025-08-08

收藏

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-08-08 每个行业超过20年的公司 
with industry_avg_total as 
(
  select 
  industry,
  sum(DATEDIFF(CURRENT_DATE(), list_date))/count(1) as avg_age_days,
  sum(DATEDIFF(CURRENT_DATE(), list_date)) as age_days,
count(1) as total_companies

from stock_info 
 
group by industry
)
,
industry_over_20 as 
(
select 
  industry,
	count(1) as total_companies 

from stock_info 
where DATEDIFF(CURRENT_DATE(), list_date) >=(365*20)
 
group by industry
)
select industry_avg_total.industry,
	industry_avg_total.avg_age_days,
	industry_over_20.total_companies as over_20_years,
    industry_avg_total.total_companies,
    industry_over_20.total_companies/industry_avg_total.total_companies as proportion_over_20_years
from industry_avg_total
left join industry_over_20 on industry_avg_total.industry = industry_over_20.industry
order by avg_age_days desc
记录一下...虽然我用的行业内总时长/单位数和答案不一样....
啥也没说
2025-08-08 各行业第一家上市公司 
with min_listdate  as
(
  select industry, min(list_date) as min_list_date
from stock_info 
group by industry
)

select stock_info.* 
	from stock_info
inner join min_listdate
on  stock_info.industry = min_listdate.industry
	and	stock_info.list_date = min_listdate.min_list_date
	
order by stock_info.list_date asc
啥也没说
2025-08-07 每年在深交所上市的银行有多少家 
SELECT YEAR(list_date) AS Y, COUNT(1) AS cnt
FROM stock_info
WHERE ts_code LIKE '%SZ'
  AND name LIKE '%银行%'
GROUP BY YEAR(list_date) 
ORDER BY YEAR(list_date) ;  
orderby 不生效,不知道为啥
而且你还漏了深交所
2025-08-05 时间日期(5)三腿爱往会所走,全当良心喂了狗 
select '2022-10-03 17:20:20'	as time_he_love_me,
datediff('2024-12-12','2022-10-03') as days_we_falling_love,
timestampdiff(hour ,'2022-10-03 17:20:20','2024-12-12 10:36:00') as hours_we_falling_love,
datediff(MIN(trx_time),'2022-10-03') as days_he_fvck_else
from cmb_usr_trx_rcd 
WHERE 
    usr_id = '5201314520' 
    AND mch_nm ='红玫瑰按摩保健休闲'

不需要 group by 也能跑通呀。
当然不需要了, AND mch_nm ='红玫瑰按摩保健休闲' 限制了只有一个商户,有group by 和没group by一个样,好好感受这个逻辑

提交记录

提交日期 题目名称 提交代码
2025-08-08 周杰伦的最受欢迎的专辑 
select album_info.album_id,album_info.album_name,count(1) as listener_count from album_info
left join song_info on album_info.album_id = song_info.album_id
left join listen_rcd on listen_rcd.song_id = song_info.song_id
left join singer_info on singer_info.singer_id = song_info.origin_singer_id
where singer_info.singer_name='周杰伦'
and listen_rcd.if_finished = 1
group by album_info.album_id,album_info.album_name
order by listener_count
limit 1
2025-08-08 拼接歌曲名和专辑名 
select song_name , 
 CONCAT(song_name, '-', album_name) 
as song_album
from song_info 
left join album_info on song_info.album_id = album_info.album_id
2025-08-08 用户听歌习惯的时间分布 
select user_id,DAYNAME(start_time) as day_of_week,count(1)
from listen_rcd 
group by user_id,DAYNAME(start_time)
order by user_id,DAYNAME(start_time) asc
2025-08-08 特定歌曲的播放记录 
select listen_rcd.id,listen_rcd.user_id,listen_rcd.start_time,listen_rcd.song_id,listen_rcd.if_finished from singer_info 
left join song_info on singer_info.singer_id = song_info.origin_singer_id
left join listen_rcd on listen_rcd.song_id = song_info.song_id
where song_info.song_id=13
and listen_rcd.if_finished = 1
and date(listen_rcd.start_time) between '2023-12-10'and '2023-12-31' 
order by start_time
2025-08-08 特定歌曲的播放记录 
select listen_rcd.id,listen_rcd.user_id,listen_rcd.start_time,listen_rcd.song_id,listen_rcd.user_id from singer_info 
left join song_info on singer_info.singer_id = song_info.origin_singer_id
left join listen_rcd on listen_rcd.song_id = song_info.song_id
where song_info.song_id=13
and listen_rcd.if_finished = 1
and date(listen_rcd.start_time) between '2023-12-10'and '2023-12-31' 
order by start_time
2025-08-08 特定歌曲的播放记录 
select listen_rcd.id,listen_rcd.user_id,listen_rcd.start_time,listen_rcd.song_id,listen_rcd.user_id from singer_info 
left join song_info on singer_info.singer_id = song_info.origin_singer_id
left join listen_rcd on listen_rcd.song_id = song_info.song_id
where song_info.song_id=13
and listen_rcd.if_finished = 1
and date(listen_rcd.start_time) between '2023-12-10'and '2023-12-31'
2025-08-08 2020年后上市的医药公司 
select 
year(list_date) as Y,
sum(case when name rlike '医|药|生物' then1 else 0 end ) as cnt
from stock_info 
where year(list_date) between 2020 and 2024
group by Y
order by Y
2025-08-08 2020年后上市的医药公司 
select * from stock_info 
where year(list_date) between 2020 and 2024
 and name rlike '医|药|生物'
2025-08-08 输出特定日期上市的银行 
select * from stock_info
where date(list_date) >='2006-06-01'
and date(list_date) <='2006-09-01'
and name like '%银行%'
2025-08-08 21世纪上市的银行 
select 
    * 
from 
    stock_info 
where 
     industry='银行'
 andyear(list_date)>=2000
order by list_date
2025-08-08 21世纪上市的银行 
select 
    * 
from 
    stock_info 
where 
    area = '北京'
    and industry='银行'
 andyear(list_date)>=2000
order by list_date
2025-08-08 输出地区为北京的所有银行 
select * from stock_info 
wherearea='北京'
and name like '%银行%'
order by list_date
2025-08-08 统计特定行业内的公司名长度分布 
select industry,AVG(length(name)) AS avg_name_length,
MAX(length(name)) AS max_name_length,
MIN(length(name)) AS min_name_length
from stock_info 
WHERE industry IN('通信设备','生物制药','旅游景点','医疗保健','食品')
group by industry
2025-08-08 每个行业超过20年的公司 
with industry_avg_total as 
(
select 
industry,
sum(DATEDIFF(CURRENT_DATE(), list_date))/count(1) as avg_age_days,
sum(DATEDIFF(CURRENT_DATE(), list_date)) as age_days,
count(1) as total_companies
from stock_info 
group by industry
)
,
 industry_over_20 as 
(
select 
industry,
	count(1) as total_companies 
from stock_info 
where DATEDIFF(CURRENT_DATE(), list_date) >=(365*20)
group by industry
)
select industry_avg_total.industry,
	industry_avg_total.avg_age_days,
	industry_over_20.total_companies as over_20_years,
industry_avg_total.total_companies,
industry_over_20.total_companies/industry_avg_total.total_companies as proportion_over_20_years
from industry_avg_total
left join industry_over_20 on industry_avg_total.industry = industry_over_20.industry
order by avg_age_days desc
2025-08-08 各地区包含“中国”或“中”字开头的公司数量及比例 
select 
	area,
	count(1) as total_companies,
sum(case when name rlike '中国|^中' then 1 else 0 end) as chinese_named_companies,
ROUND(SUM(CASE WHEN name rlike '中国|^中' THEN 1 ELSE 0 END) / COUNT(*),3) AS proportion
from stock_info 
group by area
order by proportion desc
limit 5
2025-08-08 各地区包含“中国”或“中”字开头的公司数量及比例 
select 
	area,
	count(1) as total_companies,
sum(case when area rlike '中国|^中' then 1 else 0 end) as chinese_named_companies,
ROUND(SUM(CASE WHEN name rlike '中国|^中' THEN 1 ELSE 0 END) / COUNT(*),3) AS proportion
from stock_info 
group by area
order by proportion desc
limit 5
2025-08-08 每个行业最早上市的公司 
selectts_code,
    symbol,
    name,
    area,
    industry,
    list_date
from
(
 select stock_info.* ,
row_number()over(partition by industry ORDER BY list_date ASC ) as Sort
from stock_info 
where name rlike '^中国|中' 
)as table1 where Sort = 1
2025-08-08 中字头上市企业 
select count(*) from stock_info 
where industry in('通信设备','生物制药','旅游景点
','医疗保健','食品')
and name rlike'华|中'
2025-08-08 各行业第一家上市公司 
with min_listdateas
(
select industry, min(list_date) as min_list_date
from stock_info 
group by industry
)
select stock_info.* 
	from stock_info
inner join min_listdate
onstock_info.industry = min_listdate.industry
	and	stock_info.list_date = min_listdate.min_list_date
order by stock_info.list_date asc
2025-08-08 各行业第一家上市公司 
with min_listdateas
(
select industry, min(list_date) as min_list_date
from stock_info 
group by industry
)
select stock_info.* 
	from stock_info
rightjoin min_listdate
onstock_info.industry = min_listdate.industry
	and	stock_info.list_date = min_listdate.min_list_date
order by stock_info.list_date asc