SQL查询 - 我可以总结同一个国家/地区的值

时间:2013-12-07 17:15:36

标签: sql sql-server

我提出了这个问题:

SELECT        Projects.proj_contract_value, customers.cust_name, customers.cust_country
FROM            customers INNER JOIN
                Projects ON customers.id = Projects.id
                Where Projects.proj_date >= Convert(datetime, '2013-01-01' )
                Order By cust_country

这使我完全回复了我编码的内容:

216000000   OBB                     AUSTRIA
380000000   Eurotunnel              FRANCE
42000000    FAL                     ITALY
66000000    Ferrovie della Calabria ITALY
34200000    Ferrovie del Gargano    ITALY
247300000   Ferrovie del Sud Est    ITALY
85000000    Sistemi Territoriali    ITALY
10239000    Ferrovie Nord           ITALY
33100000    Spoorwegen              NETHERLANDS
184000000   RZhD                    RUSSIAN FEDERATION
119000000   Prasa                   SOUTH AFRICA
273000000   Renfe                   SPAIN
1423000000  Thurbo                  SWITZERLAND
285000000   SBB                     SWITZERLAND
1800000000  TCDD                    TURKEY

我的最终目标是消除客户名称并获取每个国家/地区总结的每个国家/地区的价值,以便我可以获得每个国家/地区的总价值。我正在努力解决这个问题。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

SELECT c.cust_country, 
       sum(p.proj_contract_value) as value_sum
FROM customers c
INNER JOIN Projects p ON c.id = p.id
Where p.proj_date >= Convert(datetime, '2013-01-01')
group by c.cust_country
Order By c.cust_country