纠错 select COALESCE(ooc.second_amount,1) /COALESCE(ooc.unit_quantity,1) as cc from ods.ods_durian_loading_task odlt left join ods.ods_durian_loading_sku_item odlsi on odlsi.plan_id=odlt.plan_id left join ods.ods_oms_commodity ooc on ooc.id=odlsi.commodity_id;
时间: 2024-02-23 09:59:53 浏览: 133
这个SQL语句中的COALESCE函数参数看起来是正确的,但是在除法运算符之前使用了不必要的空格。请尝试修改查询,将除法运算符和其前面的空格删除,如下所示:
```
select COALESCE(ooc.second_amount, 1) / COALESCE(ooc.unit_quantity, 1) as cc
from ods.ods_durian_loading_task odlt
left join ods.ods_durian_loading_sku_item odlsi on odlsi.plan_id = odlt.plan_id
left join ods.ods_oms_commodity ooc on ooc.id = odlsi.commodity_id;
```
如果您仍然遇到问题,请提供更多上下文或错误信息。
相关问题
MYSQL 运行失败;SELECT COALESCE(storage_in.in_date, storage_out.out_date) AS date, COALESCE(storage_in.product_name, storage_out.product_name) AS product_name, IFNULL(storage_in.quantity,0) AS IN_, IFNULL(storage_out.quantity,0) AS OUT_, SUM(IFNULL(storage_in.quantity,0) - IFNULL(storage_out.quantity,0)) OVER (PARTITION BY COALESCE(storage_in.in_date,storage_out.out_date), COALESCE(storage_in.product_name,storage_out.product_name) ORDER BY COALESCE(storage_in.in_date, storage_out.out_date)) AS END_ FROM storage_in FULL OUTER JOIN storage_out ON storage_in.product_name=storage_out.product_name AND storage_in.in_date = storage_out.out_date ORDER BY 1,2;
这是一个 SQL 查询语句,用于从两个表中获取产品进出库存信息,并计算每个产品在每个日期的总库存。其中使用了 COALESCE 函数来处理空值,IFNULL 函数来处理 NULL 值。JOIN 条件是产品名称和日期相等,使用了 FULL OUTER JOIN 来保证左右两个表都包含在结果中。最后使用了 OVER 子句来计算每个产品在每个日期的总库存。
从语法上看,这个 SQL 查询语句是正确的,但是可能会受到 MySQL 版本的限制。您可以检查一下 MySQL 的版本以及运行失败的具体原因,然后进行调整。
SELECT f.PAR_FAULT_CODE AS "parFaultCode", (SELECT t.FAULT_NAME FROM FAULT_TYPE t WHERE f.PAR_FAULT_CODE = t.FAULT_CODE) AS "faultName", COALESCE( r.REPORT_DEPT_CODE, 'N/A' ) AS "reportDeptCode", COUNT( r.REPORT_DEPT_CODE ) AS "report", COUNT(*) AS "reportCount" FROM FAULT_TYPE f LEFT JOIN FAULT_REPORT r ON f.FAULT_CODE = r.FAULT_CODE GROUP BY f.PAR_FAULT_CODE, f.FAULT_NAME, COALESCE( r.REPORT_DEPT_CODE, 'N/A' ), f.FAULT_CODE ORDER BY f.PAR_FAULT_CODE, f.FAULT_NAME按parfaultcode的report的和加到一起放到reportCount字段怎么修改
可以使用以下SQL语句来实现:
```
SELECT f.PAR_FAULT_CODE AS "parFaultCode",
(SELECT t.FAULT_NAME FROM FAULT_TYPE t WHERE f.PAR_FAULT_CODE = t.FAULT_CODE) AS "faultName",
COALESCE(r.REPORT_DEPT_CODE, 'N/A') AS "reportDeptCode",
COUNT(r.REPORT_DEPT_CODE) AS "report",
SUM(COUNT(r.REPORT_DEPT_CODE)) OVER (PARTITION BY f.PAR_FAULT_CODE) AS "reportCount"
FROM FAULT_TYPE f
LEFT JOIN FAULT_REPORT r ON f.FAULT_CODE = r.FAULT_CODE
GROUP BY f.PAR_FAULT_CODE, f.FAULT_NAME, COALESCE(r.REPORT_DEPT_CODE, 'N/A'), f.FAULT_CODE
ORDER BY f.PAR_FAULT_CODE, f.FAULT_NAME
```
这里使用了窗口函数 `SUM`,对每个 `parFaultCode` 分组的 `report` 字段求和并放到 `reportCount` 字段中。
阅读全文