w3resource

SQL Exercise: Find the number of booking happened in stoppage time


28. From the following table, write a SQL query to count the number of bookings during stoppage time.

Sample table: player_booked

 match_no | team_id | player_id | booking_time | sent_off | play_schedule | play_half
----------+---------+-----------+--------------+----------+---------------+-----------
        1 |    1216 |    160349 |           32 |          | NT            |         1
        1 |    1216 |    160355 |           45 |          | NT            |         1
        1 |    1207 |    160159 |           69 | Y        | NT            |         2
        1 |    1216 |    160360 |           78 |          | NT            |         2
        2 |    1221 |    160470 |           14 |          | NT            |         1
        2 |    1201 |    160013 |           23 |          | NT            |         1
        2 |    1201 |    160013 |           36 |          | NT            |         1
        2 |    1201 |    160014 |           63 |          | NT            |         2
        2 |    1221 |    160472 |           66 |          | NT            |         2
.......
       51 |    1214 |    160302 |          122 |          | ET            |         2

View the table

Sample Solution:

SQL Code:

-- This SQL query calculates the count of rows in the 'player_booked' table where the 'play_schedule' column has the value 'ST'.

SELECT COUNT(*) 
-- COUNT(*) is an aggregate function that counts the number of rows in a result set.
FROM player_booked
-- 'player_booked' is the name of the table being queried.
WHERE play_schedule='ST';
-- The WHERE clause filters rows where the 'play_schedule' column has the value 'ST'.

Sample Output:

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

Code Explanation:

The said query in SQL that determine the number of players who have been booked during stoppage time of a game.
The WHERE clause specifies a condition to filter the rows where the value of "play_schedule" is equal to 'ST'.

Relational Algebra Expression:

Relational Algebra Expression: Find the number of booking happened in stoppage time.


Relational Algebra Tree:

Relational Algebra Tree: Find the number of booking happened in stoppage time.


Go to:


PREV : Within each half of play, find the number of bookings.
NEXT : Find the number of booking happened in extra time.


Practice Online



Sample Database: soccer

soccer database relationship structure.


Query Visualization:

Duration:

Query visualization of Find the number of booking happened in stoppage time - Duration.


Rows:

Query visualization of Find the number of booking happened in stoppage time - Rows.


Cost:

Query visualization of Find the number of booking happened in stoppage time - 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.