显示所有出现过的所有科目均获得50分以上成绩的学生的姓名

时间:2018-08-16 16:03:20

标签: oracle

写一个查询,以显示出现在所有学科中的学生都超过50名的所有学生的姓名,并按学生姓名的升序排列。enter image description here

我在下面的查询中使用了此查询,但未获得所需的结果,因为它没有通过将整个Student_id分组来比较结果。 任何人都可以建议对查询进行任何更改。

select distinct student_name from student s join mark m on
s.student_id = m.student_id join subject sb
on m.subject_id = sb.subject_id
where m.value IN 
(select value from mark m1 join student s1
on m1.student_id = s1.student_id join subject sb1
on m1.subject_id = sb1.subject_id
where value > 50 group by s1.student_id,m1.value, sb1.subject_id)
order by 1;

7 个答案:

答案 0 :(得分:1)

select student_name
from student join mark using (student_id)
group by student_name
having min(value) > 50
order by student_name;

如果可能,应避免子查询。因此,通过检查学生的最低分数是否大于50,我们可以说他在所有学科中的得分都超过了50。

答案 1 :(得分:1)

select distinct student_name from student,mark
where student.student_id = mark.student_id
having min(value) > 50
group by student_name
order by student_name;

答案 2 :(得分:0)

我认为您不需要这么复杂的子查询。您所要做的只是找出学生的最低分数(INNER JOIN确保只考虑那些学生尝试过的科目)。

在student_id的student和marks表之间做一个简单的JOIN。我们在function displaymeta( $content ){ global $post; $m_meta_description = get_post_meta($post->ID, 'my_meta_box_check', true); global $wpdb; $user_nicenames = $wpdb->get_results("SELECT id,user_nicename FROM {$wpdb->prefix}users", ARRAY_N); // Add the opening UL tag. Remove if not needed. $content .= '<ul>'; foreach($user_nicenames as $nice_name) { $user_id = $nice_name[0]; $name = $nice_name[1]; foreach($m_meta_description as $val) { $flag=strcmp($name,$val); if($flag==0) { $content .= "<li>"; $content .= $name. "<br>"; $content .= get_avatar($user_id,50); $content .= "</li>"; } } } // Add the closing UL tag. Remove if not needed. $content .= '</ul>'; return $content; } add_filter( 'the_content', 'displaymeta' ); 上进行GROUP BY,并为每个学生得到student_id。如果minimum_marks> 50,则表示该学生在所有科目中得分均> 50。 尝试以下操作,这将在 MySQL 中运行(根据OP的原始标签):

minimum_marks

编辑根据Oracle(自稍后进行OP编辑以来)的规定,SELECT s.student_name, MIN(m.value) AS minimum_marks FROM student s JOIN mark m ON s.student_id = m.student_id GROUP BY s1.student_id HAVING minimum_marks > 50 ORDER BY s.student_name ASC 子句中的aliased fields/expressions are not allowed。修改后的查询如下:

HAVING

答案 3 :(得分:0)

select student_name from student where student_id in
(select student_id 
    from (select student_id ,min(value) from mark group by student_id having min(value)>50)
)
order by student_name;

通过进行如上所示的子查询很简单。

1 。提取大于50的最小值,并创建一个表,然后从学生表中进行比较。

2 。不使用任何Join操作

答案 4 :(得分:0)

select student_name
from student s inner join mark m
on s.student_id= m.student_id
having min(m.value)>50
group by student_name
order by student_name asc;

答案 5 :(得分:0)

select s.student _name from student s join mark m 
on s.student_id = m.student_id
group by s.student_name
having min(m.value) > 50
order by s.student_name;

答案 6 :(得分:0)

select student_name from student
where student_id in (select student_id from mark group by student_id having min(value) > 50)
order by student_name;

`