|
mysql> explain -- 22
-> select
-> cntrycode,
-> count(*) as numcust,
-> sum(c_acctbal) as totacctbal
-> from
-> (
-> select
-> substr(c_phone ,1 ,2) as cntrycode,
-> c_acctbal
-> from
-> customer
-> where
-> substr(c_phone ,1 ,2) in
-> ('23', '39', '40', '27', '33', '31', '25')
-> and c_acctbal > (
-> select
-> avg(c_acctbal)
-> from
-> customer
-> where
-> c_acctbal > 0.00
-> and substr(c_phone ,1 ,2) in
-> ('23', '39', '40', '27', '33', '31', '25')
-> )
-> and not exists (
-> select
-> *
-> from
-> orders
-> where
-> o_custkey = c_custkey
-> )
-> ) custsale
-> group by
-> cntrycode
-> order by
-> cntrycode limit 10;
+----+--------------------+------------+------+---------------+------------+---------+-------------------------+---------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+------------+------+---------------+------------+---------+-------------------------+---------+---------------------------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 45382 | Using temporary; Using filesort |
| 2 | DERIVED | customer | ALL | NULL | NULL | NULL | NULL | 1490739 | Using where |
| 4 | DEPENDENT SUBQUERY | orders | ref | orders_fk1 | orders_fk1 | 4 | tpch.customer.c_custkey | 7 | Using index |
| 3 | SUBQUERY | customer | ALL | NULL | NULL | NULL | NULL | 1490739 | Using where |
+----+--------------------+------------+------+---------------+------------+---------+-------------------------+---------+---------------------------------+
4 rows in set (2.87 sec)
mysql> -- 22
mysql> select
-> cntrycode,
-> count(*) as numcust,
-> sum(c_acctbal) as totacctbal
-> from
-> (
-> select
-> substr(c_phone ,1 ,2) as cntrycode,
-> c_acctbal
-> from
-> customer
-> where
-> substr(c_phone ,1 ,2) in
-> ('23', '39', '40', '27', '33', '31', '25')
-> and c_acctbal > (
-> select
-> avg(c_acctbal)
-> from
-> customer
-> where
-> c_acctbal > 0.00
-> and substr(c_phone ,1 ,2) in
-> ('23', '39', '40', '27', '33', '31', '25')
-> )
-> and not exists (
-> select
-> *
-> from
-> orders
-> where
-> o_custkey = c_custkey
-> )
-> ) custsale
-> group by
-> cntrycode
-> order by
-> cntrycode limit 10;
+-----------+---------+-------------+
| cntrycode | numcust | totacctbal |
+-----------+---------+-------------+
| 23 | 8988 | 67627762.48 |
| 25 | 9111 | 68360817.05 |
| 27 | 9014 | 67640913.65 |
| 31 | 9087 | 68149522.82 |
| 33 | 9182 | 68895118.67 |
+-----------+---------+-------------+
5 rows in set (2.81 sec)
mysql> |
|