w3resource

SQL Exercise: Matches decided by penalties in the Round of 16


10. From the following table, write a SQL query to find number of matches decided by penalties in the Round 16.

Sample table: match_mast

 match_no | play_stage | play_date  | results | decided_by | goal_score | venue_id | referee_id | audence | plr_of_match | stop1_sec | stop2_sec
----------+------------+------------+---------+------------+------------+----------+------------+---------+--------------+-----------+-----------
        1 | G          | 2016-06-11 | WIN     | N          | 2-1        |    20008 |      70007 |   75113 |       160154 |       131 |       242
        2 | G          | 2016-06-11 | WIN     | N          | 0-1        |    20002 |      70012 |   33805 |       160476 |        61 |       182
        3 | G          | 2016-06-11 | WIN     | N          | 2-1        |    20001 |      70017 |   37831 |       160540 |        64 |       268
        4 | G          | 2016-06-12 | DRAW    | N          | 1-1        |    20005 |      70011 |   62343 |       160128 |         0 |       185
        5 | G          | 2016-06-12 | WIN     | N          | 0-1        |    20007 |      70006 |   43842 |       160084 |       125 |       325
        6 | G          | 2016-06-12 | WIN     | N          | 1-0        |    20006 |      70014 |   33742 |       160291 |         2 |       246
        7 | G          | 2016-06-13 | WIN     | N          | 2-0        |    20003 |      70002 |   43035 |       160176 |        89 |       188
        8 | G          | 2016-06-13 | WIN     | N          | 1-0        |    20010 |      70009 |   29400 |       160429 |       360 |       182
        9 | G          | 2016-06-13 | DRAW    | N          | 1-1        |    20008 |      70010 |   73419 |       160335 |        67 |       194
.........
       51 | F          | 2016-07-11 | WIN     | N          | 1-0        |    20008 |      70005 |   75868 |       160307 |       161 |       181

View the table

Sample Solution:

-- This SQL query calculates the count of rows in the 'match_mast' table where the 'decided_by' column has the value 'P'
-- and the 'play_stage' column has the value 'R'.

SELECT COUNT(*) 
-- COUNT(*) is an aggregate function that counts the number of rows in a result set.
FROM match_mast 
-- 'match_mast' is the name of the table being queried.
WHERE decided_by='P' AND play_stage='R';
-- The WHERE clause filters rows where the 'decided_by' column has the value 'P' 
-- and the 'play_stage' column has the value 'R'.

Sample Output:

 count
-------
     1
(1 row)

Code Explanation:

The said query in SQL that selects the count of rows from the 'match_mast' table where the "decided_by" column has the value of 'P' and the "play_stage" column has the value of 'R'.
The "COUNT" function counts the number of rows that meet the specified conditions.

Relational Algebra Expression:

Relational Algebra Expression: Find the number of matches decided by penalties in the Round of 16.


Relational Algebra Tree:

Relational Algebra Tree: Find the number of matches decided by penalties in the Round of 16.


Go to:


PREV : Number of matches got a result by penalty shootout.
NEXT : Number of goals scored during a normal play schedule.


Practice Online




Sample Database: soccer

soccer database relationship structure.


Query Visualization:

Duration:

Query visualization of Find the number of matches decided by penalties in the Round of 16 - Duration.


Rows:

Query visualization of Find the number of matches decided by penalties in the Round of 16 - Rows.


Cost:

Query visualization of Find the number of matches decided by penalties in the Round of 16 - Cost.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.