select
user_id,
dayname(start_time) as day_of_week,
count(user_id) as listens_per_day
from
listen_rcd
group by
user_id,day_of_week
order by
user_id,day_of_week
select
*
from
cmb_usr_trx_rcd
where
usr_id = 5201314520
and
(date(trx_time) between '2024-06-08' and '2024-06-10'
or
date(trx_time) between '2024-09-15' and '2024-09-17')
select
*
from
cmb_usr_trx_rcd
where
usr_id = 5201314520
and
date(trx_time) between '2024-06-08' and '2024-06-10'
or
date(trx_time) between '2024-09-15' and '2024-09-17'
SELECT
COUNT(DISTINCT CASE
WHEN TIME(login_time) BETWEEN '07:30:00' AND '09:30:00'
OR TIME(login_time) BETWEEN '18:30:00' AND '20:30:00' THEN usr_id
END) AS commute,
COUNT(DISTINCT CASE
WHEN TIME(login_time) BETWEEN '11:30:00' AND '14:00:00' THEN usr_id
END) AS lunch_break,
COUNT(DISTINCT CASE
WHEN TIME(login_time) BETWEEN '22:30:00' AND '23:59:59' THEN usr_id
WHEN TIME(login_time) BETWEEN '00:00:00' AND '01:00:00' THEN usr_id
END) AS bedtime
from
user_login_log
where
login_time between date_format(date_sub(current_date(),interval 1 month),'%Y-%m-01') and DATE_FORMAT(CURDATE(), '%Y-%m-01')
select
year(dt) as Y,
cast(avg(case when city = 'beijing' then tmp_h else null end) as decimal(4,2)) as '北京',
cast(avg(case when city = 'shanghai' then tmp_h else null end) as decimal(4,2)) as '上海',
cast(avg(case when city = 'shenzhen' then tmp_h else null end) as decimal(4,2)) as '深圳',
cast(avg(case when city = 'guangzhou' then tmp_h else null end) as decimal(4,2)) as '广州'
from
weather_rcd_china
where
year(dt) between 2011 and 2022
group by
Y
select
city,
sum(case when con like '%雪%' then 1 else 0 end) as snowy_days
from
weather_rcd_china
where
month(dt) in (1,2,12)
group by
city
order by
snowy_days desc
select year(dt) as Y
,cast(avg(case when city='beijing' then tmp_h else null end) as decimal(4,2)) as '北京'
,cast(avg(case when city='shanghai' then tmp_h else null end) as decimal(4,2)) as '上海'
,cast(avg(case when city='shenzhen' then tmp_h else null end) as decimal(4,2)) as '深圳'
,cast(avg(case when city='guangzhou' then tmp_h else null end) as decimal(4,2)) as '广州'
from
weather_rcd_china
where
year(dt) between 2011 and 2022
group by
year(dt)
SELECT
sum(TIMESTAMPDIFF(SECOND, call_time, grab_time))/count(1) AS avg_response_time_seconds
FROM
didi_order_rcd
WHERE
grab_time != '1970-01-01 00:00:00';
select
*
from
cmb_usr_trx_rcd
where
usr_id = '5201314520'
and
date(trx_time) between '2024-09-01' and '2024-09-30'
and
(hour(trx_time) between '22:00:00' and '24:00:00'
or
hour(trx_time) between '00:00:00' and '05:00:00')
select
*
from
cmb_usr_trx_rcd
where
usr_id = '5201314520'
and
date(trx_time) between '2024-09-01' and '2024-09-30'
and
hour(trx_time) between '01:00:00' and '05:59:59'
select
*
from
cmb_usr_trx_rcd
where
usr_id = '5201314520'
and
date(trx_time) between '2024-09-01' and '2024-09-30'
and
hour(trx_time) between '01:00:00' and '06:00:00'
select
student_id,
sum(score) as total_score
from
scores
where
exam_date = '2024-06-30'
and
subject in ('语文','数学','英语')
group by
student_id
having
sum(score) > 330