From 7d92fa6b8b5f1b82bc36f21426ae07e3029da552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <2496363855@qq.com> Date: Mon, 5 Apr 2021 23:45:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A2=81=E4=B8=96=E8=B1=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../4.1a1.sql" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\346\242\201\344\270\226\350\261\252/4.1a1.sql" diff --git "a/\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\346\242\201\344\270\226\350\261\252/4.1a1.sql" "b/\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\346\242\201\344\270\226\350\261\252/4.1a1.sql" new file mode 100644 index 0000000..b0057fa --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\346\242\201\344\270\226\350\261\252/4.1a1.sql" @@ -0,0 +1,54 @@ +use master +go +create database GoodsDB +on +( + name='GoodsDB.mdf', + filename='D:\GoodsDB.mdf', + size=5, + maxsize=15, + filegrowth=15% +) +log on +( + name='GoodsDB_log.ldf', + filename='D:\GoodsDB_log.ldf', + size=5, + maxsize=15, + filegrowth=15% +) +go +use GoodsDB +go +create table GoodsType +( + TypeID int primary key identity(1,1), + TypeName nvarchar(20) not null +) +go +create table GoodsInfo +( + GoodsID int primary key identity(1,1), + 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 values ('提花小西装', '红色' ,'菲曼琪', '300' ,'1'), +('百搭短裤', '绿色',' 哥弟', '100', 1),('无袖背心', '白色',' 阿依莲',' 700', 1), +('低帮休闲鞋',' 红色',' 菲曼琪',' 900', 2), +('中跟单鞋',' 绿色 ','哥弟',' 400', 2),('平底鞋',' 白色 ','阿依莲',' 200', 2), +('迷你照相机',' 红色',' 尼康',' 500', 3), +('硬盘',' 黑色 ','希捷',' 600', 3),('显卡',' 黑色',' 技嘉', '800', 3) +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +select top 1 GoodsName 商品名称,GoodsColor 商品颜色,max(GoodsMoney) 最贵的商品价格 from GoodsInfo +group by GoodsName,GoodsColor order by max(GoodsMoney) desc +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +select TypeID 商品类型编号,max(GoodsMoney) 商品最高价格, +min(GoodsMoney) 最低价格,avg(GoodsMoney) 平均价格 + from GoodsInfo group by TypeID +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 +select * from GoodsInfo where GoodsColor='红色' and (GoodsMoney between 300 and 600) \ No newline at end of file -- Gitee