56,677
社区成员
发帖
与我相关
我的任务
分享
mysql> select name,if(period=2008,amount,0) from table1 a left join table1_detail b on a.id=b.table1id
-> ;
+------+--------------------------+
| name | if(period=2008,amount,0) |
+------+--------------------------+
| A | 22 |
| B | 33 |
| C | 0 |
| D | 0 |
+------+--------------------------+
4 rows in set (0.00 sec)
mysql>
select name,if(period=2008,amount,0) from table1 t left join table1_detail tb on t.id=tb.table1ID
select a.name,ifnull(amount,0)
from table1 a Left Join (select table1ID,amount FROM table1_detail Where period='2008' ) b ON a.id=b.table1ID