--
-- MULTI_TPCH_QUERY10
--
-- Query #10 from the TPC-H decision support benchmark.
SELECT
	c_custkey,
	c_name,
	sum(l_extendedprice * (1 - l_discount)) as revenue,
	c_acctbal,
	n_name,
	c_address,
	c_phone,
	c_comment
FROM
	customer,
	orders,
	lineitem,
	nation
WHERE
	c_custkey = o_custkey
	AND l_orderkey = o_orderkey
	AND o_orderdate >= date '1993-10-01'
	AND o_orderdate < date '1993-10-01' + interval '3' month
	AND l_returnflag = 'R'
	AND c_nationkey = n_nationkey
GROUP BY
	c_custkey,
	c_name,
	c_acctbal,
	c_phone,
	n_name,
	c_address,
	c_comment
ORDER BY
	revenue DESC
LIMIT 20;
 c_custkey |       c_name       |   revenue   | c_acctbal |          n_name           |               c_address               |     c_phone     |                                                      c_comment
---------------------------------------------------------------------
       436 | Customer#000000436 | 255187.7382 |   5896.87 | ROMANIA                   | 4DCNzAT842cVYTcaUS94kR0QXHSRM5oco0D6Z | 29-927-687-6390 | olites engage carefully. slyly ironic asymptotes about the ironi
       640 | Customer#000000640 | 251941.1430 |   3025.84 | BRAZIL                    | j3vjr0 n,pJFG4gIOtC                   | 12-702-315-6637 | lly. furiously quick deposits haggle quickly regular packages. pinto
       361 | Customer#000000361 | 239204.0858 |   7451.84 | SAUDI ARABIA              | l0F8jMJVe63cb                         | 30-164-267-4590 | fully busy ideas. regular foxes cajole
       223 | Customer#000000223 | 218652.8040 |   7476.20 | SAUDI ARABIA              | ftau6Pk,brboMyEl,,kFm                 | 30-193-643-1517 | al, regular requests run furiously blithely silent packages. blithely ironic accounts across the furious
       613 | Customer#000000613 | 186092.2017 |   6679.75 | EGYPT                     | AJT,26RbanTdEHOBgTWg                  | 14-275-416-1669 | ironic, pending deposits: quickl
       355 | Customer#000000355 | 168184.4825 |   8727.90 | KENYA                     | 205r3Xg9ZWjPZNX1z                     | 24-656-787-6091 | ly bold requests detect furiously. unusual instructions sleep aft
       872 | Customer#000000872 | 166831.7294 |   -858.61 | PERU                      | vLP7iNZBK4B,HANFTKabVI3AO Y9O8H       | 27-357-139-7164 |  detect. packages wake slyly express foxes. even deposits ru
       805 | Customer#000000805 | 165239.8440 |    511.69 | IRAN                      | wCKx5zcHvwpSffyc9qfi9dvqcm9LT,cLAG    | 20-732-989-5653 | busy sentiments. pending packages haggle among the express requests-- slyly regular excuses above the slyl
       427 | Customer#000000427 | 148033.5226 |   4376.80 | BRAZIL                    | LHzXa71U2AGqfbqj1yYYqw2MEXq99dWmY     | 12-124-309-3821 | y even multipliers according to the regu
       581 | Customer#000000581 | 146369.1712 |   3242.10 | UNITED STATES             | s9SoN9XeVuCri                         | 34-415-978-2518 | ns. quickly regular pinto beans must sleep fluffily
       679 | Customer#000000679 | 145188.0664 |   1394.44 | IRAN                      | IJf1FlZL9I9m,rvofcoKy5pRUOjUQV        | 20-146-696-9508 | ely pending frays boost carefully
       160 | Customer#000000160 | 138511.7370 |   4363.17 | JORDAN                    | 5soVQ3dOCRBWBS                        | 23-428-666-4806 | olites. silently ironic accounts cajole furious
       883 | Customer#000000883 | 128224.1349 |    479.96 | CANADA                    | qVQ8rWNU5KZYDcS                       | 13-526-239-6950 | uctions are carefully across the regular, regular asymptote
       101 | Customer#000000101 | 124996.0120 |   7470.96 | BRAZIL                    | sMmL2rNeHDltovSm Y                    | 12-514-298-3699 |  sleep. pending packages detect slyly ironic pack
       671 | Customer#000000671 | 124125.2191 |   3227.87 | VIETNAM                   | ic6qGrt0giB,HDEiBK,,FYGHXQpc          | 31-593-213-9388 | bold ideas above the ironic packages affix blithely about the furiou
       526 | Customer#000000526 | 120324.0048 |    705.93 | ARGENTINA                 | 0oAVPhh1I4JdrDafVG2Z8                 | 11-170-679-3115 | ctions cajole after the furiously unusual ideas. ironic packages among the instructions are carefully carefully iro
       367 | Customer#000000367 | 118572.6180 |   9108.65 | JORDAN                    | yZaDoEZCqt2VMTVKoZUkf6gJ4yj           | 23-939-319-4691 | eodolites under the ironic, stealthy requests affix furiously among the unusual tit
       745 | Customer#000000745 | 113738.6908 |   7115.14 | CHINA                     | vjuHvDKdaomsivy l                     | 28-913-438-9403 | o beans. bold, regular theodolites haggle carefully about the quickl
       118 | Customer#000000118 | 113149.7832 |   3582.37 | CHINA                     | OVnFuHygK9wx3xpg8                     | 28-639-943-7051 | uick packages alongside of the furiously final deposits haggle above the fluffily even foxes. blithely dogged dep
        50 | Customer#000000050 | 111600.5870 |   4266.13 | FRANCE                    | 9SzDYlkzxByyJ1QeTI o                  | 16-658-112-3221 | ts. furiously ironic accounts cajole furiously slyly ironic dinos.
(20 rows)

