t5.sql 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. -- select count(*) from (
  2. select t.*,
  3. IFNULL(pr.`reportery`,0) reporteryQ
  4. from (
  5. SELECT
  6. CONCAT('uploads/thumbnail/',ep.`picpath`,'/',ep.`newpicname`) picpath,
  7. CONCAT('uploads/image/',ep.`picpath`,'/',ep.`newpicname`) srcpath,
  8. b.`brandName`,
  9. c.`id`,c.`brand`,c.`brandId`,c.`partCode`,c.`partId`,c.`partName`,c.`pastureId`,c.`pastureName`,
  10. c.`specification`,c.`unit`,
  11. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.`price`))) price
  12. FROM
  13. contract c
  14. LEFT JOIN brand b ON b.id = c.brandId
  15. LEFT JOIN bigcontract bc ON bc.id = c.bigId
  16. LEFT JOIN bigcontract bc2 ON bc2.contractCode = left(bc.contractCode,12)
  17. join pasture_bigcontract pbt on pbt.bigcontract_id =bc2.id
  18. LEFT JOIN parts ps ON ps.id = c.partId
  19. LEFT JOIN eq_pic ep ON ep.id = ps.picpath
  20. WHERE
  21. bc.`providerId` = '2808'
  22. AND c.enable = 1
  23. -- AND (bc.`stopTime`>=DATE_FORMAT(NOW(),'%Y-%m-%d') and bc.statue=1 and bc.SHStatus = 7 )
  24. -- AND if(''='' ,bc.SHStatus = 7,c.`partCode` = '' OR c.`partName` ='' OR c.`specification` ='' )
  25. and (bc.pastureId='631' or '631'='' or pbt.pasture_id = '631' )
  26. -- limit 10
  27. )t
  28. left join
  29. (
  30. select reportery,contractId from part_repertory pr2 left join warehouse w on pr2.locationId =w.id
  31. where pr2.pastureId ='631' or (pr2.pastureId =18 and w.pastureId = '631')
  32. ) pr ON pr.`contractId` = t.`id`
  33. )a