I have the following table t_vouchers:
id code amount isactive
1 a1 10 1
2 a2 20 0
3 a3 30 1
I want to compute the sum(amount) of all active vouchers but also get another column containing the list of ids included in this sum. Like below:
sum ids
40 1,3
The query would be something like:
select sum(amount) /* ? how to get here the ids stuffed in a comma separated string ? */
from t_vouchers
where isactive = 1
This should work:
Here is an SQL Fiddle