mysql> select date(end_date),sum(charge) from table group by date(end_date) with rollup;
+----------------------+------------------+
| date(end_date) | sum(charge) |
+----------------------+------------------+
| 2010-11-01           |                7 | 
| 2010-11-02           |                4 | 
| NULL                 |               11 | 
+----------------------+------------------+如何让NULL显示成自己想要的文字:total

解决方案 »

  1.   

    select COALESCE(date(end_date),'total'),sum(charge) from table group by date(end_date) with rollup;
      

  2.   

    mysql> select COALESCE(date(end_date),'total'),sum(charge) from table group by date(end_date) with rollup;
    +----------------------------------------+------------------+
    | COALESCE(date(end_date),'total') | sum(charge) |
    +----------------------------------------+------------------+
    | 2010-11-01                             |                7 | 
    | 2010-11-02                             |                4 | 
    | 2010-11-02                             |               11 | 
    +----------------------------------------+------------------+不对
      

  3.   

    select if(date(end_date)<=>null,'total',date(end_date)),sum(charge) from table group by date(end_date) with rollup;
      

  4.   

    不会吧,示例
    SELECT COALESCE(title,'total'),SUM(hotelid) FROM gg GROUP BY title WITH rollupCOALESCE(title,'total') sum(hotelid)
    井冈山大酒店 1
    南昌春天大酒店 2
    南昌富豪酒店 3
    total 6
      

  5.   

    MySQL 5.1.11-beta-log 
    还是不对,难道是我数据库有问题?
    还显示原来的。二位的都试了
      

  6.   

    SELECT VERSION()
    version()
    5.1.31-community
      

  7.   

    select IFNULL(date(end_date),'total') AS total,sum(charge) from table group by date(end_date) with rollup;