1

Could you please help me to construct a query to sum specific rows from a table, basically desired output is:

+-----------------+----------------+
| Total reads     | Total writes   |
+-----------------+----------------+
| 345436          | 345435         |
+-----------------+----------------+
  • Total reads = Com_select
  • Total writes = Com_delete, Com_insert, Com_update, Com_replace
3

Use the typical trick of sum(IF the column is the right one, use it, if not read 0:

SELECT sum(IF(variable_name = 'Com_select', variable_value, 0)) as `Total reads`,
       sum(IF(variable_name IN ('Com_delete', 'Com_insert', 'Com_update', 'Com_replace'),
           variable_value, 0)) as `Total writes` 
FROM information_schema.GLOBAL_STATUS;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.