0% found this document useful (0 votes)
14 views1 page

DB Queries

The document contains a series of SQL queries designed to retrieve various data related to species observations and personnel. It includes queries to calculate total observations by individual agents, total observations by species, and to filter species with observations greater than four. Additionally, it provides queries to list personnel, identify species that have never been observed, and obtain detailed information about the Gorilla species.

Uploaded by

pekogroup2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

DB Queries

The document contains a series of SQL queries designed to retrieve various data related to species observations and personnel. It includes queries to calculate total observations by individual agents, total observations by species, and to filter species with observations greater than four. Additionally, it provides queries to list personnel, identify species that have never been observed, and obtain detailed information about the Gorilla species.

Uploaded by

pekogroup2017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

What the query does: We need the total number of species observed by an individual

SELECT a.names, a.firstname, sum(o.nb) as total


FROM agents a, species s, observed o
WHERE a.id=o.id and o.spid=s.spid
GROUP BY a.names, a. firstname
ORDER BY a.names

Query: Write the total number of observations by species


SELECT s.en_name, s.lat_name, sum(o.nb) as total
FROM species s, observed o
WHERE o.spid=s.spid
GROUP BY s.en_name, s.lat_name
ORDER BY s.en_name

Query: Display the total number of observations by species with total number greater than 4
SELECT s.en_name as english_name, s.lat_name as latin_name, sum(o.nb) as total
FROM species s, observed o
WHERE o.spid=s.spid
GROUP BY s.en_name, s.lat_name
HAVING SUM(o.nb)>4
ORDER BY total desc

Query: Print the list of personels/agents


SELECT a.names as personel FROM agents a
UNION
SELECT head FROM services

Query: Give a list species that has never been observed


SELECT s.en_name FROM species s
WHERE s.en_name NOT IN (SELECT s.en_name FROM species s, observed o where
s.spid=o.spid)

Query: Give details on Gorilla (The name, the date, the number of individuals observed, and the
observer)
SELECT s.en_name, o.date, o.nb, a.names
FROM species s, agents a, observed o
WHERE s.spid=o.spid and a.id=o.id and s.en_name='Gorilla'

You might also like