0

私は、これら2つのクエリを組み合わせて、機器を所有しているPIが誰であるかを判断しようとしています(> $ 100,000の値)。私には、1つのPIが所有する100kを超えるすべての機器を見つける能力があります。また、すべてのPIを表示することもできます。これらの2つのクエリを組み合わせることができません。WHEREサブクエリとEXISTサブクエリを試してみました。クエリ#2でPIが存在するすべての機器(PI所有者と一致)を見つけられるようにしたい。

特定のPIの機器を見つけるためのクエリ#1

select Account_No,Inventory_No,Building_No,Room_No,CDDEPT,Location,Normalized_MFG,Manufacturer_Name,Normalized_Model,Name,Serial_Code,CONCAT( '$', FORMAT( Cost, 2 ) ) as Cost, Equipment_Inventory_Normalized.Active 
from Temp_Equipment_Inventory.Equipment_Inventory_Normalized, `paul`.`ROOM`, `paul`.`BLDG`, `paul`.`LABORATORY`, `paul`.`PERSON` 
where (`PERSON`.`ID` = `LABORATORY`.`PI_ID` OR `PERSON`.`ID` = `LABORATORY`.`SUPV_ID`) 
AND `LABORATORY`.`RM_ID` = `ROOM`.`ID` 
AND `LABORATORY`.`ACTIVE` = '1' 
AND `ROOM`.`BLDG_ID` = `BLDG`.`ID` 
AND ((
`BLDG`.`BLDGNUM` = Equipment_Inventory_Normalized.Building_No 
AND Equipment_Inventory_Normalized.Actual_Building IS NULL 
AND (`BLDG`.`BLDGNUM` != '1023' AND `LABORATORY`.`OTHER_LEVEL` != '1' AND `ROOM`.`RMNUM` != '0199')
)OR (
`BLDG`.`BLDGNUM` = Equipment_Inventory_Normalized.Actual_Building AND 
(`BLDG`.`BLDGNUM` != '1023' AND `LABORATORY`.`OTHER_LEVEL` != '1' AND `ROOM`.`RMNUM` != '0199')
)) 
AND ((
`ROOM`.`RMNUM` = Equipment_Inventory_Normalized.Room_No 
AND Equipment_Inventory_Normalized.Actual_Room IS NULL
)OR (
`ROOM`.`RMNUM` = Equipment_Inventory_Normalized.Actual_Room
)) 
AND Equipment_Inventory_Normalized.Active !=0 
AND SurplusPending != '1'
AND Cost >= 100000 
AND `PERSON`.`CANNUM`='810010787'

すべてのPIを見つけるクエリ2

select distinct i.CAN
from CGWarehouse.CCGV10WC w
inner join CGWarehouse.CCGV10IC i
on w.PROJECT_NUMBER=i.SPONSORED_PROJECT
and w.SEQUENCE_NUMBER=i.PROJECT_SEQUENCE
where w.STATUS='A'
and i.PRIN_INVEST_CODE='Y'
and i.DEL_CODE!='Y'
and i.CAN IS NOT NULL
4

1 に答える 1

2

INWHERE 句でキーワードを探しているのではないでしょうか?

申し訳ありませんが、クエリの書式設定を少し整理する必要がありました...それは私の OCD のようなものです:

SELECT
    Account_No,
    Inventory_No,
    Building_No,
    Room_No,
    CDDEPT,
    Location,
    Normalized_MFG,
    Manufacturer_Name,
    Normalized_Model,
    Name,
    Serial_Code,
    CONCAT('$', FORMAT( Cost, 2 )) AS Cost,
    Equipment_Inventory_Normalized.Active
FROM
    Temp_Equipment_Inventory.Equipment_Inventory_Normalized a,
    `paul`.`ROOM`,
    `paul`.`BLDG`,
    `paul`.`LABORATORY`,
    `paul`.`PERSON` 
WHERE
    (`PERSON`.`ID` = `LABORATORY`.`PI_ID` OR `PERSON`.`ID` = `LABORATORY`.`SUPV_ID`) 
    AND `LABORATORY`.`RM_ID` = `ROOM`.`ID` 
    AND `LABORATORY`.`ACTIVE` = '1' 
    AND `ROOM`.`BLDG_ID` = `BLDG`.`ID` 
    AND (
        (
            `BLDG`.`BLDGNUM` = Equipment_Inventory_Normalized.Building_No 
            AND Equipment_Inventory_Normalized.Actual_Building IS NULL 
            AND `BLDG`.`BLDGNUM` != '1023'
            AND `LABORATORY`.`OTHER_LEVEL` != '1'
            AND `ROOM`.`RMNUM` != '0199'
        ) OR (
            `BLDG`.`BLDGNUM` = Equipment_Inventory_Normalized.Actual_Building
            AND `BLDG`.`BLDGNUM` != '1023'
            AND `LABORATORY`.`OTHER_LEVEL` != '1'
            AND `ROOM`.`RMNUM` != '0199'
        )
    ) 
    AND (
        (
            `ROOM`.`RMNUM` = Equipment_Inventory_Normalized.Room_No 
            AND Equipment_Inventory_Normalized.Actual_Room IS NULL
        ) OR (
            `ROOM`.`RMNUM` = Equipment_Inventory_Normalized.Actual_Room
        )
    ) 
    AND Equipment_Inventory_Normalized.Active !=0 
    AND SurplusPending != '1'
    AND Cost >= 100000 
    AND `PERSON`.`CANNUM` IN ( /* this assumes that the `PERSON`.`CANNUM` column matches up with the CGWarehouse.CCGV10IC.CAN column */
        SELECT DISTINCT i.CAN
        FROM
            CGWarehouse.CCGV10WC w
            INNER JOIN CGWarehouse.CCGV10IC i ON w.PROJECT_NUMBER=i.SPONSORED_PROJECT AND w.SEQUENCE_NUMBER=i.PROJECT_SEQUENCE
        WHERE
            w.STATUS='A'
            AND i.PRIN_INVEST_CODE='Y'
            AND i.DEL_CODE!='Y'
            AND i.CAN IS NOT NULL
    )
于 2012-05-08T14:36:16.133 に答える