select u.ID,u.NAME,sum(b.CREDIT_NUM) from user u left outer join credit b on u.ID=b.USER_ID where b.CHANGE_TIME>='2008-1-1' and b.CHANGE_TIME<='2008-2-1' and b.CREDIT_NUM>0 group by b.USER_ID order by u.ID
credit表中空的记录查不出来 left outer join 不行 这跟sum函数有关系吗 mysql中有没有象orale中那样的空值置换函数NVL()
credit表中空的记录查不出来 left outer join 不行 这跟sum函数有关系吗 mysql中有没有象orale中那样的空值置换函数NVL()
from user u left outer join credit b on u.ID=b.USER_ID
where b.CHANGE_TIME>='2008-1-1'
and b.CHANGE_TIME <='2008-2-1'
and b.CREDIT_NUM>0
group by u.ID,u.NAME
order by u.ID你有条件 and b.CREDIT_NUM>0 这样 b表为空的时候就自然不会select出来[align=center]==== 思想重于技巧 ====
[/align]
group by u.ID,u.NAME order by u.ID