我在MySQL数据库表中有以下专栏:
noOfChild noOfAdult childPrice adultPrice
==================================================
1 1 120 174
3 2 14 47
4 3 45 49
现在,我想获得所有
noOfChild
* childPrice
和noOfAdult
* adultPrice
的总和。为此,我正在使用此查询,但它仅显示第一行结果,而不是所有行。我怎么才能得到它?
$account->rowQuery("SELECT (noOfChild * childPrice) AS totalChildPrice,
(noOfAdult * adultPrice) AS totalAdultPrice FROM booking ");
结果应该是这样的:
1 X 120 = 120
3 X 14 = 52
4 X 45 = 180
=====
352 for child
和
1 X 174 = 174
2 X 47 = 74
3 X 49 = 147
=====
395 for adult
最佳答案
$account->rowQuery("SELECT (noOfChild * childPrice) AS totalChildPrice,
(noOfAdult * adultPrice) AS totalAdultPrice,
SUM(noOfChild * childPrice) AS sumForChild,
SUM(noOfAdult * adultPrice) AS sumForAdult
FROM booking ");