Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Kursa4_BD1.docx
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
183.46 Кб
Скачать
      1. Інформаційно-пошукові запити

Наведемо приклади інформаційно пошукових запитів відносно тих задач, які були окреслені в підрозділі «2.4. Інформаційно-довідкові задачі». Приклади наведемо у мові SQLMSSQLз використанням бази даних, визначеної у попередньому підрозділі.

Запит. Надавання інформації щодо здійснюваних польотів в різні країни та міста, різними авіалайнерами, авіакомпаніями;

selectairport.country, airport.City

from flight, airport

whereflight.endposition = airport.airid;

selectairliner.name, airliner.num

fromflight, airliner

whereflight.airFK = airliner.airid;

selectcompany.name

fromflight, company

whereflight.comfk = company.comid;

Запит:Перевірка наявності вільних та проданих місць;

select

seat.soldFcsas "Firstclass",

seat.soldBcSas "Businessclass",

seat.soldEcSas "Economyclass"

fromflight, seat

whereflight.seafk = seaidandflight.fliid = 1;

select

(variantairliner.FirstClasSseat - seat.soldFcs) as "FreeinFirstclass",

(variantairliner.BusinessClassSeat - seat.soldBcS) as "FreeinBusinessclass",

(variantairliner.EconomyClassSeat - seat.soldEcS) as "FreeinEconomyclass"

fromflight, seat, airliner, variantairliner

whereflight.seafk = seaidandflight.fliid = 1 andflight.airFK = airliner.airidand

airliner.varfk = variantairliner.varID;

Запит: Можливість підібрати певний варіант літака для певного польоту

select

min(variantairliner.FirstClasSseat - seat.soldFcs) as "min in First class",

min(variantairliner.BusinessClassSeat - seat.soldBcS) as "min in Business class",

min(variantairliner.EconomyClassSeat - seat.soldEcS) as "min in Economy class"

from flight, seat, airliner, variantairliner

whereflight.seafk = seaid and flight.fliid = 1 and flight.airFK = airliner.airid and

airliner.varfk = variantairliner.varID;

Запит: Надавання інформації про клієнтів компанії, а також пасажирів літака;

select *

fromClient;

selectname, surname, age, passport, country, city, address, phone

fromclient, ticket

whereticket.cliFK = client.cliID;

Запит: Можливість передавання електронного квитка клієнту

selectticFK as "Ticket id", email, Fax

frometicket;

Запит: Отримати перелік польотів, що виконуються певною компанією

select

flight.FliIDas "Flight #",

Airport.Nameas "From"

fromflight, company, airport

whereflight.comFK = Company.ComIDandflight.beginposition = airport.airidand

company.name = 'aerosvit';

Запит: Отримати перелік польотів, що задовольняють критеріям клієнта

select

flight.FliIDas "Flight #"

fromflight, airport, company

whereflight.endposition = airport.airidand

flight.begintimebetweento_date('01.01.2011') andto_date('05.01.2011')and

airport.City = 'Berlin'andCompany.name = 'Aerosvit';

select

flight.FliIDas "Flightnumber"

fromflight, airport, company, airliner, variantairliner, seat

whereflight.endposition = airport.airidand

flight.begintimebetweento_date('01.01.2011') andto_date('05.01.2011')and

airport.City = 'Madrid'andCompany.name = 'Aerosvit'and

flight.airFK = airliner.airidandairliner.varfk = variantairliner.varidand

flight.seafk = seat.seaidand

variantairliner.firstclassSeat - soldfcs> 0;

Запит:Отриманнястатистичноїінформації.

selectcount(*)

fromticket;

selectClient.Name, max(Client.surname)

fromticket, client

whereticket.clifk = client.cliid

groupbyClient.surname, client.Name

selectcount(flight.Fliid)

fromflight

whereflight.begintimebetweento_date('01.01.2010') andto_date('01.01.2011');

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]