我有一个大数据库和4个表。我想拥有的是可用PN的数量以及每个LocVAR的已使用PN的数量。
我会尽力解释最好的情况,如果不清楚,请大喊大叫。
表格:
create table rot (
code int(10) primary key,
PN varchar(10) not null,
SN varchar(10) not null,
LocID int(10) not null);
insert into rot values (1,'T1','T1SN1','1');
insert into rot values (2,'A1','A1SN1','2');
insert into rot values (3,'J1','J1SN1','3');
insert into rot values (4,'A2','A2SN1','1');
insert into rot values (5,'J2','J2SN1','2');
insert into rot values (6,'A3','A3SN1','3');
insert into rot values (7,'J3','J3SN1','4');
insert into rot values (8,'T1','T1SN2','5');
insert into rot values (9,'A1','A1SN2','1');
insert into rot values (10,'J2','J2SN2','3');
insert into rot values (11,'J2','J2SN3','4');
insert into rot values (12,'A1','A1SN3','3');
insert into rot values (13,'J2','J2SN4','5');
create table loc(
LocID int(10) primary key,
LocVar varchar(10) not null);
insert into loc values (1,'AAA');
insert into loc values (2,'BBB');
insert into loc values (3,'CCC');
insert into loc values (4,'DDD');
insert into loc values (5,'EEE');
create table rotVAR (
code int(10) primary key,
PN varchar(10) not null,
PNVAR varchar(10) not null);
insert into rotVAR values (1,'A1', 'A1_la');
insert into rotVAR values (2,'A2','A2_la');
insert into rotVAR values (3,'A3','A3_la');
insert into rotVAR values (4,'J1','J1_la');
insert into rotVAR values (5,'J2','J2_la');
insert into rotVAR values (6,'J3','J3_la');
insert into rotVAR values (7,'T1','T1_la');
create table PNUsage2(
code int(10) primary key,
PN varchar(10) not null,
DatePN varchar(10) not null,
Usage1 varchar(10),
LocVar varchar(10) not null );
insert into PNUsage2 values (1,'A1', '2018-01-01','Yes','AAA' );
insert into PNUsage2 values (2,'A2','2018-01-07','Yes','AAA');
insert into PNUsage2 values (3,'A3','2018-01-06', 'No','BBB');
insert into PNUsage2 values (4,'J1','2018-01-05','Yes','BBB');
insert into PNUsage2 values (5,'J2','2018-01-04', 'No','DDD');
insert into PNUsage2 values (6,'J3','2018-01-03', 'Yes','DDD');
insert into PNUsage2 values (7,'T1','2018-01-02','No','DDD');
注意:表格腐烂-根据SN的数量对PN进行计数(因此A1为3,A2为1) 表PNUsage2仅计数为“是” 期望的结果是显示以下列: rot.PN |腐烂。数(PN)| loc.LocVar | rotVAR.PNVAR | PNUsage2.Usage1
我可以连接所有表,但无法两次使用count。