select * from hand_permutations
where concat(card1, card2) like '%A%K%' or
concat(card1, card2) like '%K%K%' or
concat(card1, card2) like '%K%A%' or
concat(card1, card2) like '%A%A%'
select
case
when mch_nm like '%按摩保健休闲%' then '按摩保健休闲'
when lower(mch_nm) rlike '.*(按摩|保健|休闲|spa|养生|会所).*' then '按摩、保健、休闲、养生、SPA、会所'
end as reg_rules,
count(distinct mch_nm) as mch_cnt
from
cmb_usr_trx_rcd
where mch_nm like '%按摩保健休闲%'
or lower(mch_nm) rlike '.*(按摩|保健|休闲|spa|养生|会所).*'
group by reg_rules
order by mch_cnt desc;
select count(distinct mch_nm) as mch_cnt
from cmb_usr_trx_rcd
where mch_nm like '%按摩%' or mch_nm like '%保健%' or mch_nm like '%休闲%' or mch_nm like '%养生%' or lower(mch_nm) like '%spa%' or mch_nm like '%会所%'
union
select count(distinct mch_nm) as mch_cnt
from cmb_usr_trx_rcd
where mch_nm like '%按摩保健休闲%'
select user_id, dayname(start_time) as day_of_week, count(distinct id) as listens_per_day
from listen_rcd
group by user_id, day_of_week
order by user_id, day_of_week
select user_id, dayname(start_time) as day_of_week, count(distinct id) as listens_per_day
from listen_rcd
group by user_id, day_of_week
order by user_id, dayname(start_time)
select user_id, dayname(start_time) as day_of_week, count(distinct id) as listens_per_day
from listen_rcd
group by user_id, dayname(start_time)
order by user_id, dayname(start_time)
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 else null end) as commute,
count(distinct case when time(login_time) between '11:30:00' and '14:00:00' then usr_id else null end) as lunch_break,
count(distinct case when time(login_time) between '22:30:00' and '23:59:59' or
time(login_time) between '00:00:00' and '01:00:00' then usr_id else null end) as bedtime
from user_login_log
where login_time >= date_format(date_sub(curdate(), interval 1 month), '%Y-%m-01 00:00:00') and
login_time < date_format(curdate(),'%Y-%m-01 00:00:00')
SELECT
COUNT(DISTINCT usr_id) AS active_users
FROM
user_login_log
WHERE
login_time>=date_format(date_sub(curdate(), interval 1 month), '%Y-%m-01 00:00:00') and
login_time<date_format(curdate(), '%Y-%m-01 00:00:00')
select year(dt) as Y,
cast(sum(case when city = 'beijing' then tmp_h else 0 end) / sum(case when city = 'beijing' then 1 else 0 end) as decimal(10,2) )as '北京',
cast(sum(case when city = 'shanghai' then tmp_h else 0 end) / sum(case when city = 'shanghai' then 1 else 0 end) as decimal(10,2) )as '上海',
cast(sum(case when city = 'shenzhen' then tmp_h else 0 end) / sum(case when city = 'shenzhen' then 1 else 0 end) as decimal(10,2) )as '深圳',
cast(sum(case when city = 'guangzhou' then tmp_h else 0 end) / sum(case when city = 'guangzhou' then 1 else 0 end) as decimal(10,2) )as '广州'
from weather_rcd_china
where year(dt) between 2011 and 2022
group by year(dt)
select year(dt) as Y,
cast(sum(case when city = 'beijing' then tmp_h else 0 end) / sum(case when city = 'beijing' then 1 else 0 end) as decimal(10,2) )as '北京',
cast(sum(case when city = 'shanghai' then tmp_h else 0 end) / sum(case when city = 'beijing' then 1 else 0 end) as decimal(10,2) )as '上海',
cast(sum(case when city = 'shenzhen' then tmp_h else 0 end) / sum(case when city = 'beijing' then 1 else 0 end) as decimal(10,2) )as '深圳',
cast(sum(case when city = 'guangzhou' then tmp_h else 0 end) / sum(case when city = 'beijing' then 1 else 0 end) as decimal(10,2) )as '广州'
from weather_rcd_china
where dt between '2011-01-01' and '2022-12-31' and city in ('beijing', 'shanghai', 'guangzhou', 'shenzhen')
group by year(dt)
select city, sum(case when con like '%雪%' then 1 else 0 end) as snowy_days
from weather_rcd_china
where month(dt) in (12,1,2)
group by city
order by snowy_days desc
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) in (22,23,0,1,2,3,4,5))
select * from cmb_usr_trx_rcd
where usr_id='5201314520' and (cast(trx_time as date) between '2024-09-01' and '2024-09-30') and (hour(trx_time) between 1 and 5)
select * from cmb_usr_trx_rcd
where usr_id='5201314520' and (cast(trx_time as date) between '2024-09-01' and '2024-09-30') and (hour(trx_time) between 1 and 4)