首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

max()group by的应用有关问题,求解

2012-08-16 
max()group by的应用问题,求解。如果有t1(year,company,tax)--------------2010 comp1 1002011 comp1 20020

max()group by的应用问题,求解。
如果有t1(year,company,tax)
--------------
2010 comp1 100
2011 comp1 200
2011 comp2 100
2012 comp2 300

需要的结果
公司最新一年的年份,公司名,纳税金额
2011 comp1 200
2012 comp2 300

应该怎样写查询语句?

[解决办法]

SQL code
select * from t1 twhere not exists(select 1 from t1 where company=t.company and [year]>t.[year])
[解决办法]
SQL code
select [year],company,tax from t1    where tax=(select max(tax) from t1 t2 where t2.company=t1.company)order by t1.company 

热点排行