I need to sum the totals of a row except the first column.
Something similar too:
SELECT SUM( col2 + col3 + col4 +colN)
FROM numbers
WHERE user_name = ‘person’;
My table will continuously have columns added to it. So I want it to automatically pick up the sum of the new columns too without it needing to be hard coded into the query?
user_name | Col | col2 | Col3 | Col4 + other columns.
person1 | 2 | 3 | 76 | 56 etc. ---------> sum of row
person2 | 6 | 72 | 200 | 13 etc. ---------> sum of row
Thanks in advance for any help!
Not wishing to ‘avoid’ the question, but it looks like you could do with having a different data structure.
You should consider having a ‘users’ table with columns for
idanduser_name, and a new table (e.g.properties) with a row for each of the other columns in your current table (Col1,Col2…ColN). The new table would then have a column for user_name to link it to the users table.That way you’d be able to do something like:
I’d also recommend selecting users by ID (i.e. have the
propertiestable with a user_id column, rather than a user_name column), unless you’re confident that a user_name is never going to change (and even then…).