如何在SQL中设置临时列的条件?

问题描述 投票:0回答:1
USE COLEGIUU
SELECT NmStud, PrenStud, 
      NotaMedie = (SELECT AVG(N.Nota) FROM [Notele] N WHERE N.idStudent = S.IdStudent)
  FROM Student S
  WHERE idStudent IN(SELECT idStudent FROM Notele GROUP BY idStudent)

NotaMedie是具有可计算值的临时列。我如何仅输出NotaMedie> 9的行?

mysql join group-by ssms
1个回答
0
投票

您可以使用having子句加入,聚合和过滤:

select s.NmStud, s.PrenStud, avg(n.Nota) NotaMedie
from student s
inner join notele n on n.idStudent = s.idStudent
group by s.NmStud, s.PrenStud
having avg(n.Nota) > 9

© www.soinside.com 2019 - 2024. All rights reserved.