w3resource

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


29. From the following table, write a SQL query to count the number of bookings that happened in extra 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 'ET'.

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='ET';
-- The WHERE clause filters rows where the 'play_schedule' column has the value 'ET'.

Sample Output:

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

Code Explanation:

The said query in SQL that determines the number of players who have been booked during extra time of a game.
The WHERE clause filters rows where the value of "play_schedule" is equal to 'ET'.

Relational Algebra Expression:

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


Relational Algebra Tree:

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


Go to:


PREV : Find the number of booking happened in stoppage time.
NEXT : SQL SUBQUERIES Exercises on Soccer Database


Practice Online



Sample Database: soccer

soccer database relationship structure.


Query Visualization:

Duration:

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


Rows:

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


Cost:

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