w3resource

SQL Exercise: Find the number of venues for EURO cup 2016

SQL soccer Database: Basic Exercise-1 with Solution

1. From the following table, write a SQL query to count the number of venues for EURO cup 2016. Return number of venues.

Sample table: soccer_venue
 venue_id |       venue_name        | city_id | aud_capacity
----------+-------------------------+---------+--------------
    20001 | Stade de Bordeaux       |   10003 |        42115
    20002 | Stade Bollaert-Delelis  |   10004 |        38223
    20003 | Stade Pierre Mauroy     |   10005 |        49822
    20004 | Stade de Lyon           |   10006 |        58585
    20005 | Stade VElodrome         |   10007 |        64354
    20006 | Stade de Nice           |   10008 |        35624
    20007 | Parc des Princes        |   10001 |        47294
    20008 | Stade de France         |   10002 |        80100
    20009 | Stade Geoffroy Guichard |   10009 |        42000
    20010 | Stadium de Toulouse     |   10010 |        33150

Sample Solution:

-- This SQL query calculates the total number of rows in the 'soccer_venue' table.

SELECT COUNT(*) 
-- COUNT(*) is an aggregate function that counts the number of rows in a result set.
FROM soccer_venue;
-- 'soccer_venue' is the name of the table from which the count is being calculated.

Sample Output:

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

Code Explanation:

The said query in SQL that counts the total number of rows in the soccer_venue table. The COUNT(*) function is an aggregate function that counts the number of rows returned by a query. The result of the query will be a single value, which represents the total number of rows in the soccer_venue table.

Relational Algebra Expression:

Relational Algebra Expression: Find the number of venues for EURO cup 2016.

Relational Algebra Tree:

Relational Algebra Tree: Find the number of venues for EURO cup 2016.

Practice Online



Sample Database: soccer

soccer database relationship structure

Query Visualization:

Duration:

Query visualization of Find the number of venues for EURO cup 2016 - Duration

Rows:

Query visualization of Find the number of venues for EURO cup 2016 - Rows

Cost:

Query visualization of Find the number of venues for EURO cup 2016 - Cost

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

Previous SQL Exercise: SQL Basic Exercises on Soccer Database
Next SQL Exercise: Number of countries participated in the EURO cup 2016.

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.