Sql Server : How to use an aggregate function like MAX in a WHERE clause

前端 未结 6 1170
灰色年华
灰色年华 2020-12-03 04:48

I want get the maximum value for this record. Please help me:

SELECT rest.field1 
    FROM mastertable AS m
    INNER JOIN  (
        SELECT t1.field1 field1         


        
6条回答
  •  Happy的楠姐
    2020-12-03 05:21

    As you've noticed, the WHERE clause doesn't allow you to use aggregates in it. That's what the HAVING clause is for.

    HAVING t1.field3=MAX(t1.field3)
    

提交回复
热议问题