select
s.student_id,
s.name,
sc.score,
row_number()over(order by sc.score desc) as rnk
from students s
left join scores sc
on sc.student_id = s.student_id
where sc.subject = '物理'
and s.grade_code = 'S1'
order by rnk,s.student_id
limit 10;
这个输出结果都是一样的为什么不正确?
select
trx_amt,
count(*) as total_trx_cnt,
count(distinct usr_id) as unique_usr_cnt,
round(count(*)/count(distinct usr_id),4) as avg_trx_per_user
from cmb_usr_trx_rcd
where ((year(trx_time) = 2023 and month(trx_time) between 1 and 12)
or (year(trx_time) = 2024 and month(trx_time) between 1 and 6))
and mch_nm = "红玫瑰按摩保健休闲"
group by trx_amt
order by round(count(*)/count(distinct usr_id),4) desc
limit 5;
select
trx_amt,
count(*) as total_trx_cnt,
count(distinct usr_id) as unique_usr_cnt,
round(count(*)/count(distinct usr_id),4) as avg_trx_per_user
from cmb_usr_trx_rcd
where year(trx_time) = 2023
and month(trx_time) between 1 and 6
and mch_nm = "红玫瑰按摩保健休闲"
group by trx_amt
order by round(count(*)/count(distinct usr_id),4) desc
limit 5;
select
trx_amt,
count(*) as total_trx_cnt,
count(distinct usr_id) as unique_usr_cnt,
round(count(*)/count(distinct usr_id),4) as avg_trx_per_user
from cmb_usr_trx_rcd
where year(trx_time) = 2023
and month(trx_time) between 1 and 6
and mch_nm = "红玫瑰按摩保健休闲"
group by trx_amt
order by count(*) desc
limit 5;
select
trx_amt,
count(*) as trx_cnt
from cmb_usr_trx_rcd
where year(trx_time) = 2024
and month(trx_time) between 1 and 7
and mch_nm = "红玫瑰按摩保健休闲"
group by trx_amt
order by count(*) desc
limit 5 ;
select date(trx_time) as trx_date,
max(trx_amt) as max_trx_amt,
min(trx_amt) as min_tex_amt,
round(sum(trx_amt)/count(*),6) as avg_trx_amt,
sum(trx_amt) as sum_trx_amt
from cmb_usr_trx_rcd
where mch_nm = "红玫瑰按摩保健休闲"
and date(trx_time) between '2024-09-01' and '2024-09-30'
group by date(trx_time)
order by date(trx_time);
select mch_nm,sum(trx_amt) as sum_trx_amt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and year(trx_time) = 2024
group by mch_nm
order by sum(trx_amt) desc;
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) >= 22)
or (hour(trx_time) between 0 and 5))
order by trx_time asc;
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) >= 22
or hour(trx_time) between 0 and 5
order by trx_time asc;
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) >= 22
or hour(trx_time) between 0 and 5
order by trx_time ;
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 1 and 5
order by trx_time asc;
select usr_id,mch_nm,trx_time,trx_amt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and date(trx_time) between '2024-09-01' and '2024-09-30'
group by usr_id,mch_nm,trx_time,trx_amt
order by trx_time asc;
select usr_id,mch_nm,trx_time,trx_amt
from cmb_usr_trx_rcd
where usr_id = 5201314520
and trx_time between '2024-09-01' and '2024-09-30'
group by usr_id,mch_nm,trx_time,trx_amt
order by trx_time asc;
select student_id,subject,score,exam_date
from scores
where exam_date = '2024-06-30'
and case when subject in ("历史","政治","地理") then score end >= 90
group by student_id,subject,score,exam_date
order by score desc,student_id,subject;
select student_id,subject,score,exam_date
from scores
where exam_date = '2024-06-30'
and case when subject = "英语" then score end between 100 and 110
group by student_id,subject,score,exam_date
order by score desc;
select student_id,name,class_code,grade_code,birth_date,residence,gender
from students
where class_code in ('C219','C220','C221') and gender = 'f'
group by student_id,name,class_code,grade_code,birth_date,residence,gender
order by student_id;
select student_id,chinese,math,english
from subject_score
where chinese > 100 or math > 100 or english > 100
group by student_id,chinese,math,english
order by chinese asc;
select
exam_date,
max(case when subject = "语文" then score else NULL end) as chinese_score,
max(case when subject = "数学" then score else NULL end) as math_score,
max(case when subject = "英语" then score else NULL end) as English_score
from scores
where student_id = 460093 and subject in ("语文","数学","英语")
group by exam_date
order by exam_date;
select student_id,sum(score) as total_score
from scores
where subject in ("语文","数学","英语")
and exam_date = "2024-06-30"
group by student_id
having sum(score) > 330;
select student_id,sum(score) as total_score
from scores
where subject in ("语文","数学","英语")
and exam_date = "2024-06-30"
group by student_id
having sum(score) >= 330;