R
R
rechmp2014-05-16 13:59:43
MySQL
rechmp, 2014-05-16 13:59:43

How to select'om get the sum of all columns starting with X? (mssql)

I have a table:
id, name, a1,a2,a3,..., an
where a1-an is in decimal format, null is possible.
n - arbitrary number (the number of columns may change over time)
I would like to get the sum of all columns starting with 'a' in one query, for example:
table:
2 milk 1 3 5
3 meat 5 6 2
Select id, sum
2 9
3 13
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2014-05-16
@rechmp

Normalize the base and get rid of the crooked storage method. Move the quantity of goods in stores to a separate table (`product id`, `shop id`, `quantity`).

1
1001001 111, 2014-05-16
@IgorO2

Use CONCAT()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question