select
start_loc,
end_loc,
start_ctg,
end_ctg,
cnt
from
(select
start_loc,
end_loc,
count(*) cnt,
start_ctg,
end_ctg,
row_number()over(partition by case when end_ctg='酒店' then start_ctg else end_ctg end order by count(*) desc) as rnk
from
(select
a.start_loc,
a.end_loc,
b.loc_ctg as start_ctg,
c.loc_ctg as end_ctg
from didi_sht_rcd a
left join loc_nm_ctg b on a.start_loc=b.loc_nm
left join loc_nm_ctg c on a.end_loc=c.loc_nm
where (b.loc_ctg='酒店' or c.loc_ctg='酒店')and c.loc_ctg is not null and b.loc_ctg is not null)t1
group by start_loc,end_loc,start_ctg,end_ctg
order by cnt desc
)t2
where rnk=1
order by cnt desc,start_loc asc 请问我的代码在哪里的逻辑上有问题啊
select
count(case when cnt between 1 and 5 then usr_id end),
count(case when cnt between 6 and 10 then usr_id end),
count(case when cnt between 11 and 20 then usr_id end),
count(case when cnt >20 then usr_id end)
from
(select
usr_id,
count(distinct login_date) as cnt
from
(select
usr_id,
date(login_time) as login_date
from user_login_log
where login_time>=date_sub(curdate(),interval 180 day))t1
group by usr_id)t2
select
year(list_date) as Y
,
case when right(ts_code,2)='SZ' then '深交所'
when right(ts_code,2)='SH' then '上交所'
when right(ts_code,2)='BJ' then '北交所'
end as jys
,industry
,count(1) as cnt
from stock_info
where industry in ('银行','软件服务') and year(list_date) between '2019' and '2024'
group by 1,2,3
order by 1,2,3
select
case when right(ts_code,2)='SZ' then '深交所'
when right(ts_code,2)='SH' then '上交所'
when right(ts_code,2)='BJ' then '北交所'
end as jys
,industry
,count(1) as cnt
from stock_info
where industry in ('银行','软件服务')
group by 1,2
order by 3 desc
select
year(list_date) as Y
,sum(case when industry in ('全国地产','区域地产') then 1 else 0 end) as '地产'
,sum(case when industry ='软件服务' then 1 else 0 end) as '软件服务'
from
stock_info
where
year(list_date) between 2000 and 2024
group by
year(list_date)
order by 1
select
substr(trx_time,1,7) as trx_mon,
last_day(max(trx_time)) as last_day,
day(last_day(max(trx_time)) ) as day_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 a
left join cmb_mch_typ m
on a.mch_nm = m.mch_nm
where a.usr_id=5201314520 and year(a.trx_time) in (2023, 2024) and m.mch_typ='休闲娱乐'
group by substr(a.trx_time,1,7)
order by 1
select
substr(trx_time,1,7) as trx_mon,
last_day(max(trx_time)) as last_day,
day(last_day(max(trx_time))) as day_of_mon
from cmb_usr_trx_rcd a
left join cmb_mch_typ b on a.mch_nm=b.mch_nm
where a.usr_id='5201314520' and year(a.trx_time) in (2023,2024) and b.mch_typ='休闲娱乐'
group by substr(a.trx_time,1,7)
order by 1
select
substr(trx_time,1,7) as trx_mon,
last_day(max(trx_time)) as last_day
from cmb_usr_trx_rcd
where usr_id='5201314520' and year(trx_time) in (2023,2024)
group by trx_mon
order by 1
WITH TimeExtracted AS (
SELECT
cust_uid,
start_loc,
end_loc,
CAST(SUBSTR(start_tm, 4, 2) AS SIGNED) AS hour,
car_cls
FROM didi_sht_rcd
),
FilteredData AS (
SELECT *
FROM TimeExtracted
WHERE hour BETWEEN 18 AND 23
),
HourlyCounts AS (
SELECT
hour,
COUNT(*) AS total_orders,
SUM(CASE WHEN car_cls = 'A' THEN 1 ELSE 0 END) AS A_orders
FROM FilteredData
GROUP BY hour
),
PercentageAOrders AS (
SELECT
hour,
(A_orders * 100.0 / total_orders) AS percentage_A_orders
FROM HourlyCounts
),
AggregatedData AS (
SELECT
COUNT(*) AS n,
SUM(hour) AS sum_x,
SUM(percentage_A_orders) AS sum_y,
SUM(hour * percentage_A_orders) AS sum_xy,
SUM(hour * hour) AS sum_x2,
SUM(percentage_A_orders * percentage_A_orders) AS sum_y2
FROM PercentageAOrders
)
SELECT
cast((n * sum_xy - sum_x * sum_y) /
(SQRT(n * sum_x2 - sum_x * sum_x) * SQRT(n * sum_y2 - sum_y * sum_y)) as decimal(10,2)) AS R
FROM AggregatedData;
select
t.mch_typ,
u.mch_nm,
count(u.mch_nm),
sum(trx_amt)
from cmb_usr_trx_rcd u
left join cmb_mch_typ t on u.mch_nm=t.mch_nm
where u.usr_id='5201314520' and year(trx_time)=2024
group by t.mch_typ,
u.mch_nm
having t.mch_typ is null
select
m.mch_typ,
count(u.mch_nm),
sum(u.trx_amt)
from cmb_usr_trx_rcd u
left join cmb_mch_typ m on u.mch_nm=m.mch_nm
where u.usr_id='5201314520' and year(u.trx_time)=2024
group by m.mch_typ
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where (date(trx_time)>'2022-11-01' and date(trx_time)<='2024-12-31') and usr_id='5201314520'and ((trx_amt>200 and (substr(trx_amt,-5) like '88%' or substr(trx_amt,-5)like '98%') and hour(trx_time) in (0,23,1,2)) or upper(mch_nm) rlike ('足疗|保健|按摩|养生|SPA'))
group by trx_mon
order by trx_mon
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where (date(trx_time)>'2022-11-01' and date(trx_time)<='2024-12-31') and usr_id='5201314520'and ((trx_amt>200 and (substr(trx_amt,-5)='88.00' or substr(trx_amt,-5)='98.00') and hour(trx_time) in (0,23,1,2)) or upper(mch_nm) rlike ('足疗|保健|按摩|养生|SPA'))
group by trx_mon
order by trx_mon
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where date(trx_time) between'2022-11-01' and '2024-12-31' and usr_id='5201314520'and ((trx_amt>200 and (substr(trx_amt,-5)='88.00' or substr(trx_amt,-5)='98.00') and hour(trx_time) in (0,23,1,2)) or upper(mch_nm) rlike ('足疗|保健|按摩|养生|SPA'))
group by trx_mon
order by trx_mon
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where trx_time between'2022-11-01' and '2024-12-31' and usr_id='5201314520'and ((trx_amt>200 and (substr(trx_amt,-5)='88.00' or substr(trx_amt,-5)='98.00') and hour(trx_time) in (0,23,1,2)) or upper(mch_nm) rlike ('足疗|保健|按摩|养生|SPA'))
group by trx_mon
order by trx_mon
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where trx_time between'2022-11-01' and '2024-12-31' and (substr(trx_amt,-5)='88.00' or substr(trx_amt,-5)='98.00') and usr_id='5201314520' and upper(mch_nm) rlike ('足疗|保健|按摩|养生|SPA')
and (hour(trx_time)=23 or (hour(trx_time) between 0 and 2))
group by trx_mon
order by trx_mon
select
date_format(trx_time,'%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt1
from cmb_usr_trx_rcd
where trx_time between'2022-11-01' and '2024-12-31' and (substr(trx_amt,-5)='88.00' or substr(trx_amt,-5)='98.00') and usr_id='5201314520' and mch_nm rlike ('足疗|保健|按摩|养生|SPA')
group by trx_mon
order by trx_mon