Home > Database > Mysql Tutorial > select-Mysql 统计求和时如何将查不到的结果置为0

select-Mysql 统计求和时如何将查不到的结果置为0

WBOY
Release: 2016-06-06 09:33:29
Original
1172 people have browsed it

selectmysql

select t.user_id, sum(t.TRADE_MONEY) from lc_account_records t
where t.USER_ID in (42,43,46,50,80)
group by t.USER_ID ;

由于user_id是一个外键,where条件中的user_id可能在这个表中没有记录,查询5条结果只能返回3条结果集,现在想将没有结果的返回0,这该怎么做呢,求各位大神帮忙!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template