oracle-求三个很简单的 Oracle 语句(只是因为英文题目,看着有点晕而已)

问题描述

求三个很简单的 Oracle 语句(只是因为英文题目,看着有点晕而已)

airports(acode, name, city, country, tzone);
flights(flightno, src, dst, dep_time, est_dur);
sch_flights(flightno, dep_date, act_dep_time, act_arr_time);
fares(fare, descr);
flight_fares(flightno, fare, limit, price, bag_allow);
passengers(email, name, country);
tickets(tno, email, paid_price);
bookings(tno, flightno, fare, dep_date, seat);



以上是表的信息,以下是问题,我只需要最后三道题的SQL语句。



The tables are derived from the Assignment 1 spec and the names of the tables and columns should give the semantics, except minor differences which are explicit in table definitions, insert statements or queries.

Creating the database

Using the SQL statements provided, create the above tables in Oracle under your user name and populate them with some data. Here is a small initial data to get you started.

(90 marks) Queries

Write down the following queries in SQL and run them in SQL*PLUS (or SQL developer) over the database created. You will be writing ONE SQL statement for every query. Your SQL queries for questions 1-2 cannot use any of aggregation, grouping, or nesting.

1、Find the email address of passengers who have had a flight booked to destination airport YEG.
2、Find the name and email address of passengers who have a flight booked out of Edmonton in December 2015. Hint: Check out the date functions in Oracle.
3、Find flights that are scheduled for a departure within the next 30 days but no one has booked those flights. For every such flight, list the flightno and the dep_date. Hint: Again check out the date functions in Oracle.
4、Find the airports with the largest number of scheduled arrivals. For each such airport, report the airport code and the number of scheduled arrivals.
5、Find top 3 airports with the largest number of scheduled arrivals and departures. For each such airport, report the airport code and the total number of scheduled arrivals and departures. Hint: You may find rank or row_number functions in Oracle useful.
6、Find the cheapest fare from Edmonton to Los Angeles. For the cheapest fare, list the flight number(s), the departure time, the fare type and the price.
7、Create a view called available_flights with the following attributes: flightno, dep_date, src, dst, dep_time, arr_time, fare, seats, price. The view includes all flights between src and dst airports that have a seat available; for every such flight, the view has the flight details including the flight number, the departure date, the source and destination airports, the departure time, the estimated arrival time, the number of seats available under each fare type and the seat price. A fare type is available on a flight if the number of bookings for that fare type is less than the allocated limit. The estimated arrival time is the arrival time at the destination (i.e. it is based on the destination time zone). Treat dep_date, dep_time, arr_time in the view as date types, and don't convert them to char (the conversion can happen inside queries that may use the view). Hint: you may find outer join useful here.
8、Using the view available_flights, find the cheapest direct flights from YEG to YYZ scheduled on December 22, 2015 with an available seat. For each such flight, list the flight number, the fare type, the number of available seats and the seat price.
9、Create a view called good_connections with columns src, dst, dep_date, flightno1, flightno2, layover, and price. The view includes all pairs of flights flightno1 and flightno2 between airports src and dst such that the arriving airport for flightno1 and the departing airport for flightno2 are the same, the connection time between the two flights is at least 90min and at most 5 hours. For each such pair of flights, the view includes the flight numbers, the airport codes for src and dst, the dep_date of the first flight, the layover time and the sum of the price. Assume the view available_flights is available and can be used here.
10、Find top 5 cheapest flights from YEG to LAX scheduled for a departure on Dec 22, 2015, with at most one connection (i.e. at most two flights) and some available seats. For each such flight(s), list the first flightno, the second flightno (if applicable), layover time (if applicable) and the price. Assume the views available_flights and good_connections are both available and can be used here.



以上是所有问题,我只需要最后三个问题的SQL代码,谢谢!!
最后三个问题即问题8、9、10

解决方案

翻译可以给你,但SQL就帮不了哈哈。我跪~

解决方案二:

百度翻译可以帮到你 出门右拐就到了

解决方案三:

8、9、10需要用到视图available_flights,这个视图是7里创建的,如果创建了这个视图,你直接从这个视图里取数据就行了

8的条件是find the cheapest direct flights from YEG to YYZ scheduled on December 22, 2015 with an available seat.

解决方案四:

该表是来自分配1规范和表和列的名称应给予的语义,除了小的差异,这是明确的表的定义,插入语句或查询。

创建数据库

使用提供的SQL语句,创建Oracle上表你的用户名下,一些数据填充它们。这里是一个小的初始数据,让你开始。

(90标记)查询

写出下列查询SQL运行在SQL * Plus(或SQL Developer)在数据库中创建。你会写一个SQL语句为每个查询。你的SQL查询1-2题不能使用任何聚集,分组,或筑巢。

1、发现谁有一个航班的乘客到目的地机场诞生的电子邮件地址。

2、在十二月2015的航班上,找到乘客的姓名和电子邮件地址。提示:查看甲骨文中的日期函数。

3,找到在未来30天内的航班,但没有人已经预订了这些航班。对于每一次这样的飞行,flightno和dep_date列表。提示:再次检查甲骨文中的日期函数。

4、找到最大数量的机场。对于每一个这样的机场,报告机场的代码和预定人数。

5、找到最多的3个机场,数量最多的预定人数和出发点。对于每一个这样的机场,报告机场的代码和总人数的预定人数和离开。提示:你会发现等级或row_number Oracle中的有用的功能。

6,找到最便宜的票价从埃德蒙顿到Los。为最便宜的票价,列出航班号,出发时间,票价类型和价格。

7、创建一个视图称为available_flights具有以下属性:flightno,dep_date,SRC,DST,dep_time,arr_time,票价,座位,价格。视图包含所有航班SRC和DST机场之间,有一个座位;对于每一次这样的飞行,观有航班信息包括航班号,出发日期,来源和目的地机场,出发时间,预计到达时间,座位每张票价类型下的座位数量和价格。如果票价类型的预订数量低于所分配的限额,则可在航班上提供一种票价类型。估计到达时间是到达目的地的到达时间(即它是基于目标时区)。治疗dep_date,dep_time,视图中的arr_time日期类型,不要将它们转换为char(转换可以发生在查询,可以使用视图)。提示:你可能会发现外部连接有用的。

8、使用视图available_flights,找到最便宜的直飞航班从诞生到多伦多定于2015年12月22日与座位。对于每一个这样的飞行,列出航班号,票价类型,可用的座位数量和座位价格。

9、创建一个视图称为DST,SRC柱,dep_date,flightno1,flightno2,停留good_connections,和价格。视图包含所有对机场SRC和DST,到达机场flightno1和离开机场之间的航班flightno2是相同的flightno1和flightno2,两个航班之间的连接时间至少90min和最多5小时。对于航班的每一对,视图包括航班号,SRC和DST的机场代码,第一次飞行的dep_date,的时间和价格的总和。承担的观点available_flights可用,可以用在这里。

10、找到最便宜的机票从5强诞生松懈定于2015年12月22日出发,至多一个连接(即最多两航班)和一些座位。对于每一次这样的飞行(S),列表的第一flightno,第二flightno(如果适用),停留时间(如果适用)和价格。假设的观点available_flights和good_connections都可用,可以用在这里。

时间: 2024-09-17 04:53:03

oracle-求三个很简单的 Oracle 语句(只是因为英文题目,看着有点晕而已)的相关文章

Oracle中备份表的简单sql命令语句_oracle

复制代码 代码如下: create table bmpforest.E_PKG_ATPCFG_BAC as select * from bmpforest.e_pkg_atpcfg where 1=2 insert into E_PKG_ATPCFG_BAC select * from E_PKG_ATPCFG;

执行计划-跪求大神指导:一下sql为什么加了一个exists后查询变得很慢很慢。oracle~

问题描述 跪求大神指导:一下sql为什么加了一个exists后查询变得很慢很慢.oracle~ 具体请见截图,以为是内网无法拷贝代码,请见谅 注: 其中 A 表中的数据大概 60 多万晚条,下面 OB 表中数据才 6 千多条,换成用 in 也是一样的效率啊 exists还造成了全表扫描了,包括buffer sort 了 , 请大神知道如何改写此sql,谢谢啊~~~ 解决方案 求指导,希望大神帮助解答啊,谢谢啊

sql-一道关于数据库的面试题,看着很简单,但我就是不会写。求指导

问题描述 一道关于数据库的面试题,看着很简单,但我就是不会写.求指导 解决方案 oracle的http://www.cnblogs.com/luluping/archive/2012/07/26/2610705.html 解决方案二: 这就是竖表变横表,用case语法汇总,或者用PIVOT(sqlserver方法) 解决方案三: SQL行转列汇总 解决方案四: 本人菜鸟一枚.以下是我想到的一种方法: ---行转列 create table tb( name varchar(10), subjec

三十八载,Oracle伴我同行—记我的职业成长之路

题记 三十八载 Oracle伴我同行 --记我的职业成长之路 2015,今年是Oracle公司38周年:2015,今年我已然38岁.在Oracle庆祝38岁生日之际,仅以此文作为回顾,记录我的Oracle技术之路. 缘起边陲 恰同学风华正茂 我在2000年大学毕业时,第一次接触到Oracle数据库,作为一个程序员,开始从网络配置一步一步深入Oracle数据库的内部. 很幸运,在我作为程序员的职业生涯中,我的第一位师傅把云波先生,不断给我信任和鼓励,也不断促进我的学习,在我能够轻松完成开发工作

立等可取:工具定制让Oracle优化变得更简单快捷

   Oracle的优化工具很是丰富,大家基本都会常用到的awr,ash,addm自不必多说,还有大量的tuning包,可能在EM中去用感觉还方便一些,就是动动鼠标,所见即所得,而且sql monitor作为11g的新特性,对于调优来说也是如虎添翼.但是作为前线的工程师们,总是会有各种环境的挑战,想用图形工具还是比较困难的,优化工具虽好,但是使用起来如果不太方便,或者很多时候不能很快定位问题,就会让人感觉使不上劲,眉毛胡子一把抓.这也是我简单定制这些工具的一个动力.所谓磨刀不误砍柴工,这些强大的

oracle 求两个时间点直接的分钟、小时数

select sum(ceil((gdr.enddt - gdr.startdt) * 24)) h, sum(ceil((gdr.enddt - gdr.startdt) * 24 * 60)) m, sum(ceil((gdr.enddt - gdr.startdt) * 24 * 60 * 60)) s from gat_data_record gdr where gdr.enddt between to_date('2011-1-1','yyyy-mm-dd') and to_date(

想做个很简单的服务器,但是不知道怎么做了,求指点,真的很简单

问题描述 想做个很简单的服务器,但是不知道怎么做了,求指点,真的很简单 就是c/s模型的服务器端,客户端在安卓手机上,通过URL请求服务器数据,服务器返回一串json数组就好.这个功能的服务器该看什么方面的东西??完全没做过,求大牛. 解决方案 最简单的,服务器用jsp写一个web service,客户端用httpclient连它.具体google下. 解决方案二: 参考:http://blog.csdn.net/ice343241993/article/details/22037829http

oracle 求大神解决谢谢!!!! select报错怎么改 急急急

问题描述 oracle 求大神解决谢谢!!!! select报错怎么改 急急急 select mv.*,(select r.currency,trunc(r.rcv_date,'MM') as rcv_date,sum(decode(r.transaction_type, 'RECEIVE', 1, -1) * r.QUANTITY) from epms_erp_rcvqty_info r where r.LINE_LOCATION_ID = '33733' and r.rcv_date >=

《Oracle性能优化与诊断案例精选》——第1章 三十八载,Oracle伴我同行 1.1 缘起边陲,恰同学风华正茂

第1章 三十八载,Oracle伴我同行 Oracle性能优化与诊断案例精选--记我的职业成长之路(盖国强) 题记 2015年是Oracle公司38周年,2015年我38岁.在Oracle庆祝38岁生日之际,谨以此文作为回顾,记录我的Oracle技术之路.同时也希望可以给走在技术道路上的朋友们以借鉴. 1.1 缘起边陲,恰同学风华正茂 2000年大学毕业时,我在第一份工作中第一次接触到Oracle数据库.那时我作为一个程序员,参与了一个大型企业ERP系统的开发进程.也就是从那时开始,我由网络配置一