1

I am using this query to get single total value:

SELECT SUM(`contact_awards`.`amount`) AS amount
FROM (`contact_awards`)
WHERE
    `contact_awards`.`gift_award_id` IN (1) 
AND `created` BETWEEN '2013-05-05' AND '2014-04-01'
GROUP
    BY `contact_awards`.`amount`

However when run, it products two rows containing amount field:

500
1000

Why doesn't it run single row with sum 1500 ?

Thanks for your help

4

2 回答 2

3

删除GROUP BY子句,

SELECT SUM(contact_awards.amount) AS amount
FROM   contact_awards
WHERE  contact_awards.gift_award_id IN (1) 
       AND created BETWEEN '2013-05-05' AND '2014-04-01'

您获得两条记录的原因是因为有两个不同的contact_awards.amount分组值。

于 2013-04-29T14:09:22.600 回答
2

当您使用group by时,结果将由您的分组子句分隔。如果您想要总结单行,只需删除group by查询末尾的 。

于 2013-04-29T14:10:01.707 回答