Code:
mysql> create table t3 (id bigint auto_increment primary key, x int, y int) engine=innodb;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> insert into t3 (x,y) select x,y from t1;
Query OK, 1250000 rows affected (10.77 sec)
Records: 1250000 Duplicates: 0 Warnings: 0
mysql> update t3 set x = id % 15, y = id % 10;
Query OK, 1250000 rows affected (9.48 sec)
Rows matched: 1250000 Changed: 1250000 Warnings: 0
mysql> SELECT SUM(x)/(SELECT SUM(x) FROM t3) FROM t3 GROUP BY y;
+--------------------------------+
| SUM(x)/(SELECT SUM(x) FROM t3) |
+--------------------------------+
| 0.0714 |
| 0.0857 |
| 0.1000 |
| 0.1143 |
| 0.1286 |
| 0.0714 |
| 0.0857 |
| 0.1000 |
| 0.1143 |
| 0.1286 |
+--------------------------------+
10 rows in set (1.13 sec)
mysql> SELECT SUM(x*0.7)/(SELECT SUM(x*0.7) FROM t3) FROM t3 GROUP BY y;
+----------------------------------------+
| SUM(x*0.7)/(SELECT SUM(x*0.7) FROM t3) |
+----------------------------------------+
| 0.07143 |
| 0.08571 |
| 0.10000 |
| 0.11429 |
| 0.12857 |
| 0.07143 |
| 0.08571 |
| 0.10000 |
| 0.11429 |
| 0.12857 |
+----------------------------------------+
10 rows in set (1.35 sec)
mysql> set @S = (SELECT SUM(x*0.7) FROM t3);
Query OK, 0 rows affected (0.68 sec)
mysql> select @S;
+-----------+
| @S |
+-----------+
| 6124986.0 |
+-----------+
1 row in set (0.00 sec)
mysql> SELECT SUM(x*0.7)/@S FROM t3 GROUP BY y;
+---------------+
| SUM(x*0.7)/@S |
+---------------+
| 0.07143 |
| 0.08571 |
| 0.10000 |
| 0.11429 |
| 0.12857 |
| 0.07143 |
| 0.08571 |
| 0.10000 |
| 0.11429 |
| 0.12857 |
+---------------+
10 rows in set (1.00 sec)