数据库1——简单 单表查询(50)

10-32 查询xsda表中所有女生的记录
 

select * from xsda
where 性别 ='女';

10-33 查询xscj表中的学号,姓名,计算机三项信息,结果按计算机成绩的降序排列。
 

select 学号,姓名,计算机
from xscj order by 计算机 desc;

10-34 查询xscj表中的计算机成绩在80至90之间(包含80和90分)的同学的学号,姓名,计算机三项信息。
 

select 学号,姓名,计算机
from xscj
where 计算机>='80' and 计算机 <='90';

10-35 计算xscj表中计算机课程的最高分
 

select max(计算机) as 计算机最高分 from xscj;

10-36 计算xscj表中计算机课程的最低分
 

SELECT min(计算机) AS 计算机最低分 FROM xscj

10-37 计算xscj表中英语课程的平均分
 

SELECT avg(英语) AS 英语平均分 FROM xscj

10-38 统计xscj表中计算机课程成绩在90至100之间的人数(包含90和100)
 

SELECT count(计算机) AS 计算机优秀人数 FROM xscj
where 计算机>='90' and 计算机<='100';

10-39 查询xsda表中的学号、姓名、性别三项信息,结果按照女生优先的顺序显示。
 

select 学号,姓名,性别
from xsda
order by 性别;

10-40 统计xsda表中男女生的人数
 

select 性别,count(*) as 人数 from xsda group by 性别

10-41 计算xsda表中男女生的平均身高
 

select 性别,avg(身高) as 平均身高 from xsda group by 性别

10-42 计算xsda表中最高同学的身高
 

select max(身高) as 最高同学的身高 from xsda;

10-43 计算xsda表中最矮同学的身高
 

select min(身高) as 最矮同学的身高 from xsda;

10-44 查询zgda表中所有女教授的信息
 

select 工号,姓名,性别,出生日期,院系,职称
from zgda
where 性别='女' and 职称='教授';

10-45 查询zgda表中的工号,姓名,性别,职称4项信息,显示结果时首先按照女性在前的顺序,如果性别相同则按照职称的升序排列。
 

select 工号,姓名,性别,职称 from zgda order by 性别 desc,职称 asc

10-47 sql-select-sample
 

select id,name from Student
where id>'50';

10-48 查询学生表所有学生记

select * from stu;

10-49 查询学生表中部分信

select sno,sname,
(case when sex=1 then '男' when sex=0 then '女' end) 
as sex from stu;


10-50 查询学生表中的女生信息

select sno as 学号,sname as 姓名
from stu
where sex='女';

10-52 查询姓‘李’的学生记录

select sno as 学号,sname as 姓名,sex as 性别,mno as 专业,
birdate as 出生日期,memo as 备注
from stu 
where sname like'李%';

10-80 2-1(a) 查询st1制片公司的地址

select address from Studio
where name='st1';

10-81 2-1(b)查询影星S1的出生日期

select birthdate from MovieStar
where name='S1';

10-82 A1-1查询联系人信息

select CompanyName,ContactName
from customers 
where City='London';

10-83 2-1-(c) 查询在1990年拍摄过电影的所有影星,或者拍摄过电影名中含有"3"的电影的所有影星

select distinct starName from StarsIn
where movieTitle like'%3%' or movieYEAR='1990';

10-84 2-1-(e) 查询所有的男影星或者住址中含有4的影星

select name from MovieStar
where gender='M' or address like'%4%';

10-85 2-1-(d) 查询净资产至少200万美元的所有行政长官
检索出MovieExec表中净资产至少200万美元的所有行政长官。

select MovieExec.name from MovieExec,Studio 
where MovieExec.certID=Studio.presCertID and netWorth>200;

10-86 2-2-(a)查询价格低于1600美元的个人计算机的型号(model)、速度(speed)及硬盘容量(hd)
检索出pc表中价格低于1600美元的个人计算机的型号(model)、速度(speed)及硬盘容量(hd)。

select model,speed,hd
from pc
where price<='1600';

10-87 2-2-(b)查询价格低于1600美元的个人计算机的型号、速度及硬盘容量,将"speed"改为"兆赫","hd"改为"吉字节"

select model,speed as 兆赫,hd as 吉字节
from pc
where price<'1600';

10-88 2-2-(c)查询打印机的制造商

select distinct maker
from product
where type='打印机'

10-89 2-2-(d)查询费用高于2000美元的便携式电脑的型号)、内存容量以及屏幕尺寸

select model,ram,screen from laptop
where price>='2000';

10-92 2-2-(e)查询所有彩色打印机的元组

select model,color,type,price
from printer
where color='1';

10-95 2-2-(f)查询具有1GB以上的硬盘容量而价格低于2000美元的所有个人计算机的型号、速度以及硬盘容量

select model,speed,hd from pc
where hd>'1' and price<'2000';

10-101 A1-2根据所在国家查找订单信息

订单表(orders)中找出所在国家(ShipCountry)GermanyBrazilFrance订单编号(OrderID)顾客编号(CustomerID)

select OrderID,CustomerID from orders
where shipCountry='Germany' or shipCountry='Brazil' or shipCountry='France';

10-102 A1-3查询顾客表中所有不重复的城市

查询出顾客表(customers)中所有不重复的所在城市(City)

提示:请使用SELECT语句作答。

SELECT DISTINCT City
FROM customers;

10-103 A1-4在产品表中找出库存数量大于50的产品的信息

产品表(products)中找出库存数量(UnitsInStock)大于50产品编号(ProductID),产品名称(ProductName)
提示:请使用SELECT语句作答。

select ProductID,ProductName from products
where UnitsInStock>'50';

10-104 3-1-(d)查询比电影《M1》时间更长的电影
查询比电影M1时间更长的电影。

select title,year from Movie
where length>'100'; 

10-106 A1-5在顾客表中找出特定名字的顾客信息

顾客表(customers)中找出公司名(CompanyName)中包含字符串th的顾客编号和公司名称

提示:请使用SELECT语句作答。

select CustomerID,CompanyName from customers
where CompanyName like'%th%';

10-110 3-2-(d)查询在两种或两种以上PC机上出现的硬盘容量

本题目要求编写SQL语句,
查询在两种或两种以上PC机上出现的硬盘容量。

select hd from pc group by hd having count(hd)>=2;

10-111 3-2-(e)查询拥有相同速度和内存的PC机的成对的型号
查询拥有相同速度和内存的PC机的成对的型号,输出结果属性名分别为model1,model2。

提示:请使用SELECT语句作答。

select pc1.model as model1,pc2.model as model2 
from pc pc1,pc pc2
where pc1.speed=pc2.speed and pc1.ram=pc2.ram and pc1.model<pc2.model

10-112 A1-6在顾客表中找出不是特定城市的顾客信息

顾客表(customers)中找出所在城市(City)不是MadridTorinoParis顾客编号(CustomerID)电话(Phone)

select CustomerID,Phone from customers
where City!='Madrid' and City!='Torino'and City!='Paris';

10-113 A1-7在产品表中找出库存量小于订购量的产品信息

产品表(products)中找出库存量(UnitsInStock)小于订购量(UnitsOnOrder)的产品的产品编号(ProductID)产品名称(ProductName)
提示:请使用SELECT语句作答。

select ProductID,ProductName from products
where UnitsInStock<UnitsOnOrder;


10-114 A1-8查询传真号码不为空的供货商信息

供货商(suppliers)中查找传真号码(Fax)不为NULL的供货商信息供货商编号(SupplierID)公司名称(CompanyName)

提示:请使用SELECT语句作答。

select SupplierID,CompanyName from suppliers
where Fax is not null;


10-115 A2-1查找产品表中再次订购量大于15的产品信息

产品表(products)中找出再次订购量(ReorderLevel)大于15的产品的产品编号(ProductID)产品名称(ProductName)供货商编号(SupplierID)
提示:请使用SELECT语句作答。

select ProductID,ProductName,SupplierID from products
where ReorderLevel>15;


10-116 A2-2查找产品表中再次订购量大于等于10且修订量大于订货数量的产品信息

产品表(products)中找出再次订购量(ReorderLevel)大于等于10,且再次订购量(ReorderLevel)大于订购数量(UnitsOnOrder)的产品的产品编号(ProductID)产品名称(ProductName)供货商编号(SupplierID)

提示:请使用SELECT语句作答。

select ProductID,ProductName,SupplierID from products
where ReorderLevel>=10 and ReorderLevel>UnitsOnOrder;

10-117 A2-3查询产品表中单价不在范围内的的产品信息

产品表(products)中查询单价(UnitPrice)小于15或大于45的产品的产品编号(ProductID)产品名称(ProductName)种类编号(CategoryID)

提示:请使用SELECT语句作答。

select ProductID,ProductName,CategoryID from products
where UnitPrice<15 or UnitPrice>45;

10-121 A3-1查询订单表中的平均运费

查询订单表(orders)平均运费,并将其重命名为avgFreight

提示:请使用SELECT语句作答。

select avg(Freight) as avgFreight from orders;

10-122 A3-2查询国家为Mexico、Germany的客户数量

查询出顾客表(customers)中查询国家(Country)MexicoGermany的客户数量,并重命名为custCount

提示:请使用SELECT语句作答。

select count(Country) as custCount from customers 
where Country='Mexico' or Country='Germany';

10-123 A3-3查找产品表中最低的单价

产品表(products)中查询最低的单价(UnitPrice),并重命名为minUnitPrice

提示:请使用SELECT语句作答。

select min(UnitPrice) as minUnitPrice from products;

10-124 A3-4查询产品表中最大库存量

产品表(products)中查询最多的库存数量(UnitsInStock),并重命名为maxUnitsInStock

提示:请使用SELECT语句作答。

select max(UnitsInStock) as maxUnitsInStock  from products;

10-125 A4-1查找订单表中每位顾客的平均运费

查询订单表(orders)中每位顾客的平均运费,结果显示为顾客编号(CustomerID)平均运费(avgFreight)

提示:请使用SELECT语句作答。

select CustomerID,avg(Freight) as avgFreight 
from orders
group by CustomerID;

10-126 A4-2统计顾客表中每个国家的顾客数量

查询出顾客表(customers)中查询每个国家的客户数量,显示为国家(Country)客户数量(custCount)

提示:请使用SELECT语句作答。

select Country,count(*) as custCount
from customers
group by Country


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值