求句SQL,或者存储过程

寂小魔 2012-09-08 12:04:50

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
-- 因为数据可能会有不连续,不能取他的最大值。
...全文
84 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2012-09-08
  • 打赏
  • 举报
回复
你的结果是根据什么来的? 详细描述一下以免别人来猜。
寂小魔 2012-09-08
  • 打赏
  • 举报
回复
3q3q3q3q
ACMAIN_CHM 2012-09-08
  • 打赏
  • 举报
回复
mysql> select RackID,
-> count(distinct Layer) as Layer,
-> count(distinct Number) as Number
-> from WareHouseProperty
-> group by RackID;
+--------+-------+--------+
| RackID | Layer | Number |
+--------+-------+--------+
| A | 3 | 3 |
| B | 4 | 4 |
| C | 5 | 5 |
+--------+-------+--------+
3 rows in set (0.00 sec)

mysql>
寂小魔 2012-09-08
  • 打赏
  • 举报
回复
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)
);
-- 查询条件是 根据wiid来的
-- 查询结果是 某仓库 的 货架 有多少层 这层有少个格子(其中某层格子数最多的)
寂小魔 2012-09-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

引用 1 楼 的回复:

你的结果是根据什么来的? 详细描述一下以免别人来猜。

结果 是 rackid 不重复 layer 有多少个不相同的数 Number 有多少个相同的数
[/Quote]
都是不相同的 , 是针对 rackid来说的。
寂小魔 2012-09-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你的结果是根据什么来的? 详细描述一下以免别人来猜。
[/Quote]
结果 是 rackid 不重复 layer 有多少个不相同的数 Number 有多少个相同的数

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧