1 Star 0 Fork 48

段文杰/SQL Server作业仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
李春阳子4.09作业.sql 5.08 KB
一键复制 编辑 原始数据 按行查看 历史
李春阳 提交于 2021-04-11 23:32 . LCYZ.4.09作业
create database goodsdb
go
use goodsdb
go
create table goodstype
(
typeid int not null identity(1,1) primary key ,
typename nvarchar(20) not null
)
create table goodsinfo
(
goodsid int not null identity (1,1) primary key,
goodsname nvarchar(20) not null ,
goodscolor nvarchar(20) not null,
goodsbrand nvarchar(20) ,
goodsmoney money not null,
typeid int references goodstype (typeid)
)
insert into goodstype(typename)
values
('服装内衣'),('鞋包配饰'),('手机鞋码')
insert into goodsinfo(goodsname,goodscolor,goodsbrand,goodsmoney,typeid)
values
('提花小西装','红色','菲曼琪',300,1),('百搭短裤 ','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1),
('低帮休闲鞋',' 红色 ','菲曼琪',900,2),('中跟单鞋','绿色','哥弟 ',400,2),('平底鞋','白色','阿依莲',200,2),
('迷你照相机','红色','尼康',500,3),('硬盘 ','黑色 ','希捷',600,3),(' 显卡 ','黑色','技嘉 ',900,3)
--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名
select top 1 goodsname,goodscolor,goodsmoney from goodsinfo
order by goodsmoney desc
--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名
select typeid,max(goodsmoney) 商品最高价格 ,min(goodsmoney) 最低价格,avg(goodsmoney) 平均价格 from goodsinfo
group by typeid
--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间
select * from goodsinfo
where goodscolor in (select goodscolor from goodsinfo where goodscolor='红色')
and goodsmoney in (select goodsmoney from goodsinfo where goodsmoney>300 and goodsmoney <600)
create database housedb
on
(
maxsize=50mb,
size=5mb,
filegrowth=1mb,
filename='C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA',
name='nb.ndf'
)
go
use housedb
go
create table housetype
(
typeid int identity(1,1) primary key,
typename varchar(50) unique
)
create table house
(
houseid int primary key identity(1,1),
housename varchar(50) ,
houseprice float default(0),
typeid int references housetype(typeid)
)
insert into housetype(typename )
values
('小户型'),('经济型'),('别墅')
insert into house(housename,houseprice,typeid)
values
('小户型1','1000',1),('小户型2','1100',1),('经济型1','2000',2),
('经济型2','2200',2),('别墅1','3000',3),('别墅2','3300',3)
--4、添加查询
--查询所有房屋信息
select * from house
--使用模糊查询包含”型“字的房屋类型信息
select * from house
where housename like '%型%'
--查询出房屋的名称和租金,并且按照租金降序排序
select housename,houseprice from house
order by houseprice desc
--使用连接查询,查询信息,显示房屋名称和房屋类型名称
select housename,typename from house
inner join housetype on housetype.typeid=house.typeid
--查询所有房屋中月租最高的房屋,显示最高的租金和房屋名称
select top 1 housename,houseprice from house
order by houseprice desc
create database stardb
go
use stardb
go
create table startype
(
tno int identity(1,1) primary key,
tname nvarchar(20)
)
create table starinfo
(
sno int identity(1,1) primary key ,
sname nvarchar(20),
sage int ,
shobby nvarchar(20) ,
snative nvarchar(20) default('中国大陆'),
stno int references startype(tno)
)
insert into startype(tname)
values
('体育明星'),('IT明星'),('相声演员')
insert into starinfo(sname,sage,shobby,snative,stno)
values
('梅西',30,'射门','阿根廷',1),('科比',35,'过人','美国',1),('蔡景现',40,'敲代码','中国',2),
('马斯克',36,'造火箭','外星人',2),('郭德纲',50,'相声','中国',3),('黄铮',41,'拼多多','中国',2)
--3、查询年龄最大的3个明星的姓名,特技和籍贯信息,要求使用别名显示列名。
select top 3 sname,shobby,snative from starinfo
order by sage desc
--4、按明星类型编号分类查询明星人数,明星平均年龄,显示明星人数大于2的分组信息,要求使用别名显示列名。
select stno,count(sname)明星人数,avg(sage)明星平均年龄 from starinfo
group by stno
having count(sname)=2
--5、查询明星类型为“体育明星”中年龄最大的姓名、特技、籍贯信息,要求显示列别名。
select top 1 sname,shobby,snative from startype
inner join starinfo on startype.tno=starinfo.stno
where tname='体育明星'
create database xt
go
use xt
go
create table a--用户信息
(
aid int identity(1,1) primary key,--用户id
aname nvarchar(20) unique,--用户名称
)
create table b--供应商信息
(
bid int references a(aid),--供应商id
huowid int references c(huowid),--供应商提供货物id
)
create table c--提货客户信息
(
cid int references a(aid),--提货客户id
cname nvarchar(20) ,--提货客户名称
huowid int identity(1,1) primary key,--货物id
ckid int references d(did),--仓库id
)
create table d--仓库信息
(
did int primary key,--仓库id
houwcount int --货物数量
)
create table e--商品信息
(
houwid int references c(huowid),--货物id
houwname nvarchar(20) --货物名称
)
create table f--商品入库
(
fid int ,--货物id
rkid int references d(did),--仓库id
bid int references a(aid),--供应商id
rkprice money ,--入库价格
fcount int,--入库数量
workerid int references a(aid) --入库操作人员
)
create table g--商品出库
(
houwid int references c(huowid),--出库货物id
ckid int references d(did),--仓库id
cid int references a(aid),--提货人员id
ckcount int ,--仓库数量
cktime datetime ,--出库时间
workerid int references a(aid)--操作人员id
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/duan-wenjie/sql-server-job-warehouse.git
git@gitee.com:duan-wenjie/sql-server-job-warehouse.git
duan-wenjie
sql-server-job-warehouse
SQL Server作业仓库
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385