P
P
Pinko2020-02-19 17:25:15
SQL
Pinko, 2020-02-19 17:25:15

Help with basic SQL queries?

There are three tables - traffic, managers, clients.

Cargo table: record number (id), container (container), link to the client (id_client), link to the manager (id_manager), date of actual arrival of the cargo (arriving_date).

Table of managers: record number (id), last name (surname), first name (name), mail (mail), phone (phone).

Customer table: record number (id), company name (name), TIN (INN), address (address), mail (mail), telephone (phone).

Please help me with these questions, 4 seems wrong to me, and 5 and 7 I can't think
of 4. Select clients who have cargo on the way
SELECT clients.id FROM traffic INNER JOIN ON traffic.id_client=clients.id WHERE arriving_date IS NOT null or arriving_date != ' '
5. Select clients whose cargoes are handled by the manager Natalia

7. Number of cargoes for each client.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Koltunov, 2020-02-19
@i_olega

In order

SELECT c.* 
FROM clients c
LEFT JOIN traffic t ON t.client_id = c.id
WHERE  t.arriving_date ISNULL


SELECT c.* 
FROM clients c
LEFT JOIN traffic t ON t.id_client = c.id
LEFT JOIN managers m ON t.id_manager = m.id
WHERE  m.name = 'Наталья'

SELECT t.id_client, 
    count(*)
FROM traffic t
GROUP BY id_client

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question