File size: 18,838 Bytes
8b36206 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Отсортировать книги так, чтобы они шли в алфавитном порядке жанров, а если в жанре несколько книг, то в обратном алфавитном порядке книг",
"output": "select BookName, BookGenre from Books order by BookGenre, BookName desc;"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Найти тиражи в книги с шифром 6, в которых число поступивших экземпляров меньше 10",
"output": "select * from Сirculation where NumReceivedCopies<10 and BookСipher=6;"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Найти издательства, в которых торговая наценка находится в диапазоне от 0.15 до 0.3333",
"output": "select * from PublishingHouse where TradeMargin between 0.1500 and 0.3333;"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Найти авторов, ФИО которых оканчивается на -ов",
"output": "select * from Bookstore.Authors where AuthorFIO like '%ов';"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Подвести итоги в таблице тиражей: сколько всего тиражей, общее число поступивших экземпляров, минимальное и максимальное число непроданных экземпляров, средняя закупочная цена.",
"output": "select count(*) as СirculationCount, sum(NumReceivedCopies) as AllReceivedCopies, min(NumUnsoldCopies) as MinUnsoldCopies, max(NumUnsoldCopies) as MaxUnsoldCopies, avg(PurchasePrice) as AvgPurchasePrice from Сirculation;"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Найти все тиражи, в которых количество непроданных копий больше 3, отсортировать и сгруппировать по дате поступления, вывести при условии, что закупочная цена больше 110000",
"output": "select DeliveryDate, count(*) as Counts, sum(PurchasePrice) as Prices from Сirculation where NumUnsoldCopies>3 group by DeliveryDate having sum(PurchasePrice)>110000 order by DeliveryDate;"
},
{
"input": "\ncreate database Bookstore\n\ncreate table Authors(\nAuthorID integer not null primary key check(AuthorID>0),\nAuthorFIO varchar(40) not null\n);\n\ncreate table Books(\nCipher integer not null primary key check(Cipher>0),\nBookName varchar(4000) not null,\nBookTheme varchar(30) not null\ncheck(BookTheme in('Любовь','Дружба','Смерть','Общественные проблемы','Внутренние противоречия')),\nBookGenre varchar(15) not null\ncheck(BookGenre in('Роман','Поэма','Рассказ','Пьеса','Эпопея','Драма'))\n);\n\ncreate table PublishingHouse(\nPublishingHouseID integer not null primary key\ncheck(PublishingHouseID>0),\nPublishingHouseName varchar(1000) not null,\nTradeMargin decimal(5,4) default'0' not null check (TradeMargin>0 and TradeMargin<=100)\n);\n\ncreate table Circulation(\nCirculationID integer not null primary key check(CirculationID>0),\nDeliveryDate date not null,\nPurchasePrice decimal(18,4) default'1000.0000' not null check(PurchasePrice>0),\nNumReceivedCopies integer not null check(NumReceivedCopies>=0),\nNumUnsoldCopies integer not null check(NumUnsoldCopies>=0),\nBookCipher integer not null check(BookCipher>0),\nIDPublishingHouse int not null check(IDPublishingHouse>0),\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nforeign key(IDPublishingHouse) references PublishingHouse(PublishingHouseID) on update cascade,\ncheck(NumReceivedCopies>NumUnsoldCopies)\n);\n\ncreate table Cheque(\nChequeID integer not null primary key\ncheck(ChequeID>0),\nPurchaseDate date not null,\nCashierFIO varchar(40) not null\n);\n\ncreate table Wrote(\nIDAuthor integer not null check(IDAuthor>0),\nBookCipher integer not null check(BookCipher>0),\nforeign key(IDAuthor) references Authors(AuthorID) on update cascade,\nforeign key(BookCipher) references Books(Cipher) on update cascade,\nprimary key(IDAuthor,BookCipher)\n);\n\ncreate table Contains(\nIDCheque int not null check(IDCheque>0),\nIDCirculation int not null check(IDCirculation>0),\nBooksQuantity int not null check(BooksQuantity>0),\nforeign key(IDCheque) references Cheque(ChequeID) on update cascade,\nforeign key(IDCirculation) references Circulation(CirculationID) on update cascade,\nprimary key(IDCheque,IDCirculation)\n);Сделать суммирующую строку для жанра и темы книги, посчитать количество книг для каждой пары жанр-тема.",
"output": "select [BookTheme],[BookGenre], count(*) as Counts from [dbo].[Books] group by [BookTheme],[BookGenre] with rollup;"
}
] |