想请问一下怎么排除NULL的影响呢?这个NULL是指缺考还是考试不及格呢?
select student_id,max(score) max_score, min(score) min_score, avg(score) avg_score
from scores
where student_id not in(
select student_id
from scores
where score is null)
group by student_id
having min(score)>=80
order by student_id
上面是我写的代码,想请问一下错误原因
where date_format(enter_time,'%Y-%m-%d %H')='2021-09-12 23'
请问一下这个为什么没办法筛选时间呢?
如下代码可以通过测试呀,你再试试呢。 SELECT
t2.live_id,
t2.live_nm,
COUNT(*) AS enter_cnt
FROM
ks_live_t1 t1
JOIN
ks_live_t2 t2
ON
t1.live_id = t2.live_id
WHERE
DATE_FORMAT(t1.enter_time, '%Y-%m-%d %H') = '2021-09-12 23'
GROUP BY
t1.live_id, t2.live_nm
ORDER BY
enter_cnt DESC
LIMIT 5;
一个小问题,题目写到‘探索,渣男经常去,而你男朋友没去过的,究竟是哪些商户呢?’。那应该在表连接之后筛选出渣男去过了,但是男朋友没去过的店铺,这更符合题意吧
select a.mch_nm asshole_tried,a.trx_cnt,b.mch_nm darling_tried
from
(select mch_nm,count(mch_nm) trx_cnt
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time) in (2023,2024)
group by mch_nm
having count(mch_nm)>=20) a
left join
(select distinct(mch_nm)
from cmb_usr_trx_rcd
where usr_id=5211314521 and year(trx_time)in(2023.2024))b on a.mch_nm=b.mch_nm
where b.mch_nm is null
order by a.trx_cnt desc
select student_id,max(score) max_score, min(score) min_score, avg(score) avg_score
from scores
group by student_id
having min(score)>=80
order by student_id
select klt1.live_id,klt2.live_nm,count(distinct klt1.usr_id) enter_cnt
from ks_live_t1 klt1 join ks_live_t2 klt2 using(live_id)
where date_format(klt1.enter_time,'%Y-%m-%d')='2021-09-12' and hour(klt1.enter_time)=23
group by klt1.live_id,klt2.live_nm
order by enter_cnt desc
limit 5
select a.mch_nm asshole_tried,a.trx_cnt, b.mch_nm darling_tried
from
(select mch_nm,count(mch_nm) trx_cnt
from cmb_usr_trx_rcd
where usr_id='5201314520'and(year(trx_time) in (2023,2024))
group by mch_nm
having count(mch_nm)>=20) a
left join
(select distinct(mch_nm)
from cmb_usr_trx_rcd
where usr_id='5211314521' and year(trx_time) in(2023,2024)) b
using (mch_nm)
order by trx_cnt desc
select a.mch_nm asshole_tried,a.trx_cnt,b.mch_nm darling_tried
from
(select mch_nm,count(mch_nm) trx_cnt
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time) in (2023,2024)
group by mch_nm
having count(mch_nm)>=20) a
left join
(select distinct(mch_nm)
from cmb_usr_trx_rcd
where usr_id=5211314521 and year(trx_time)in(2023.2024))b on a.mch_nm=b.mch_nm
order by a.trx_cnt desc
select a.mch_nm asshole_tried,a.trx_cnt,b.mch_nm darling_tried
from
(select mch_nm,count(mch_nm) trx_cnt
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time) in (2023,2024)
group by mch_nm
having count(mch_nm)>=20) a
left join
(select mch_nm
from cmb_usr_trx_rcd
where usr_id=5211314521 and year(trx_time)in(2023.2024))b on a.mch_nm=b.mch_nm
where b.mch_nm is null
order by a.trx_cnt desc
select b.mch_nm
from
(select distinct(mch_nm)
from cmb_usr_trx_rcd
where usr_id='5201314520' and year(trx_time)=2024 ) b
join
(select distinct(mch_nm)
from cmb_usr_trx_rcd
where usr_id='5211314521' and year(trx_time)=2024) a
using(mch_nm)
order by mch_nm desc
select distinct(a.mch_nm)
from cmb_usr_trx_rcd cutr join
(
select mch_nm
from cmb_usr_trx_rcd
where usr_id=5211314521 and year(trx_time)=2024) aon cutr.mch_nm=a.mch_nm
where cutr.usr_id=5201314520 and year(cutr.trx_time)=2024
order by a.mch_nm desc
select distinct(a.mch_nm)
from cmb_usr_trx_rcd cutr join
(
select mch_nm
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time)=2024) aon cutr.mch_nm=a.mch_nm
where cutr.usr_id=5201314520 and year(cutr.trx_time)=2024
order by a.mch_nm desc
select*
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time)=2024 and trx_amt=(
select max(trx_amt)
from cmb_usr_trx_rcd
where usr_id=5201314520 and year(trx_time)=2024)
select a.ser_typ,count(a.ser_typ) trx_cnt,min(date(a.trx_time)) first_date
from(
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 )ser_typ
from cmb_usr_trx_rcd) a
where a.usr_id=5201314520 and a.mch_nm='红玫瑰按摩保健休闲'
group by a.ser_typ
order by a.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 '6.other'
end as ser_type
,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_type
order by 1
select a.ser_type,count(a.ser_type) trx_cnt,min(date(a.trx_time)) first_date
from(
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 )ser_type
from cmb_usr_trx_rcd) a
where a.usr_id=5201314520 and a.mch_nm='红玫瑰按摩保健休闲'
group by a.ser_type
order by a.ser_type;
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 1
select a.ser_type,count(a.ser_type) trx_cnt,min(date(a.trx_time)) first_date
from(
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 ser_type
from cmb_usr_trx_rcd) a
where a.usr_id=5201314520 and a.mch_nm='红玫瑰按摩保健休闲'
group by a.mch_nm,a.ser_type
order by a.ser_type
select usr_id, mch_nm ,sum(trx_amt) trx_amt, count(trx_amt) trx_cnt, min(trx_time) first_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
select usr_id, mch_nm ,sum(trx_amt) trx_amt, count(trx_amt) trx_cnt, min(trx_time) first_time
from cmb_usr_trx_rcd
where usr_id=5201314520
group by usr_id, mch_nm
having sum(trx_amt)>=288
order by trx_cnt desc
select usr_id, mch_nm ,sum(trx_amt) trx_amt, count(trx_amt) trx_cnt, min(trx_time) first_time
from cmb_usr_trx_rcd
where usr_id=5201314520
group by usr_id, mch_nm
order by trx_cnt desc