input
stringclasses
7 values
output
stringclasses
7 values
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Отсортировать книги так, чтобы они шли в алфавитном порядке жанров, а если в жанре несколько книг, то в обратном алфавитном порядке книг
select BookName, BookGenre from Books order by BookGenre, BookName desc;
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Найти тиражи в книги с шифром 6, в которых число поступивших экземпляров меньше 10
select * from Сirculation where NumReceivedCopies<10 and BookСipher=6;
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Найти издательства, в которых торговая наценка находится в диапазоне от 0.15 до 0.3333
select * from PublishingHouse where TradeMargin between 0.1500 and 0.3333;
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Найти авторов, ФИО которых оканчивается на -ов
select * from Bookstore.Authors where AuthorFIO like '%ов';
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Подвести итоги в таблице тиражей: сколько всего тиражей, общее число поступивших экземпляров, минимальное и максимальное число непроданных экземпляров, средняя закупочная цена.
select count(*) as СirculationCount, sum(NumReceivedCopies) as AllReceivedCopies, min(NumUnsoldCopies) as MinUnsoldCopies, max(NumUnsoldCopies) as MaxUnsoldCopies, avg(PurchasePrice) as AvgPurchasePrice from Сirculation;
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Найти все тиражи, в которых количество непроданных копий больше 3, отсортировать и сгруппировать по дате поступления, вывести при условии, что закупочная цена больше 110000
select DeliveryDate, count(*) as Counts, sum(PurchasePrice) as Prices from Сirculation where NumUnsoldCopies>3 group by DeliveryDate having sum(PurchasePrice)>110000 order by DeliveryDate;
create database Bookstore create table Authors( AuthorID integer not null primary key check(AuthorID>0), AuthorFIO varchar(40) not null ); create table Books( Cipher integer not null primary key check(Cipher>0), BookName varchar(4000) not null, BookTheme varchar(30) not null check(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')), BookGenre varchar(15) not null check(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма')) ); create table PublishingHouse( PublishingHouseID integer not null primary key check(PublishingHouseID>0), PublishingHouseName varchar(1000) not null, TradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100) ); create table Circulation( CirculationID integer not null primary key check(CirculationID>0), DeliveryDate date not null, PurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0), NumReceivedCopies integer not null check(NumReceivedCopies>=0), NumUnsoldCopies integer not null check(NumUnsoldCopies>=0), BookCipher integer not null check(BookCipher>0), IDPublishingHouse int not null check(IDPublishingHouse>0), foreign key(BookCipher) references Books(Cipher) on update cascade, foreign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade, check(NumReceivedCopies>NumUnsoldCopies) ); create table Cheque( ChequeID integer not null primary key check(ChequeID>0), PurchaseDate date not null, CashierFIO varchar(40) not null ); create table Wrote( IDAuthor integer not null check(IDAuthor>0), BookCipher integer not null check(BookCipher>0), foreign key(IDAuthor) references Authors(AuthorID) on update cascade, foreign key(BookCipher) references Books(Cipher) on update cascade, primary key(IDAuthor,BookCipher) ); create table Contains( IDCheque int not null check(IDCheque>0), IDCirculation int not null check(IDCirculation>0), BooksQuantity int not null check(BooksQuantity>0), foreign key(IDCheque) references Cheque(ChequeID) on update cascade, foreign key(IDCirculation) references Circulation(CirculationID) on update cascade, primary key(IDCheque,IDCirculation) );Сделать суммирующую строку для жанра и темы книги, посчитать количество книг для каждой пары жанр-тема.
select [BookTheme],[BookGenre], count(*) as Counts from [dbo].[Books] group by [BookTheme],[BookGenre] with rollup;
README.md exists but content is empty.
Downloads last month
44