q18.sql 1.1 KB

12345678910111213141516171819202122232425262728
  1. SELECT
  2. i_item_id,
  3. ca_country,
  4. ca_state,
  5. ca_county,
  6. avg(cast(cs_quantity AS DECIMAL(12, 2))) agg1,
  7. avg(cast(cs_list_price AS DECIMAL(12, 2))) agg2,
  8. avg(cast(cs_coupon_amt AS DECIMAL(12, 2))) agg3,
  9. avg(cast(cs_sales_price AS DECIMAL(12, 2))) agg4,
  10. avg(cast(cs_net_profit AS DECIMAL(12, 2))) agg5,
  11. avg(cast(c_birth_year AS DECIMAL(12, 2))) agg6,
  12. avg(cast(cd1.cd_dep_count AS DECIMAL(12, 2))) agg7
  13. FROM catalog_sales, customer_demographics cd1,
  14. customer_demographics cd2, customer, customer_address, date_dim, item
  15. WHERE cs_sold_date_sk = d_date_sk AND
  16. cs_item_sk = i_item_sk AND
  17. cs_bill_cdemo_sk = cd1.cd_demo_sk AND
  18. cs_bill_customer_sk = c_customer_sk AND
  19. cd1.cd_gender = 'F' AND
  20. cd1.cd_education_status = 'Unknown' AND
  21. c_current_cdemo_sk = cd2.cd_demo_sk AND
  22. c_current_addr_sk = ca_address_sk AND
  23. c_birth_month IN (1, 6, 8, 9, 12, 2) AND
  24. d_year = 1998 AND
  25. ca_state IN ('MS', 'IN', 'ND', 'OK', 'NM', 'VA', 'MS')
  26. GROUP BY ROLLUP (i_item_id, ca_country, ca_state, ca_county)
  27. ORDER BY ca_country, ca_state, ca_county, i_item_id
  28. LIMIT 100