浅浅星空 2022-11-20 15:42 采纳率: 66.7%
浏览 2

mysqlcountif记录为空

为什么这样写活动一的输出结果中会有uid=none而没有1005的记录呀~~已经限制了非空了呀,又是想了一下午啥没想出来的一天。

img

select * from(
select if(count(if(score>=85,1,null))=count(uid),uid,null) as uid,'activity1' as activity
from
(select uid,score,submit_time,start_time,release_time from exam_record 
join examination_info using(exam_id)
where tag='SQL'
)a
where uid is not null
group by uid
)t1
union
select * from(
select if(count(if(timestampdiff(second,start_time,submit_time)<=duration*30 and score>80 and year(start_time)=2021 and difficulty='hard',1,null))>=1,uid,null) as uid,'activity2' as activity
from
(select uid,score,submit_time,start_time,release_time,duration,difficulty from exam_record 
join examination_info using(exam_id)
where tag='SQL'
)a
where uid is not null
group by uid
) t2
where uid is not null
order by uid

  • 写回答

1条回答 默认 最新

  • 鱼找水需要时间 优质创作者: Java技术领域 2022-11-20 20:16
    关注

    在数据库执行看看 uid为空的那条数据,是null还是空字符串呢

    评论

报告相同问题?

问题事件

  • 创建了问题 11月20日