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 (DATE_FORMAT(login_time, '%H:%i:%s') between '07:30:00' and '09:30:00' )
or (DATE_FORMAT(login_time, '%H:%i:%s') between '18:30:00' and '20:30:00' )
then usr_id
else null end) as commute,
count(distinct(case when DATE_FORMAT(login_time, '%H:%i:%s') between '11:30:00' and '14:00:00' then usr_id else null end)) as lunch_break,
count(distinct case when (DATE_FORMAT(login_time, '%H:%i:%s') between '00:00:00' and '01:00:00' )
or (DATE_FORMAT(login_time, '%H:%i:%s') between '22:30:00' and '23:59:59' )
then usr_id
else null end) as commute
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
sum(
case when (DATE_FORMAT(login_time, '%H:%i:%s') between '07:30:00' and '09:30:00' )
or (DATE_FORMAT(login_time, '%H:%i:%s') between '18:30:00' and '20:30:00' )
then 1
else null end) as commute,
sum((case when DATE_FORMAT(login_time, '%H:%i:%s') between '11:30:00' and '14:00:00' then 1 else null end)) as lunch_break,
sum(case when (DATE_FORMAT(login_time, '%H:%i:%s') between '00:00:00' and '01:00:00' )
or (DATE_FORMAT(login_time, '%H:%i:%s') between '22:30:00' and '23:59:59' )
then 1
else null end) as commute
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(avg(casewhen city = 'beijing' then tmp_h else null end) as decimal(4,2)) as 北京
,cast(avg(casewhen city = 'shanghai' then tmp_h else null end) as decimal(4,2)) as 上海
,cast(avg(casewhen city = 'shenzhen' then tmp_h else null end) as decimal(4,2)) as 深圳
,cast(avg(casewhen city = 'guangzhou' then tmp_h else null end) as decimal(4,2)) as 广州
from weather_rcd_china
group by
year(dt)
select
year(dt) as Y,
round(avg(casewhen city = 'beijing' then tmp_h else null end),2) as 北京
,round(avg(casewhen city = 'shanghai' then tmp_h else null end),2) as 上海
,round(avg(casewhen city = 'shenzhen' then tmp_h else null end),2) as 深圳
,round(avg(casewhen city = 'guangzhou' then tmp_h else null end),2) as 广州
from weather_rcd_china
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(1,2,12)
group by
city
order by
2 desc
select *
from cmb_usr_trx_rcd
where
usr_id='5201314520'
and trx_amt IN(
select
MAX(trx_amt)
from
cmb_usr_trx_rcd
where
usr_id='5201314520'
group by
usr_id
)
select
(case trx_amt
when 288 then '1.WithHand'
when 388 then '2.WithMimi'
when 588 then '3.BlowJobbie'
when 888 then '4.Doi'
when 1288 then '5.DoubleFly'
else '6.other'
end ) as ser_typ
,count(1) as trx_cnt
,date(MIN(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 ASC
select usr_id,mch_nm,SUM(trx_amt),count(1) as trx_cnt,MIN(trx_time)
from cmb_usr_trx_rcd
where
usr_id = '5201314520'
and trx_amt > 287
group by
usr_id,mch_nm
order by
trx_cnt desc
select usr_id,mch_nm,SUM(trx_amt),count(1) as trx_cnt,MIN(trx_time)
from cmb_usr_trx_rcd
where
usr_id = '5201314520'
and trx_amt > 287
group by
usr_id,mch_nm
order by
trx_cnt desc
limit 5;
select usr_id,mch_nm,SUM(trx_amt),count(1) as trx_cnt,MIN(trx_time)
from cmb_usr_trx_rcd
where
usr_id = '5201314520'
and trx_amt > 288
group by
usr_id,mch_nm
order by
trx_cnt desc
limit 5;
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 date(trx_time) between '2023-01-01' and '2024-06-30'
group by
trx_amt
order by
avg_trx_per_user desc
limit 5;
select trx_amt,count(usr_id) as trx_cnt
from cmb_usr_trx_rcd
where mch_nm like '红玫瑰按摩保健休闲'
and date(trx_time) between '2024-01-01' and '2024-07-31'
group by
trx_amt
order by
trx_cnt DESC
limit 5
select date(trx_time),max(trx_amt),min(trx_amt),avg(trx_amt),sum(trx_amt)
from cmb_usr_trx_rcd
where mch_nm = '红玫瑰按摩保健休闲'
and date(trx_time) like '2024-09%'
group by date(trx_time)
order by date(trx_time)