房天下 > 房天下问答 > 业主生活 > 其他
  • 求高人指点一下这个sql语句该怎么写,急!!!

    有一个tb_Questions表中有个字段为type,type的值为:单选题和多选题,还有一个lessonId(课程号)字段表示此题属于哪个课程,现在想选择出单选题和多选题都大于2的课程号。想用group by和having语句可是一个sql语句中只能出现一个group by语句,不知道怎么办,求高人指点,感激不尽!!!

    提问者:张永5910

    发布于2011-01-04

共1个回答
  • 只住别墅 丨Lv 2
    你试一下 那个count后面跟的应该是group by后面跟的一样select a.lessonId from tb_Questions a,tb_Questions bwhere 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 bwhere a.type='单选题' or b.type='多选题' group by a.lessonId,b.lessonIdhaving count(a.lessonId)>=2 and count(b.lessonId )>=2
    +1 2011-01-05 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。