我试图得到数据库中计数产品的总和,当我使用嵌套求和语句的结果是错误的一个记录是不重复的。我的代码:
INSERT OR IGNORE INTO COUNT_REPORT
(
PRODUCT_CODE,
BRANCH,
WAREHOUSE,
PRODUCT_NAME,
CURRENT_COUNT,
PREVIOUS_COUNT,
DIFFERENCE,
STATE,
DATE,
PRICE
)
SELECT
PROD_CODE,
(SELECT UNVAN FROM BRANCHES WHERE SUBE_KODU = BRANCH_CODE),
(SELECT DEPO_ISMI FROM WAREHOUSES WHERE DEPO_KODU = WARE_CODE),
(SELECT STOK_ADI FROM PRODUCT_DETAILS WHERE STOK_KODU = PROD_CODE),
(SELECT SUM(QUANTITY) FROM FINAL_DATA GROUP BY PROD_CODE),
PREVIOUS_COUNT,
DIFFERENCE,
STATE,
TASK_DATE,
PRICE
FROM FINAL_DATA
WHERE TASK_ID = ?
我尝试使用DISTINCT和GROUP BY以及另一个嵌套语句。我期望查询返回重复记录中数量的总和。
1条答案
按热度按时间jogvjijk1#
问题是在同一个表中执行两次子查询,因此:
我使用了:
它现在正按预期工作。