123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- select contractid ,count(*)c from part_repertory group by contractid
- having count(*)>1
- select contractid ,count(*)c from part_repertory group by partCode,locationId,contractId,providerId,price
- having count(*)>1
- show create table part_repertory
- drop table part_repertory2
- CREATE TABLE `part_repertory3` (
- `id` int(11) NOT NULL COMMENT '主键',
- `pastureId` int(11) NOT NULL COMMENT '牧场主键',
- `partId` int(11) DEFAULT NULL COMMENT '设备主键',
- `partName` varchar(100) DEFAULT NULL,
- `partCode` varchar(100) DEFAULT NULL,
- `specification` varchar(100) DEFAULT NULL COMMENT '规格',
- `location` varchar(100) DEFAULT NULL COMMENT '位置',
- `locationId` int(11) NOT NULL,
- `reportery` decimal(10,2) DEFAULT NULL COMMENT '库存',
- `minRepertory` decimal(11,0) NOT NULL DEFAULT 0 COMMENT '最低库存',
- `maxRepertory` decimal(11,0) NOT NULL DEFAULT 10 COMMENT '最高库存',
- `contractId` bigint(50) NOT NULL,
- `providerId` int(11) DEFAULT NULL,
- `providerNames` varchar(100) DEFAULT NULL,
- `brand` varchar(100) DEFAULT NULL COMMENT '品牌',
- `brandId` int(11) NOT NULL,
- `unit` varchar(20) DEFAULT NULL COMMENT '单位',
- `price` decimal(15,5) NOT NULL COMMENT '单价',
- `enable` tinyint(4) DEFAULT NULL,
- `precontractId` varchar(50) DEFAULT NULL,
- PRIMARY KEY (`id`),
- index `pastureId` (`partCode`,`precontractId`,`locationId`),
- index `contractId` (`contractId`),
- index `partcode` (`partCode`,`locationId`,`contractId`,`providerId`,`price`)
- ) ENGINE=InnoDB AUTO_INCREMENT=587461 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC
- describe buydetail
- alter table buydetail modify column contractId bigint(50) ;
- describe checkpart
- alter table checkpart modify column contractId bigint(50) ;
- show index from part_repertory
- insert into part_repertory2
- alter table part_repertory add unique index (partCode,
- locationId,
- contractId,
- providerId,
- price)
- describe part_repertory
- select pr.partCode,
- pr.locationId,
- pr.contractId,
- pr.providerId,
- pr.price,
- pr.reportery from part_repertory pr
- join (
- select partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price
- having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- order by pr.partCode,
- pr.locationId,
- pr.contractId,
- pr.providerId,
- pr.price
- insert into part_repertory2
- (
- select pr.* from part_repertory pr
- join (
- select partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price
- having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- order by pr.partCode,
- pr.locationId,
- pr.contractId,
- pr.providerId,
- pr.price
- )
- describe contract
- describe part_repertory
- select pr.id, pr.partcode ,pr.contractId ,c.id ,c.partcode,c2.id,c2.partcode
- from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- select count(*)
- from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- delete from part_repertory3
- insert into part_repertory3
- (
- select distinct pr.*
- from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- )
- select t1.* from
- (
- select pr.id, pr.partcode ,pr.contractId ,c.id cid ,c.partcode ,c2.id c2id,c2.partcode
- from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- )t1 join
- (
- select pr.id
- from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- group by pr.id
- having count(*) >1
- )t2 on t1.id =t2.id
- update
- part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- set pr.contractId = c2.id
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- select contractid ,count(*)c from part_repertory group by contractid having count(*)>1
- show index from part_repertory
- alter table part_repertory add index(contractId)
- alter table part_repertory drop index contractId
- show create table part_repertory
- alter table part_repertory add UNIQUE index (`partCode`,`locationId`,`contractId`,`providerId`,`price`)
- select group_concat(id,',') from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- select * from part_repertory
- where instr ( (
- select group_concat(id,',') from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- ),id )
- select * from part_repertory where instr('123',id )
- delete pr from part_repertory pr
- left join contract c on c.id =pr.contractId
- left join contract c2 on c2.partcode = pr.partcode
- join bigcontract bc on bc.id =c2.bigid
- where pr.providerId = bc.providerId and pr.brandid =c2.brandid and pr.price =c2.price
- and c.partcode <>c2.partcode
- and pr.reportery <0
- alter table part_repertory add UNIQUE index (`partCode`,`locationId`,`contractId`,`providerId`,`price`)
- select pr.* from part_repertory pr
- join
- (select group_concat(id,',') gid ,partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price and
- instr (t.gid,pr,pr.id) >1
- CREATE TABLE `part_repertory5` (
- `id` int(11) NOT NULL COMMENT '主键',
- `pastureId` int(11) NOT NULL COMMENT '牧场主键',
- `partId` int(11) DEFAULT NULL COMMENT '设备主键',
- `partName` varchar(100) DEFAULT NULL,
- `partCode` varchar(100) DEFAULT NULL,
- `specification` varchar(100) DEFAULT NULL COMMENT '规格',
- `location` varchar(100) DEFAULT NULL COMMENT '位置',
- `locationId` int(11) NOT NULL,
- `reportery` decimal(10,2) DEFAULT NULL COMMENT '库存',
- `minRepertory` decimal(11,0) NOT NULL DEFAULT 0 COMMENT '最低库存',
- `maxRepertory` decimal(11,0) NOT NULL DEFAULT 10 COMMENT '最高库存',
- `contractId` bigint(50) NOT NULL,
- `providerId` int(11) DEFAULT NULL,
- `providerNames` varchar(100) DEFAULT NULL,
- `brand` varchar(100) DEFAULT NULL COMMENT '品牌',
- `brandId` int(11) NOT NULL,
- `unit` varchar(20) DEFAULT NULL COMMENT '单位',
- `price` decimal(15,5) NOT NULL COMMENT '单价',
- `enable` tinyint(4) DEFAULT NULL,
- `precontractId` varchar(50) DEFAULT NULL,
- PRIMARY KEY (`id`),
- index `pastureId` (`partCode`,`precontractId`,`locationId`),
- index `contractId` (`contractId`),
- index `partcode` (`partCode`,`locationId`,`contractId`,`providerId`,`price`)
- ) ENGINE=InnoDB AUTO_INCREMENT=587461 DEFAULT CHARSET=utf8 ROW_FORMAT=dynamic
- insert into part_repertory4 (
- select * from part_repertory where reportery <0
- )
- delete from part_repertory where reportery <0
- select * from part_repertory4
- insert into part_repertory4
- select pr.*
- from part_repertory pr
- join
- (select partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- select t2.ranking,pr.* from part_repertory pr join
- (
- select pr.id ,
- rank() over (partition by pr.partCode,
- pr.locationId,
- pr.contractId,
- pr.providerId,
- pr.price order by id) as Ranking
- from part_repertory pr
- join
- (select partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- )t2 on pr.id =t2.id
- where t2.Ranking >1
- delete pr from part_repertory pr join
- (
- select pr.id ,
- rank() over (partition by pr.partCode,
- pr.locationId,
- pr.contractId,
- pr.providerId,
- pr.price order by id) as Ranking
- from part_repertory pr
- join
- (select partCode,locationId,contractId,providerId,price from part_repertory group by partCode,locationId,contractId,providerId,price having count(*)>1
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- )t2 on pr.id =t2.id
- where t2.Ranking >1
- alter table part_repertory add UNIQUE index (`partCode`,`locationId`,`contractId`,`providerId`,`price`)
- show index from part_repertory
- alter table part_repertory drop index partcode
- update part_repertory pr join (
- select sum(reportery)c,partCode,locationId,contractId,providerId,price from part_repertory4
- where reportery >0
- group by partCode,locationId,contractId,providerId,price
- )t on
- pr.partCode= t.partCode and
- pr.locationId= t.locationId and
- pr.contractId= t.contractId and
- pr.providerId= t.providerId and
- pr.price= t.price
- set pr.reportery =pr.reportery+t.c
- select rank() over (partition by
- partCode,
- locationId,
- contractId,
- providerId,
- price order by id) as Ranking,partCode,locationId,contractId,providerId,price ,group_concat(id,',')
- from part_repertory4
- where reportery >0
- select * from part_repertory4 where reportery >0
- select * from part_repertory pr join (
- select t.* from (
- select
- rank() over (partition by
- partCode,
- locationId,
- contractId,
- providerId,
- price order by id) as Ranking,p.*
- from part_repertory4 p
- where reportery >0
- )t where t.ranking =2
- )t2 on
- pr.partCode= t2.partCode and
- pr.locationId= t2.locationId and
- pr.contractId= t2.contractId and
- pr.providerId= t2.providerId and
- pr.price= t2.price
- update part_repertory pr join (
- select t.* from (
- select
- rank() over (partition by
- partCode,
- locationId,
- contractId,
- providerId,
- price order by id) as Ranking,p.*
- from part_repertory4 p
- where reportery >0
- )t where t.ranking =2
- )t2 on
- pr.partCode= t2.partCode and
- pr.locationId= t2.locationId and
- pr.contractId= t2.contractId and
- pr.providerId= t2.providerId and
- pr.price= t2.price
- set pr.reportery =pr.reportery +t2.reportery
|