0
slno state district company 
1     a       ab     abc
2     a       ab     ac
3     a       ab     abc
4     a       ab     abc
5     a       ab     abc
6     a       ab     ac

输出

state district company sumzz
 a      ab       abc    4
 a      ab       ac     2

我试过的

select state,district,company,sum(company) as sumzz from company

如何实现基于不同公司的显示最后一行?

4

4 回答 4

2

编辑:对于更新的问题,您可以slno在子查询中检索最大值。然后你可以in用来过滤那些:

select  state
,       district
,       company
,       slno
from    Company
where   slno in
        (
        select  max(slno)
        from    Company
        group by
                state
        ,       district
        ,       company
        )
于 2012-07-06T21:29:33.187 回答
2

这种方法有什么问题:

  SELECT state, district, company, COUNT(*) as countzz
    FROM company
GROUP BY state, district, company
于 2012-07-06T21:32:01.290 回答
2

我认为您正在尝试计算有多少记录而不是求和。如果那是您想要的,那么您应该这样做:

SELECT state, district, company, COUNT(*) as sumzz 
FROM company
GROUP BY state, district, company
于 2012-07-06T21:32:15.687 回答
0

选择 state,district,company,sum(company) as sumzz from company where company = 'abc'

于 2012-07-06T21:35:05.243 回答