当前位置: 代码迷 >> Sql Server >> sql怎么查询一列相等其他列值最高的
  详细解决方案

sql怎么查询一列相等其他列值最高的

热度:4   发布时间:2016-04-24 18:17:40.0
sql如何查询一列相等其他列值最高的
select * from C_Discount D,C_Users U 
----------------------------------------------
ID DiscountName Discount Required
1 九折         9.5             100
2 九折         9.1             100

如何在Required这一列相同的情况下,选择DISCOUNT列比较大的一行,就选一行

------解决方案--------------------
select * from tb t where not exists(select 1 from tb where Required=t.Required and Discount>t.Discount)

select * from tb t where Discount=(select max(Discount) from tb where Required=t.Required 
  相关解决方案