Oto dane ładowane
mysql> use junk
Database changed
mysql> drop table if exists summation_trick;
Query OK, 0 rows affected (0.04 sec)
mysql> create table summation_trick
-> (
-> col1 varchar(20),
-> col2 int
->);
Query OK, 0 rows affected (0.09 sec)
mysql> insert into summation_trick values
-> ('Water',22 ),('water', 3 ),
-> ('water', 5 ),('Air' ,10 ),
-> ('Earth', 3 ),('Air' , 5 );
Query OK, 6 rows affected (0.05 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql>
i tutaj jest kwerenda wykonana
mysql> select IFNULL(col1,'SUM') col1,sumcol2
-> from (select col1,col2,sum(col2) sumcol2
-> from summation_trick
-> group by col1,col2
-> with rollup) B
-> where (col1 is null and col2 is null)
-> or (col1 is not null and col2 is not null);
+-------+---------+
| col1 | sumcol2 |
+-------+---------+
| Air | 5 |
| Air | 10 |
| Earth | 3 |
| water | 3 |
| water | 5 |
| Water | 22 |
| SUM | 48 |
+-------+---------+
7 rows in set (0.00 sec)
mysql>
widzę co mówią o tobie nie wiem, dlaczego miałbym go używać to jednak działa, jak powiedziałem, czego szukam, to hav w sumie col2 na dole kolumny – dames