求高人指点一下这个sql语句该怎么写,急!!!

2025-03-09 13:54:57
推荐回答(2个)
回答1:

你试一下 那个count后面跟的应该是group by后面跟的一样
select a.lessonId from tb_Questions a,tb_Questions b
where a.type='单选题' group by a.lessonId having count(a.lessonId )>=2

不过我感觉 你这个句子表达的就不对
你是不是想找出a b中都满足你提条件的项

不需要在写两个where句子
你这样试一下
select a.lessonId, b.lessonId from tb_Questions a,tb_Questions b
where a.type='单选题' or b.type='多选题' group by a.lessonId,b.lessonId
having count(a.lessonId)>=2 and count(b.lessonId )>=2

回答2:

大于2的字段从哪里来的?你得把名称给我啊。