doupu9251 2014-03-22 09:24
浏览 26

如果清除状态等于1,则MYSQL选择student_id

Table name : batch_1_student_marks

i am having student mark list in batch_1_student_marks table.

where "cleared" is representing the student pass/fail status.
cleared = 1 (pass)
cleared = 0 (fail)

In the following table student_id 2 is only having cleared status 1 in all rows. i dont want to select student_id 1 and 3 because it having cleared status 0 in corresponding rows.

if i use the following query it will give the result,
SELECT student_id from batch_1_student_marks WHERE student_id=2 and cleared=1. but this query is not suitable for student_id 1 and 3. because i dont want to select student_id if it has cleared 0 in even single row......... please help me to do a query...

|id| |semester| |student_id| |subject_id| |grade| |marks| |cleared|
1 -----1 --------------1-------------1-----------a---------8--------0
1 -----1 --------------1-------------2-----------b---------9--------1
1 -----1 --------------1-------------3-----------d---------2--------0
1 -----1 --------------1-------------8-----------e---------4--------1
1 -----1 --------------1-------------2-----------b---------9--------1
1 -----1 --------------1-------------3-----------d---------2--------1
1 -----1 --------------1-------------8-----------e---------4--------1
1 -----1 --------------1-------------2-----------b---------9--------0

1 -----1 --------------2-------------3-----------d---------2--------1
1 -----1 --------------2-------------8-----------e---------4--------1
1 -----1 --------------2-------------3-----------d---------2--------1
1 -----1 --------------2-------------8-----------e---------4--------1
1 -----1 --------------2-------------3-----------d---------2--------1
1 -----1 --------------2-------------8-----------e---------4--------1

1 -----1 --------------3-------------3-----------d---------2--------1
1 -----1 --------------3-------------8-----------e---------4--------0
1 -----1 --------------3-------------3-----------d---------2--------1
1 -----1 --------------3-------------8-----------e---------4--------0
1 -----1 --------------3-------------3-----------d---------2--------1
1 -----1 --------------3-------------8-----------e---------4--------0

  • 写回答

3条回答 默认 最新

  • dty63504 2014-03-22 09:30
    关注

    Just use the following query:

    SELECT student_id FROM batch_1_student_marks WHERE cleared='1';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)