SELECT DISTINCT A.BEGIN_REPAIR_NO, A.PART_NO, A.CREATE_BY, B.EMPLOYEE_NAME AS CREATE_NAME, A.CREATE_TIME FROM TPMDATA.PICKING A LEFT JOIN TPMDATA.SAP_EMPLOYEE B ON A.CREATE_BY = B.EMPLOYEE_NO SELECT nvl(sum(A.CURRENT_QUANTITY),0) FROM TPMDATA.PICKING A LEFT JOIN TPMDATA.sys_part B ON A.PART_NO = B.PART_NO 将这俩条sql语句 合成一条
时间: 2024-02-14 10:35:23 浏览: 182
可以使用子查询将这两条 SQL 查询语句合并成一条:
SELECT DISTINCT
A.BEGIN_REPAIR_NO,
A.PART_NO,
A.CREATE_BY,
B.EMPLOYEE_NAME AS CREATE_NAME,
A.CREATE_TIME,
NVL((SELECT SUM(CURRENT_QUANTITY)
FROM TPMDATA.PICKING
LEFT JOIN TPMDATA.sys_part ON TPMDATA.PICKING.PART_NO = TPMDATA.sys_part.PART_NO
WHERE TPMDATA.PICKING.BEGIN_REPAIR_NO = A.BEGIN_REPAIR_NO AND TPMDATA.PICKING.PART_NO = A.PART_NO), 0) AS CURRENT_QUANTITY
FROM
TPMDATA.PICKING A
LEFT JOIN TPMDATA.SAP_EMPLOYEE B ON A.CREATE_BY = B.EMPLOYEE_NO;
这条语句将原本要查询的 SUM(CURRENT_QUANTITY) 作为子查询嵌入到了主查询中,并且增加了 WHERE 子句,以便查询对应的 BEGIN_REPAIR_NO 和 PART_NO。
相关问题
SELECT DISTINCT A.BEGIN_REPAIR_NO, A.PART_NO, A.CREATE_BY, B.EMPLOYEE_NAME AS CREATE_NAME, A.CREATE_TIME FROM TPMDATA.PICKING A LEFT JOIN TPMDATA.SAP_EMPLOYEE B ON A.CREATE_BY = B.EMPLOYEE_NO
这是一条 SQL 查询语句,用于查询 TPMDATA 数据库中 PICKING 表中不同的 BEGIN_REPAIR_NO、PART_NO、CREATE_BY 和对应的 CREATE_NAME、CREATE_TIME。其中使用了 LEFT JOIN 关键字,将 TPMDATA.PICKING 表中的 CREATE_BY 字段与 TPMDATA.SAP_EMPLOYEE 表中的 EMPLOYEE_NO 字段关联起来,以便查询对应的 CREATE_NAME。
阅读全文