Home  >  Article  >  Backend Development  >  求个mysql话语

求个mysql话语

WBOY
WBOYOriginal
2016-06-13 10:57:37878browse

求个mysql语句
id parent_id num
1 0 1
2 1 5
3 1 4
4 0 2
5 4 3
我想要查询parent_id=0,并且parent_id对应id的sum(num)的值;
既是parent_id=0的id=1,我需要得到的num的值是1+5+4
能不能用mysql语句实现?

------解决方案--------------------

我想要查询parent_id=0,并且parent_id对应id的sum(num)的值:
select count(num) as sum from 表 where parent_id =0


下面这句什么意思?

既是parent_id=0的id=1,我需要得到的num的值是1+5+4

Statement:
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