select
st.student_id,
st.name,
sc.score,
row_number()over(PARTITION BY st.grade_code order by sc.score desc) as rnk
from scores as sc
join students as st on sc.student_id=st.student_id
where st.grade_code = "S1"
and sc.subject = '物理'
limit 10;
select st.student_id,
st.name,sc.score,
row_number()over(order by sc.score desc) as rnk
from scores as sc
join students as st on sc.student_id=st.student_id
where st.grade_code = "S1"
and sc.subject = '物理'
limit 10;
select
p.prd_id,
m.prd_nm,
count(if_snd) exposure_count
from tb_pg_act_rcd as p
join tb_prd_map as m on p.prd_id=m.prd_id
group by p.prd_id,m.prd_nm
order by exposure_count desc
limit 1;
with t as
(select
usr_id,
count(distinct date(login_time)) as f
from user_login_log
where date(login_time) >= date_add(curdate(), interval -180 DAY)
group by usr_id
order by f desc
)
select
count(case when t.f between 1 and 5 then 1 end) as days_1_to_5,
count(case when t.f between 6 and 10 then 1 end) as days_6_to_10,
count(case when t.f between 11 and 20 then 1 end) as days_11_to_20,
count(case when t.f > 20 then 1 end) asdays_over_20
from t
with t as
(select
usr_id,
count(distinct date(login_time)) as f
from user_login_log
where date(login_time) > date_add(curdate(), interval -180 DAY)
group by usr_id
order by f desc
)
select
count(case when t.f between 1 and 5 then 1 end) as days_1_to_5,
count(case when t.f between 6 and 10 then 1 end) as days_6_to_10,
count(case when t.f between 11 and 20 then 1 end) as days_11_to_20,
count(case when t.f > 20 then 1 end) asdays_over_20
from t
with t as
(select
usr_id,
count(case
when date(login_time) >= date_add(curdate(), interval -180 DAY)then 1 end) as f
from user_login_log
group by usr_id
order by f desc)
select
count(case when t.f between 1 and 5 then 1 end) as days_1_to_5,
count(case when t.f between 6 and 10 then 1 end) as days_6_to_10,
count(case when t.f between 11 and 20 then 1 end) as days_11_to_20,
count(case when t.f > 20 then 1 end) asdays_over_20
from t
with t as
(select usr_id,count(case
when date(login_time) between date_add(current_date, interval -180 DAY) and current_date
then 1
end) as f
from user_login_log
group by usr_id
order by f desc)
select
count(case when t.f between 1 and 5 then 1 end) as days_1_to_5,
count(case when t.f between 6 and 10 then 1 end) as days_6_to_10,
count(case when t.f between 11 and 20 then 1 end) as days_11_to_20,
count(case when t.f > 20 then 1 end) asdays_over_20
from t
我是这样筛选的:year(login_time) = year(date_add(now(),INTERVAL -1 MONTH)) and month(login_time) = month(date_add(now(),INTERVAL -1 MONTH))