How to sum column in mysql? -


i getting table when run query joins. problem columns , rows of table vary dynamically based on master table. cant decide column , rows.

    select     ..     ..     (20gp+20hd+20rf+30fr+30hd+30gp+30gp+40hd+40fr+40rf) total          tablename 

if use above query need edit query each time instead of above query please 1 tell me how this.

now need sum each columns in table , have show in separate column total

------------------------------------------------------..etc..,----- location|20gp|20hd|20rf|30fr|30hd|30gp|30gp|40hd|40fr|..etc..,40rf| ------------------------------------------------------..etc..,-----    uae  |  0 |  1 |  1 |  0 |  0 |  0 |  0 |  1 |  0 |..etc..,  1 |    usa  |  2 |  3 |  0 |  0 |  1 |  0 |  1 |  0 |  0 |..etc..,  0 |     .......,     .......,     ........etc,     ind  |  0 |  0 |  0 | 2 |  0 |  0 |  1 |  0 |  1 | ..etc.., 1 |  ------------------------------------------------------..etc..,---- 

just shown below expected output

----------------------------------------------------------------- location|20gp|20hd|20rf|30fr|30hd|30gp|30gp|40hd|40fr|40rf|total -----------------------------------------------------------------    uae  |  0 |  1 |  1 |  0 |  0 |  0 |  0 |  1 |  0 |  1 |  4    usa  |  2 |  3 |  0 |  0 |  1 |  0 |  1 |  0 |  0 |  0 |  7     .......,     .......,     ........etc,     ind  |  0 |  0 |  0 | 2 |  0 |  0 |  1 |  0 |  1 |  1 |   5 ----------------------------------------------------------------- 

please 1 tell how this

hey try following query column list , prepare string of query , execute string preparing statement. verify column name pattern in regular expression.

(select concat('select ', group_concat(`column_name` separator '+'), ' total test2') @sql  `information_schema`.`columns`  `table_schema` = (select database())  ,   `table_name`   = 'test2' ,   `column_name` regexp '^[0-9]');  prepare stmt1 @sql; execute stmt1; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -