The document contains the SQL queries and results from a MariaDB database. It performs various SELECT queries to retrieve data from different tables within the database, including joining multiple tables to gather related information. The queries return sales data like products sold, sales amounts, dates; customer and salesperson details; and information on products, manufacturers and other entities in the database.
The document contains the SQL queries and results from a MariaDB database. It performs various SELECT queries to retrieve data from different tables within the database, including joining multiple tables to gather related information. The queries return sales data like products sold, sales amounts, dates; customer and salesperson details; and information on products, manufacturers and other entities in the database.
The document contains the SQL queries and results from a MariaDB database. It performs various SELECT queries to retrieve data from different tables within the database, including joining multiple tables to gather related information. The queries return sales data like products sold, sales amounts, dates; customer and salesperson details; and information on products, manufacturers and other entities in the database.
The document contains the SQL queries and results from a MariaDB database. It performs various SELECT queries to retrieve data from different tables within the database, including joining multiple tables to gather related information. The queries return sales data like products sold, sales amounts, dates; customer and salesperson details; and information on products, manufacturers and other entities in the database.
MariaDB [demo]> SELECT p.prod_name, m.address AS manufacturer_address
-> FROM products p -> JOIN manufact m ON p.man_id = m.man_id; +--------------+----------------------+ | prod_name | manufacturer_address | +--------------+----------------------+ | Smartphone | Seul | | Smartphone | Cupertino | | Smartphone | Tokyo | | Laptop | Beijing | | Laptop | Cupertino | | Router | San Francisco | | Access point | San Francisco | +--------------+----------------------+ 7 rows in set (0.011 sec)
MariaDB [demo]> SELECT man_name AS router_manufacturer
MariaDB [demo]> SELECT sp.sp_name AS salesperson_name
-> FROM sperson sp -> JOIN sales s ON sp.sp_id = s.sp_id -> JOIN products p ON s.prod_id = p.prod_id -> WHERE p.prod_name = 'Router'; +------------------+ | salesperson_name | +------------------+ | Tomio Yoshida | | Elena Ermana | | John Onoje | +------------------+ 3 rows in set (0.000 sec)
MariaDB [demo]> SELECT p.prod_name AS most_sold_product
-> FROM products p -> JOIN ( -> SELECT prod_id, SUM(qty) AS total_quantity -> FROM sales -> GROUP BY prod_id -> ORDER BY total_quantity DESC -> LIMIT 1 -> ) t ON p.prod_id = t.prod_id; +-------------------+ | most_sold_product | +-------------------+ | Smartphone | +-------------------+ 1 row in set (0.003 sec)
-> FROM sales s -> JOIN customers c ON s.cust_id = c.cust_id -> WHERE s.data = '2015-01-10'; +----------------+------------+ | cust_name | data | +----------------+------------+ | Vlad Boierescu | 2015-01-10 | | Ray Blayr | 2015-01-10 | | Haru Mitsu | 2015-01-10 | +----------------+------------+ 3 rows in set (0.001 sec)
MariaDB [demo]> SELECT c.cust_name
-> FROM customers c -> JOIN sales s ON c.cust_id = s.cust_id -> JOIN products p ON s.prod_id = p.prod_id -> JOIN manufact m ON p.man_id = m.man_id -> WHERE m.man_name = 'Sony'; +--------------+ | cust_name | +--------------+ | John Onoje | | Nelu Vasiliu | +--------------+ 2 rows in set (0.002 sec)
MariaDB [demo]> SELECT DISTINCT sp.sp_name
-> FROM sperson sp -> JOIN sales s ON sp.sp_id = s.sp_id -> JOIN products p ON s.prod_id = p.prod_id -> JOIN manufact m ON p.man_id = m.man_id -> WHERE m.country = 'Korea'; +--------------+ | sp_name | +--------------+ | Rodny Johns | | Terry Cardon | +--------------+ 2 rows in set (0.001 sec)
MariaDB [demo]> SELECT DISTINCT c.cust_name
-> FROM customers c -> JOIN sales s ON c.cust_id = s.cust_id; +----------------+ | cust_name | +----------------+ | John Adams | | Karl Fischer | | John Onoje | | Haru Mitsu | | Vlad Boierescu | | Ray Blayr | | Nelu Vasiliu | +----------------+ 7 rows in set (0.000 sec)
MariaDB [demo]> SELECT DISTINCT sp.sp_name
-> FROM sperson sp -> JOIN sales s ON sp.sp_id = s.sp_id; +---------------+ | sp_name | +---------------+ | Rodny Johns | | Diego Navarro | | Terry Cardon | | Tomio Yoshida | | Elena Ermana | | Goro Atsuma | | John Onoje | +---------------+ 7 rows in set (0.001 sec)
-> FROM sales s -> JOIN sperson sp ON s.sp_id = sp.sp_id -> JOIN products p ON s.prod_id = p.prod_id -> WHERE s.data BETWEEN '2014-09-01' AND '2014-09-30'; +-------------+------------+------------+-----+ | sp_name | data | prod_name | qty | +-------------+------------+------------+-----+ | Rodny Johns | 2014-09-01 | Smartphone | 200 | +-------------+------------+------------+-----+ 1 row in set (0.002 sec)
MariaDB [demo]> SELECT sp.*
-> FROM sperson sp -> LEFT JOIN sales s ON sp.sp_id = s.sp_id -> WHERE s.sp_id IS NULL; +-------+--------------+------------+--------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+--------------+------------+--------+------+ | 12 | Julio Vargas | 35 | Madrid | 13 | | 44 | Inari Hachi | 14 | Tokyo | 14 | +-------+--------------+------------+--------+------+ 2 rows in set (0.012 sec)
MariaDB [demo]> SELECT sp.*
-> FROM sperson sp -> JOIN sperson manager ON sp.manager_id = manager.sp_id -> WHERE manager.comm > 11; +-------+---------------+------------+---------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+---------------+------------+---------+------+ | 38 | Goro Atsuma | 14 | Tokyo | 10 | | 44 | Inari Hachi | 14 | Tokyo | 14 | | 10 | Rodny Johns | 23 | Chicago | 10 | | 14 | Tomio Yoshida | 23 | Tokyo | 12 | | 35 | Elena Ermana | 23 | Madrid | 14 | | 12 | Julio Vargas | 35 | Madrid | 13 | | 15 | Diego Navarro | 35 | Madrid | 9 | +-------+---------------+------------+---------+------+ 7 rows in set (0.013 sec) MariaDB [demo]> SELECT sp.* -> FROM sperson sp -> LEFT JOIN sperson subordinate ON sp.sp_id = subordinate.manager_id -> WHERE subordinate.sp_id IS NULL AND sp.manager_id = 0; +-------+------------+------------+----------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+------------+------------+----------+------+ | 45 | John Onoje | 0 | Chisinau | 15 | +-------+------------+------------+----------+------+ 1 row in set (0.000 sec)
MariaDB [demo]> SELECT *
-> FROM sperson -> WHERE comm = (SELECT MIN(comm) FROM sperson); +-------+---------------+------------+--------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+---------------+------------+--------+------+ | 15 | Diego Navarro | 35 | Madrid | 9 | +-------+---------------+------------+--------+------+ 1 row in set (0.000 sec)
MariaDB [demo]> SELECT *
-> FROM sperson -> WHERE comm = (SELECT comm FROM sperson WHERE sp_name = 'Rodny Johns') AND sp_name != 'Rodny Johns'; +-------+-------------+------------+--------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+-------------+------------+--------+------+ | 38 | Goro Atsuma | 14 | Tokyo | 10 | +-------+-------------+------------+--------+------+ 1 row in set (0.000 sec)
MariaDB [demo]> SELECT *
-> FROM sperson -> WHERE comm = ( -> SELECT MIN(comm) -> FROM sperson s -> WHERE s.office = sperson.office -> ); +-------+---------------+------------+----------+------+ | sp_id | sp_name | manager_id | office | comm | +-------+---------------+------------+----------+------+ | 10 | Rodny Johns | 23 | Chicago | 10 | | 15 | Diego Navarro | 35 | Madrid | 9 | | 38 | Goro Atsuma | 14 | Tokyo | 10 | | 45 | John Onoje | 0 | Chisinau | 15 | +-------+---------------+------------+----------+------+ 4 rows in set (0.012 sec)
MariaDB [demo]> SELECT sp.*
-> FROM sperson sp -> JOIN sales s ON sp.sp_id = s.sp_id -> JOIN customers c ON s.cust_id = c.cust_id -> WHERE c.country = 'Germany'; Empty set (0.000 sec)
MariaDB [demo]> SELECT sp.*
-> FROM sperson sp -> JOIN sales s ON sp.sp_id = s.sp_id -> JOIN products p ON s.prod_id = p.prod_id -> WHERE p.prod_name = 'Laptop' AND s.data = '2014-09-30'; Empty set (0.001 sec)
MariaDB [demo]> SELECT manager.sp_name AS manager_name, sp.sp_name AS
salesperson_name -> FROM sperson sp -> JOIN sperson manager ON sp.manager_id = manager.sp_id -> JOIN sales s ON sp.sp_id = s.sp_id -> JOIN products p ON s.prod_id = p.prod_id -> WHERE p.prod_name = 'Laptop'; +--------------+------------------+ | manager_name | salesperson_name | +--------------+------------------+ | Terry Cardon | Tomio Yoshida | | Terry Cardon | Tomio Yoshida | +--------------+------------------+ 2 rows in set (0.001 sec)