'group by'에 해당되는 글 1건

  1. 2005/02/25 칼럼에 변경을 가해 group by 절을 만든다

mysql> desc tbl_money;

+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| id               | varchar(64) |      | MUL |         |       |
| money        | int(11)     |      |     | 0       |       |
| make_time   | datetime  |      | MUL | 0       |       |
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)


mysql> select left(make_time,7) as mt,sum(money) from tbl_money group by mt having mt not in ('0000-00','2005-03');

................

| 2004-05 |    2092260 |
| 2004-06 |    1771030 |
| 2004-07 |    1182540 |
| 2004-08 |    1198620 |
| 2004-09 |    4917540 |
| 2004-10 |    6891670 |
| 2004-11 |    3110140 |
| 2004-12 |    3425810 |
| 2005-01 |    2958977 |
| 2005-02 |    1913150 |
+---------+------------+
45 rows in set (8.95 sec)