Skip to content

Tag: mysql

Count from multiple columns and rows simultaneously in SQL

I have a table of matches which look like: I need to find the total matches played by every team and the output should be like this: I know about SUM() and GROUP BY clauses but not able to do it on multiple columns. Any help would be highly appreciated. Answer You can use union all to unpivot the data

How to compare counts from subselect?

I want to compare the count between two tables. Or more to say, output if the count from table1 is greater than from table2: SELECT c1 > c2 FROM (SELECT count(*) from table1) as c1, (SELECT count(*)…