Back to home page

OSCL-LXR

 
 

    


0001 WITH customer_total_return AS
0002 (SELECT
0003     cr_returning_customer_sk AS ctr_customer_sk,
0004     ca_state AS ctr_state,
0005     sum(cr_return_amt_inc_tax) AS ctr_total_return
0006   FROM catalog_returns, date_dim, customer_address
0007   WHERE cr_returned_date_sk = d_date_sk
0008     AND d_year = 2000
0009     AND cr_returning_addr_sk = ca_address_sk
0010   GROUP BY cr_returning_customer_sk, ca_state )
0011 SELECT
0012   c_customer_id,
0013   c_salutation,
0014   c_first_name,
0015   c_last_name,
0016   ca_street_number,
0017   ca_street_name,
0018   ca_street_type,
0019   ca_suite_number,
0020   ca_city,
0021   ca_county,
0022   ca_state,
0023   ca_zip,
0024   ca_country,
0025   ca_gmt_offset,
0026   ca_location_type,
0027   ctr_total_return
0028 FROM customer_total_return ctr1, customer_address, customer
0029 WHERE ctr1.ctr_total_return > (SELECT avg(ctr_total_return) * 1.2
0030 FROM customer_total_return ctr2
0031 WHERE ctr1.ctr_state = ctr2.ctr_state)
0032   AND ca_address_sk = c_current_addr_sk
0033   AND ca_state = 'GA'
0034   AND ctr1.ctr_customer_sk = c_customer_sk
0035 ORDER BY c_customer_id, c_salutation, c_first_name, c_last_name, ca_street_number, ca_street_name
0036   , ca_street_type, ca_suite_number, ca_city, ca_county, ca_state, ca_zip, ca_country, ca_gmt_offset
0037   , ca_location_type, ctr_total_return
0038 LIMIT 100