我有一行中的采购订单申请数据。要将它们导入我们的财务系统并生成PO,我会为每个行项目选择一个联合数据。我创建了一个视图,它一直很好用。昨天,我有一个没有提取一个PO的所有订单项。在研究它时,我采用了前5个行项目的代码,因为这是此请求中的项目数并运行代码。它并没有拉动一切。所以我为每个订单项添加了一个静态编号,这样我就可以看到它没有拉动,一切都显示出来了。 由于篇幅很长,我无法发布所有内容,但这有效
SELECT '5' AS lineitem,`f`.`DWDOCID` AS `a`
, DATE_FORMAT(CURDATE(), '%m/%d/%y') AS `B`
, `f`.`FIELD_9` AS `C`
, `f`.`VENDORCODE` AS `d`
, `f`.`EMPLOYEENUMBER` AS `e`
, `f`.`REMARKS` AS `f`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Family Enrichment Network'
END) AS `shiptoname`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '21 South Broad Street'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '6678 County Rd 32'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN '24 Cherry Street'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '150 Moeller St.'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN '35 Felters Rd.'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '287 Prospect St.'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '30 College St.'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '29 Fayette St.'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '117 Whig St.'
WHEN (`f`.`SHIPTO` = 'Owego') THEN '1277 Taylor Rd.'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN '12 Cooper St.'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN '1201 Union Center Maine Highway'
END) AS `address`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN ''
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN ''
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'PO Box 997'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN ''
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Building 16'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN ''
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN ''
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN ''
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN ''
WHEN (`f`.`SHIPTO` = 'Owego') THEN ''
WHEN (`f`.`SHIPTO` = 'Waverly') THEN ''
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Linnaeus West Elementary School, Classroom 15'
END) AS `address2`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Norwich, NY 13815'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Norwich, NY 13815'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Johnson City, NY 13790-0997'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Binghamton, NY 13904'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Binghamton, NY 13903'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Binghamton, NY 13905'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Binghamton, NY 13905'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Binghamton, NY 13901'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Newark Valley, NY 13811'
WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Owego, NY 13827'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Waverly, NY 14892'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Endicott, NY 13760'
END) AS `citystatezip`
, 'Best Way' AS `BestWay`
, DATE_FORMAT(`f`.`DATENEEDED`, '%m/%d/%y') AS `date_format(f.DATENEEDED,'%m/%d/%y')`
, (`f`.`Q5` * 0.01) AS `q5`
, `f`.`DES5` AS `DES5`
, (`f`.`UPRICE5` / 100) AS `f.UPRICE5/100`
, '0' AS `0`
, 0 AS `f.shipping/100`
, `f`.`DWDOCID` AS `DWDOCID`
, '0' AS `My_exp_1_0`
, '0' AS `My_exp_2_0`
, '0' AS `My_exp_3_0`
, `f`.`GLCODE5` AS `GLCODE`
, `f`.`ELEMENT5` AS `ELEMENT`
, ((`f`.`UPRICE5` / 100) * (`f`.`Q5` * 0.01)) AS `amount`
, 'm:\\nbush.jpg' AS `Y`
, DATE_FORMAT(`f`.`APPROVALDATE`, '%m/%d/%y') AS `Approvaldate`
, 'm:\\blank.jpg' AS `AA`
, REPLACE(LEFT(`f`.`VENDOR`, 20), '#N/A', '') AS `replace(left(``f``.``vendor``,20),'#N/A','')`
FROM `dwdata`.`purchase_orders` `f`
WHERE ((`f`.`DOCUMENT_TYPE` = 'REQUISITION FOR PURCHASE ORDER')
AND (`f`.`FIELD_9` = 'Executive Director Approved')
AND (`f`.`EXECUTIVEDIRECTORAPPROVED` = 'Approved')
AND (`f`.`FISCALOFFICERAPPROVED` = 'Approved')
AND (`f`.`PROGRAMDIRECTORAPPROVED` = 'Approved')
AND (`f`.`Q5` IS NOT NULL))
这不是
SELECT `f`.`DWDOCID` AS `a`
, DATE_FORMAT(CURDATE(), '%m/%d/%y') AS `B`
, `f`.`FIELD_9` AS `C`
, `f`.`VENDORCODE` AS `d`
, `f`.`EMPLOYEENUMBER` AS `e`
, `f`.`REMARKS` AS `f`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Family Enrichment Network'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Family Enrichment Network'
END) AS `shiptoname`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN '21 South Broad Street'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN '6678 County Rd 32'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN '24 Cherry Street'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN '150 Moeller St.'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN '35 Felters Rd.'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN '287 Prospect St.'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN '30 College St.'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN '29 Fayette St.'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN '117 Whig St.'
WHEN (`f`.`SHIPTO` = 'Owego') THEN '1277 Taylor Rd.'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN '12 Cooper St.'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN '1201 Union Center Maine Highway'
END) AS `address`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN ''
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN ''
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'PO Box 997'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN ''
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Building 16'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN ''
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN ''
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN ''
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN ''
WHEN (`f`.`SHIPTO` = 'Owego') THEN ''
WHEN (`f`.`SHIPTO` = 'Waverly') THEN ''
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Linnaeus West Elementary School, Classroom 15'
END) AS `address2`
, (CASE
WHEN (`f`.`SHIPTO` = 'Broad Street Norwich') THEN 'Norwich, NY 13815'
WHEN (`f`.`SHIPTO` = 'DCMO Boces') THEN 'Norwich, NY 13815'
WHEN (`f`.`SHIPTO` = 'Cherry Street') THEN 'Johnson City, NY 13790-0997'
WHEN (`f`.`SHIPTO` = 'Carlisle') THEN 'Binghamton, NY 13904'
WHEN (`f`.`SHIPTO` = 'Saratoga') THEN 'Binghamton, NY 13903'
WHEN (`f`.`SHIPTO` = 'Wilson Elementary School') THEN 'Binghamton, NY 13905'
WHEN (`f`.`SHIPTO` = 'Horrace Mann Elementary') THEN 'Binghamton, NY 13905'
WHEN (`f`.`SHIPTO` = 'Fayette Street') THEN 'Binghamton, NY 13901'
WHEN (`f`.`SHIPTO` = 'Newark Valley') THEN 'Newark Valley, NY 13811'
WHEN (`f`.`SHIPTO` = 'Owego') THEN 'Owego, NY 13827'
WHEN (`f`.`SHIPTO` = 'Waverly') THEN 'Waverly, NY 14892'
WHEN (`f`.`SHIPTO` = 'Charles F. Johnson') THEN 'Endicott, NY 13760'
END) AS `citystatezip`
, 'Best Way' AS `BestWay`
, DATE_FORMAT(`f`.`DATENEEDED`, '%m/%d/%y') AS `date_format(f.DATENEEDED,'%m/%d/%y')`
, (`f`.`Q5` * 0.01) AS `q5`
, `f`.`DES5` AS `DES5`
, (`f`.`UPRICE5` / 100) AS `f.UPRICE5/100`
, '0' AS `0`
, 0 AS `f.shipping/100`
, `f`.`DWDOCID` AS `DWDOCID`
, '0' AS `My_exp_1_0`
, '0' AS `My_exp_2_0`
, '0' AS `My_exp_3_0`
, `f`.`GLCODE5` AS `GLCODE`
, `f`.`ELEMENT5` AS `ELEMENT`
, ((`f`.`UPRICE5` / 100) * (`f`.`Q5` * 0.01)) AS `amount`
, 'm:\\nbush.jpg' AS `Y`
, DATE_FORMAT(`f`.`APPROVALDATE`, '%m/%d/%y') AS `Approvaldate`
, 'm:\\blank.jpg' AS `AA`
, REPLACE(LEFT(`f`.`VENDOR`, 20), '#N/A', '') AS `replace(left(``f``.``vendor``,20),'#N/A','')`
FROM `dwdata`.`purchase_orders` `f`
WHERE ((`f`.`DOCUMENT_TYPE` = 'REQUISITION FOR PURCHASE ORDER')
AND (`f`.`FIELD_9` = 'Executive Director Approved')
AND (`f`.`EXECUTIVEDIRECTORAPPROVED` = 'Approved')
AND (`f`.`FISCALOFFICERAPPROVED` = 'Approved')
AND (`f`.`PROGRAMDIRECTORAPPROVED` = 'Approved')
AND (`f`.`Q5` IS NOT NULL))
知道为什么不呢?除了订单项之外,它的代码完全相同。
答案 0 :(得分:0)
我明白了。我没有意识到联盟不会检索重复记录。如果填写PO的人做了正常人所做的事情,只说一个订单项的数量为2,另一个订单项的数量为3而不是只有2个唯一订单时数量为1的5个订单项它不会是一个问题。