2017-03-07 02:01:00 +01:00
|
|
|
-- http://www.sqlserver-dba.com/2011/09/this-is-a-followup-on-my-earlier-post-of-sql-server-test-data-generation-testing-tools-i-had-some-requests-for-my-set-up-pr.html
|
|
|
|
SELECT NATION, O_YEAR, SUM(AMOUNT) AS SUM_PROFIT
|
|
|
|
FROM (SELECT N_NAME AS NATION, datepart(yy, O_ORDERDATE) AS O_YEAR,
|
|
|
|
L_EXTENDEDPRICE*(1-L_DISCOUNT)-PS_SUPPLYCOST*L_QUANTITY AS AMOUNT
|
2017-03-07 02:49:29 +01:00
|
|
|
FROM "PART", SUPPLIER, LINEITEM, PARTSUPP, ORDERS, NATION
|
2017-03-07 02:01:00 +01:00
|
|
|
WHERE S_SUPPKEY = L_SUPPKEY AND PS_SUPPKEY= L_SUPPKEY AND PS_PARTKEY = L_PARTKEY AND
|
|
|
|
P_PARTKEY= L_PARTKEY AND O_ORDERKEY = L_ORDERKEY AND S_NATIONKEY = N_NATIONKEY AND
|
|
|
|
P_NAME LIKE '%%green%%') AS PROFIT
|
|
|
|
GROUP BY NATION, O_YEAR
|
|
|
|
ORDER BY NATION, O_YEAR DESC
|