Skip to content

Instantly share code, notes, and snippets.

View bakafox's full-sized avatar
🌄
// @todo: вставить сюда крутую цитату типа вумный

Владимир Чеховский bakafox

🌄
// @todo: вставить сюда крутую цитату типа вумный
  • Novosibirsk State University
View GitHub Profile
@bakafox
bakafox / Chapter1.sql
Created May 10, 2023 02:40
SQLite | Chapter 1: Simple queries, sorting, set operations, simple aggregation
-- ЗАДАНИЕ 1.1.
-- Get all the unique companies
SELECT DISTINCT COMPANY
FROM MANUFACTURER;
-- ЗАДАНИЕ 1.2.
-- Get the total number of companies
SELECT COUNT(COMPANY)
FROM MANUFACTURER;
@bakafox
bakafox / Chapter2.sql
Created May 10, 2023 02:42
SQLite | Chapter 2: Join
-- ЗАДАНИЕ 2.1.
-- Get all the unique companies producing Drinking water in alphabetic order.
SELECT DISTINCT MANUFACTURER.COMPANY
FROM MANUFACTURER, PRODUCT
WHERE MANUFACTURER.BILL_ID = PRODUCT.BILL_ID
AND PRODUCT.WARE = "Drinking water"
ORDER BY COMPANY ASC;
-- ЗАДАНИЕ 2.2 (синтаксис where).
-- Get all the companies producing wares in Raw food category. Result must contain unique pairs of companies and wares producing by them from the given category and must be sorted by the ware first and the company name next.
@bakafox
bakafox / Chapter3.sql
Created May 24, 2023 04:04
SQLite | Chapter 3: Aggregation
-- ЗАДАНИЕ 3.1.
-- Get all the unique wares in the alphabetic order with the minimal and maximal prices for each.
SELECT PRODUCT.WARE,
MIN(PRODUCT.PRICE) AS MINPRICE, MAX(PRODUCT.PRICE) AS MAXPRICE
FROM PRODUCT
GROUP BY PRODUCT.WARE;
-- ЗАДАНИЕ 3.2.
-- Show top 3 wares with the most difference between minimal and maximal prices.
SELECT PRODUCT.WARE,
@bakafox
bakafox / Chapter4.sql
Created June 1, 2023 08:06
SQLite | Chapter 4: Subqueries
-- ЗАДАНИЕ 4.1 (SQLITE ONLY!) (0 подзапросов).
-- Show the product with the largest average price over the market.
SELECT PRODUCT.WARE, AVG(PRODUCT.PRICE) AS AVGPRICE
FROM PRODUCT
GROUP BY PRODUCT.WARE
ORDER BY AVGPRICE DESC
LIMIT 1;
-- ЗАДАНИЕ 4.1 (1 подзапрос).
SELECT *