Bhagya
Bhagya

Reputation: 43

How to combine result of SQL statement using MySQL

I have wrote a query which gives me result in separate rows but issue is that I want that result in single row.

Which gives result like below

Here count is having two possibilities yes or no.

but i want something like

for entire result i want to combine for same system name, is there any way to do this.

Upvotes: 0

Views: 33

Answers (1)

Álvaro González
Álvaro González

Reputation: 146640

The COUNT() function accepts complex expressions, not just column names. I don't think I fully understand what your data contains or what you want to accomplish but you can try something on this line:

SELECT service.sys_name AS sysname,
COUNT(CASE status.status WHEN 'yes' THEN 1 END) AS count_yes,
COUNT(CASE status.status WHEN 'no'  THEN 1 END) AS count_no
...

This will omit NULL values.

Upvotes: 1

Related Questions