This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
setlocale(0, "UKR"); | |
//1) Вывести на экран консоли надпись : | |
cout << "\"To be \n\tor not\n\t\tto be...\"\n\t\t\t/Shakespeare/\"\n\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 1. Посчитать возможную выручку за хлеб и молоко (с учётом скидок на эти товары) | |
--SELECT *,(price * quantity - price*discount)[Цена с учетом скидки] | |
--FROM Store_table | |
--WHERE name LIKE '%хлеб%' OR name LIKE '%молоко%' | |
--2. Получить информацию о том, каких товаров вчера и сегодня доставили более 10 штук (getdate, dateadd) | |
--SELECT * | |
--FROM Store_table | |
--WHERE (date_of_delivery = CAST (GETDATE() AS DATE) OR date_of_delivery = CAST (DATEADD(DAY, -1, GETDATE()) AS DATE)) AND quantity>300 -- у меня все были больше 10 штук |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: Database [Store3] Script Date: 08.02.2025 10:34:47 ******/ | |
CREATE DATABASE [Store3] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'Store3', FILENAME = N'E:\STEP\C_sharp .Net\SQL\Store\Store3.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) | |
LOG ON | |
( NAME = N'Store3_log', FILENAME = N'E:\STEP\C_sharp .Net\SQL\Store\Store3_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) | |
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: Database [Store3] Script Date: 10.02.2025 12:01:41 ******/ | |
CREATE DATABASE [Store3] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'Store3', FILENAME = N'E:\STEP\C_sharp .Net\SQL\Store\Store3.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) | |
LOG ON | |
( NAME = N'Store3_log', FILENAME = N'E:\STEP\C_sharp .Net\SQL\Store\Store3_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) | |
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INNER JOINS: | |
1. Показать названия и категории товаров, поставщиками которых являются ООО "Паньки" или ООО «Какие люди» | |
SELECT p.name AS "названия товаров", c.name AS "категории товаров", s.name AS "поставщики" | |
FROM Product p | |
JOIN Category c ON p.id_category = c.id | |
JOIN Delivery d ON d.id_product = p.id | |
JOIN Supplier s ON s.id = d.id_supplier WHERE s.name LIKE '%бусік%' OR s.name LIKE '%картофка%' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Показать товары, средняя цена продажи которых была больше 50 гривен | |
SELECT p.name | |
FROM Product p | |
JOIN Sale s ON s.id_product = p.id | |
GROUP BY p.name | |
HAVING AVG (s.price) > 50 | |
2. Вывести количество товаров каждой категории, средняя цена поставки которых больше 100 гривен |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Показать самый популярный товар магазина (больше всего раз продавался) | |
SELECT TOP 1 name AS "название товара", (SELECT SUM (quantity) FROM Sale sl WHERE sl.id_product = p.id) AS total_sold | |
FROM Product p | |
ORDER BY total_sold DESC; | |
2. Если общее количество товаров всех категорий принять за 100%, необходимо посчитать, сколько товаров каждой категории | |
(в процентном отношении) было продано |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--1. Показать среднее арифметическое трёх вещественных чисел, хранящихся в переменных | |
DECLARE @one float = 85.15 | |
DECLARE @two float = 45.45 | |
DECLARE @three float = 25.25 | |
DECLARE @average float = (@one+@two+@three)/3 | |
PRINT @average | |
--2. Показать количество цифр числа, хранящегося в переменной |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STORED PROCEDURES (выполнить минимум 3 задания): | |
1. Написать хранимую процедуру, которая показывает общее количество проданных товаров в каждой из категорий и от каждого производителя. | |
--1. Написать хранимую процедуру, которая показывает общее количество проданных товаров в каждой из категорий и от каждого производителя. | |
CREATE PROCEDURE Products_Saled AS | |
SELECT c.name AS [Категория], prr.name AS [Производитель], COUNT(1) AS [Количество проданных товаров] | |
FROM Product p | |
JOIN Category c ON p.id_category = c.id | |
JOIN Sale s ON s.id_product = p.id | |
JOIN Producer prr ON p.id_producer = prr.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR ALTER PROCEDURE GetTableFields @TableName NVARCHAR(128) | |
AS | |
BEGIN | |
DECLARE @SQL NVARCHAR(MAX) | |
SET @SQL = ' | |
SELECT | |
c.TABLE_CATALOG AS DatabaseName, | |
c.TABLE_SCHEMA AS SchemaName, | |
c.TABLE_NAME AS TableName, |
OlderNewer