select substr(trx_time, 1, 7) as trx_mon
,last_day(max(trx_time)) as last_day
,day(last_day(max(trx_time))) as days_of_mon
,sum(trx_amt) as trx_amt
,count(1) as trx_cnt
,sum(trx_amt) / day(last_day(max(trx_time))) as avg_day_amt
,count(1) / day(last_day(max(trx_time))) as avg_day_cnt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
and mch_typ = '休闲娱乐'
group by substr(trx_time, 1, 7);
select substr(trx_time, 1, 7) as trx_mon
,last_day(max(trx_time)) as last_day
,day(last_day(max(trx_time))) as days_of_mon
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
and mch_typ = '休闲娱乐'
group by substr(trx_time, 1, 7);
select substr(trx_time, 1, 7) as trx_mon
,last_day(max(trx_time)) as last_day
,day(last_day(max(trx_time))) as days_of_mon
,sum(trx_amt) as trx_amt
,count(1) as trx_cnt
,sum(trx_amt) / day(last_day(max(trx_time))) as avg_day_amt
,count(1) / day(last_day(max(trx_time))) as avg_day_cnt
from cmb_usr_trx_rcd
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
group by substr(trx_time, 1, 7);
select typ.mch_typ
,count(1) as trx_cnt
,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where rcd.usr_id = '5201314520'
and year(rcd.trx_time) = 2024
group by typ.mch_typ
select typ.mch_typ
,count(1) as trx_cnt
,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where rcd.usr_id = '5201314520'
group by typ.mch_typ
select typ.mch_typ
,count(1) as trx_cnt
,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
group by typ.mch_typ
select
*
from
cmb_usr_trx_rcd
where
trx_amt = (
select max(trx_amt)
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and year(trx_time) = 2024
)
and usr_id = '5201314520'
and year(trx_time) = 2024;
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;
with res_loc as (
select loc_nm
from loc_nm_ctg
where loc_ctg = '餐饮'
)
select *
from didi_sht_rcd
where start_loc in (select loc_nm from res_loc)
and end_loc in (select loc_nm from res_loc);
SELECT
v.video_id,
v.title,
ROUND(SUM((TIMESTAMPDIFF(SECOND, u.start_time, u.end_time))) / 3600, 2) AS total_play_duration_hours
FROM
ks_video_inf v
JOIN
ks_video_wat_log u ON v.video_id = u.video_id
WHERE
u.start_time >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
GROUP BY
v.video_id, v.title
ORDER BY
total_play_duration_hours DESC
LIMIT 5;
select substr(trx_time, 1, 7) as trx_mon
,count(1) as trx_cnt
,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and substr(trx_time, 1, 10) between '2022-11-01' and '2024-12-31'
and (truncate(trx_amt, 0) like '%88' or truncate(trx_amt, 0) like '%98')
and trx_amt > 200
and (hour(trx_time) between 0 and 3 or hour(trx_time) = 23)
and mch_nm rlike '.*(足疗|保健|按摩|养生|SPA)*.'
group by trx_mon
order by trx_mon;
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
else '6.other' end as ser_typ
,count(1) as trx_cnt
,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
where usr_id='5201314520' and mch_nm='红玫瑰按摩保健休闲'
group by ser_typ
order by ser_typ;
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
else 'other' end as ser_typ
,count(1) as trx_cnt
,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
where usr_id='5201314520' and mch_nm='红玫瑰按摩保健休闲'
group by ser_typ
order by ser_typ;
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
else 'other' end as ser_typ
,count(1) as trx_cnt
,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
group by ser_typ
order by ser_typ;
select usr_id
,mch_nm
,sum(trx_amt) as trx_amt
,count(1) as trx_cnt
,min(trx_time) as first_time
from cmb_usr_trx_rcd
where usr_id = 5201314520 and trx_amt >= 288
group by usr_id, mch_nm;
select trx_amt
,count(1) as total_trx_cnt
,count(distinct usr_id) as unique_usr_cnt
,count(1) / count(distinct usr_id) as avg_trx_per_user
from cmb_usr_trx_rcd
where mch_nm = '红玫瑰按摩保健休闲'
and substr(trx_time, 1, 10) between '2023-01-01' and '2024-06-30'
group by trx_amt
order by avg_trx_per_user desc
limit 5;
select coupon_id
,coupon_type
,discount_rule
,valid_days
from coupons
where coupon_id not in (
select distinct coupon_id
from user_coupons
where get_time is not null
)