今天在查詢一個表時,用下面的語句
select distinct concat(slipno,'|',date_format(ydate,'%Y-%m-%d')) as code,slipno as name from bus_cchecks;
結果是:
code | name |
---|---|
o080414001|200 | o080414001 |
如果將distinct去掉,結果正常,但會重復
code | name |
---|---|
o080414001|2008-04-15 | o080414001 |
o080414001|2008-04-15 | o080414001 |
o080414001|2008-04-15 | o080414001 |
o080414001|2008-04-15 | o080414001 |
o080414001|2008-04-15 | o080414001 |
o080414001|2008-04-15 | o080414001 |
後來改用下面的語句
select concat(slipno,'|',date_format(ydate,'%Y-%m-%d')) as code,slipno as name from bus_cchecks group by slipno,ydate;
結果正常:
code | name |
---|---|
o080414001|2008-04-15 | o080414001 |