From 76c009ff7aa83b468f3a66570b92fed0d20999c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=83=E6=96=87=E6=B5=A9?= <1208984334@qq.com> Date: Mon, 5 Apr 2021 23:09:43 +0800 Subject: [PATCH] zy --- ...\347\273\203\344\271\240\351\242\2301.sql" | 71 +++++++++++++++++++ 1 file changed, 71 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/\347\273\203\346\226\207\346\265\251/\347\273\203\344\271\240\351\242\2301.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/\347\273\203\346\226\207\346\265\251/\347\273\203\344\271\240\351\242\2301.sql" "b/\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\347\273\203\346\226\207\346\265\251/\347\273\203\344\271\240\351\242\2301.sql" new file mode 100644 index 0000000..e841897 --- /dev/null +++ "b/\347\254\254\345\215\201\344\270\211\346\254\241\350\257\276\344\275\234\344\270\232/\347\273\203\346\226\207\346\265\251/\347\273\203\344\271\240\351\242\2301.sql" @@ -0,0 +1,71 @@ +Use master +go + +create database GoodsDB +on +( +name='GoodsDB', +filename='D:\GoodsDB.mdf', +size=5MB, +maxsize=50MB, +filegrowth=10% + +) +log on +( +name='GoodsDB_log', +filename='D:\GoodsDB_loh.ldf', +size=5MB, +Maxsize=50MB, +filegrowth=10% +) +go + +use GoodsDB +go + +Create table GoodsType +( + TypeID int primary key identity(1,1) not null, + TypeName nvarchar(20) not null +) + +create table GoodsInfo +( + GoodsID int primary key identity(1,1) not null , + 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 values +('服装内衣'),('鞋包配饰'),('手机数码') + +insert into GoodsInfo values +('提花小西装','红色','菲曼琪',300,1),('百搭短裤','绿色','哥弟',100,1),('无袖背心','白色','阿依莲',700,1), +('低帮休闲鞋','红色','菲曼琪',900,2),('中跟单鞋','绿色','哥弟',400,2),('平底鞋','白色','阿依莲',200,2), +('迷你照相机','红色','尼康',500,3),('硬盘','黑色','希捷',600,3),('显卡','黑色','技嘉',800,3) +--1 提花小西装 红色 菲曼琪 300 1 +--2 百搭短裤 绿色 哥弟 100 1 +--3 无袖背心 白色 阿依莲 700 1 +--4 低帮休闲鞋 红色 菲曼琪 900 2 +--5 中跟单鞋 绿色 哥弟 400 2 +--6 平底鞋 白色 阿依莲 200 2 +--7 迷你照相机 红色 尼康 500 3 +--8 硬盘 黑色 希捷 600 3 +--9 显卡 黑色 技嘉 800 3 + + + +Select * from GoodsType +Select * from GoodsInfo +--3、查询价格最贵的商品名称,商品颜色和商品价格,要求使用别名显示列名 +--4、按商品类型编号分组查询商品最高价格,最低价格和平均价格,要求使用别名显示列名 +--5、查询商品信息所有列,要求商品颜色为红色,价格在300~600之间 + +Select top 1 GoodsName 商品名称,GoodsColor 商品颜色,GoodsMoney 商品价格, max(GoodsMoney) from GoodsInfo group by GoodsName,GoodsColor,GoodsMoney order by GoodsMoney Desc +Select TypeID, max(GoodsMoney)最高价格,min(GoodsMoney)最低价格,AVG(GoodsMoney)平均价格 from GoodsInfo group by TypeID +Select * from GoodsInfo where GoodsColor='红色' and GoodsMoney>=300 and GoodsMoney<=600 \ No newline at end of file -- Gitee