Skip to content

Instantly share code, notes, and snippets.

1.
UPDATE Products_menu
SET date_of_delivery = GETDATE()
WHERE date_of_delivery = NULL
2.
DELETE FROM Products_menu
WHERE measurement < 100 AND price > 70
-- phpMyAdmin SQL Dump
-- version 3.3.5-rc1
-- http://www.phpmyadmin.net
--
-- Хост: localhost
-- Время создания: Авг 25 2010 г., 01:45
-- Версия сервера: 5.4.3
-- Версия PHP: 5.2.13-pl0-gentoo
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
USE [master]
GO
/****** Object: Database [Store] Script Date: 25.05.2023 21:40:15 ******/
CREATE DATABASE [Store]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'Store', FILENAME = N'C:\1\Store.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'Store_log', FILENAME = N'C:\1\Store_log.ldf' , SIZE = 1280KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
WITH CATALOG_COLLATION = DATABASE_DEFAULT, LEDGER = OFF
1.
SELECT Product.name, Category.name, Supplier.name
FROM Product
JOIN Delivery ON Delivery.id = Product.id_producer
JOIN Supplier ON Supplier.id = Delivery.id_supplier
JOIN Category ON Category.id = Product.id_category
WHERE Supplier.name LIKE 'Супер закупка' OR Supplier.name LIKE 'Юж поставка'
2.
1.
SELECT Product.name, Delivery.date_of_delivery, Supplier.name
FROM Product
JOIN Delivery ON Delivery.id = Product.id_producer
JOIN Supplier ON Supplier.id = Delivery.id_supplier
2.
SELECT Region.name
2.
SELECT c.name, SUM(price * quantity) AS TotalSales
FROM Category c
JOIN Product p ON c.id = p.id_category
WHERE c.name IN ('Мясные', 'Хлебо-булочные')
GROUP BY c.name
3.
1.
DECLARE @start int = 0
DECLARE @finish int = 5
DECLARE @current int = @start
DECLARE @result nvarchar(500) = ''
WHILE @current < @finish
BEGIN
SET @result += '*'
   SET @current += 1
END
1.
DECLARE @string nvarchar(50) = 'нажал кабан на баклажан'
SET @string = REPLACE(@string, ' ', '')
IF @string = REVERSE(@string)
PRINT 'Строка является палиндромом'
ELSE
PRINT 'Строка не является палиндромом'
2.
DECLARE @string nvarchar(100) = 'Алекстандр так любит есть шаурму, что готов есть шаурму каждый день.'
DECLARE @string NVARCHAR(1000)
DECLARE @word NVARCHAR(50)
DECLARE @space INT
DECLARE @words TABLE (
word NVARCHAR(50),
amount INT
)
DECLARE cur CURSOR FOR SELECT mess FROM messages
OPEN cur
FETCH NEXT FROM cur INTO @string
USE [Library];
DECLARE @table TABLE (
id INT,
first_name VARCHAR(50),
last_name VARCHAR(50),
role VARCHAR(20),
department VARCHAR(20),
birthday DATE
);