2017-04-03 44 views
0

比方说,我有如下表:MYSQL:选择

ID, Name ,insurance , per_diem, net_salary, rr, rent, other_allowances 
1, John  1000   0   2000  0 0   0 
2, Jim  1000   0   2000  0 0   0 
3, Steve 500   0   3000  0 0   0 
4, Tom  0    0   0  0 0   0 

我运行下面的查询

SELECT Sum((((((applicant.insurance + applicant.per_diem) + 
       applicant.net_salary) + applicant.rr) + applicant.rent) + 
       applicant.other_allowances)) As available_fund 
WHERE applicant.id = id; 
From applicant 

我想要得到的东西好像和每个人

是它可能?

+0

如果你发布你的错误越来越多,人们可能会更快地提供帮助。在你的例子中,FROM ...子句应该在WHERE子句之前......另外,WHERE子句中的条件似乎没有意义。最后,你并不需要太多括号。 –

+0

SQL部分中的次要格式更改 –

回答

0

您必须先使用,然后使用其中

 SELECT Sum(applicant.insurance + applicant.per_diem + 
       applicant.net_salary + applicant.rr + applicant.rent + 
       applicant.other_allowances) As available_fund 
    From applicant 
    group by applicant.id 

它会给所有员工总和,但如果你想获得一些颗粒员工再放入where条件

WHERE applicant.id = id 
+0

但获得了一条记录的结果。不是所有记录 –

+0

你没有在哪里使用,并通过组? –

+0

嗨它的作品,但结果重复嵌套得到4条记录结果得到12条记录。 –