1

I have the below table.

create table cricket(team1 varchar2(22),team2 varchar2(22));

select * from cricket

Team1 Team2

INDIA  SL
SL    AUS
SA    ENG
ENG   NZ
AUS   INDIA

in the above table i want to display the count of teams played. for example

India 2
SL    1
Sa    1
Eng   2
Aus   2
Ram
  • 727
  • 2
  • 16
  • 33
  • Okay, but just "wanting" doen't produce anything. Please describe what you have tried so far and what is your current issue. And describe in general words how to get your desired output from the sample data (which is the key to start with a query composition). – astentx Jun 16 '23 at 12:56

1 Answers1

1

You can UNION ALL the two columns, then count over that:

WITH ALL_TEAMS AS (
    SELECT TEAM1 AS TEAM FROM CRICKET
    UNION ALL 
    SELECT TEAM2 FROM CRICKET
)
SELECT 
    TEAM, 
    COUNT(1) AS NUMBER_OF_PLAYS
FROM ALL_TEAMS
GROUP BY TEAM
VvdL
  • 2,799
  • 1
  • 3
  • 14