How to add and store what were the added id?

Asked

Viewed 94 times

0

Good afternoon, would like to know if it is possible to perform a query summing some values and create a column with the ids in which the values were summed.

-- table 'value'

| id | value | status |
| 1 | 100.00 | 0 |
| 2 | 200.00 | 1 |
| 3 | 300.00 | 0 |
| 4 | 400.00 | 1 |

-- sql

select sum(value) as sum from value V Where V.status = 1

-- exit
| summing up |
| 600.00 |

But I’d like the exit to stay that way.
-- desired exit
| soma | ids |
| 600.00 | 2,4 |

How could I make that appointment?

From now on. Thank you.

1 answer

1


Try:

SELECT SUM(valor) AS soma, GROUP_CONCAT(id) AS ids FROM valor V WHERE V.status = 1

Corrected.

  • It worked!!!!! but the command is GROUP_CONCAT()... BRAWL!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.