求句SQL,或者存储过程

寂小魔 寂小魔 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

create table WareHouseProperty
(
ID int(11) not null auto_increment comment 'ID',
WIID int(4) comment '仓库信息ID',
RackID varchar(2) comment '货架号:用A,B,C表示,一律用大写',
Layer int(1) comment '第几层',
Number int(2) comment '该层的第几个格子:01~99',
BarCode varchar(20) comment '条形码',
primary key (ID)
);
-- 测试数据
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',1,'1','14-A1A01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',1,'2','14-A1A02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',1,'3','14-A1A03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',2,'1','14-A2A01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',2,'2','14-A2A02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',2,'3','14-A2A03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',3,'1','14-A3A01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',3,'2','14-A3A02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'A',3,'3','14-A3A03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',1,'1','14-B1B01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',1,'2','14-B1B02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',1,'3','14-B1B03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',1,'4','14-B1B04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',2,'1','14-B2B01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',2,'2','14-B2B02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',2,'3','14-B2B03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',2,'4','14-B2B04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',3,'1','14-B3B01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',3,'2','14-B3B02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',3,'3','14-B3B03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',3,'4','14-B3B04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',4,'1','14-B4B01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',4,'2','14-B4B02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',4,'3','14-B4B03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'B',4,'4','14-B4B04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',1,'1','14-C1C01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',1,'3','14-C1C03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',1,'4','14-C1C04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',1,'5','14-C1C05');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',2,'1','14-C2C01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',2,'2','14-C2C02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',2,'3','14-C2C03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',2,'4','14-C2C04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',2,'5','14-C2C05');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',3,'1','14-C3C01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',3,'2','14-C3C02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',3,'3','14-C3C03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',3,'4','14-C3C04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',3,'5','14-C3C05');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',4,'1','14-C4C01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',4,'2','14-C4C02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',4,'3','14-C4C03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',4,'4','14-C4C04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',4,'5','14-C4C05');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',5,'1','14-C5C01');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',5,'2','14-C5C02');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',5,'3','14-C5C03');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',5,'4','14-C5C04');
insert into WareHouseProperty (WIID,RackID,Layer,Number,BarCode) values (14,'C',5,'5','14-C5C05');


-- 希望查询的结果这样
-- RackID Layer Number
-- A 3 3
-- B 4 4
-- C 5 5
-- 因为数据可能会有不连续,不能取他的最大值。
...全文
评论 6
收藏 已收藏
分享
返回顶部
寂小魔
MySQL 57,062 成员 56,759 内容