您的查询语句中存在一个错误。CASE 表达式后面的逗号 , 导致了 ORA-00936: missing expression 错误。
请将以下部分:
case when uu.original_order is not null or uu.original_order != '' then uu.original_order else u.work_order_name end as workorder,
修改为:
case when uu.original_order is not null and uu.original_order <> '' then uu.original_order else u.work_order_name end as workorder,
修改后的查询语句如下所示:
SELECT
t.FINAL_CHECK_LEVEL,
COUNT(*) AS level_count,
ROUND((COUNT(*) / total.total_count), 3) * 100 AS percentage,
case when uu.original_order is not null and uu.original_order <> '' then uu.original_order else u.work_order_name end as workorder
FROM
UDT_FINAL_TEST_DATA t
LEFT JOIN TM_UNIT u ON u.name = t.unit_name
LEFT JOIN UDA_UNIT uu ON u.id = uu.id,
(
SELECT COUNT(*) AS total_count
FROM UDT_FINAL_TEST_DATA
WHERE 1=1
AND FINAL_CHECK_LINE='M1U1'
{ and FINAL_CHECK_LINE in(:check_line)}
AND create_time >= to_date(:'2024-03-18 14:26','yyyy-mm-dd hh24:mi:ss')
AND create_time < to_date(:'2024-03-19 20:26', 'yyyy-mm-dd hh24:mi:ss')
) total
WHERE 1=1
AND t.FINAL_CHECK_LINE='M1U1'
AND t.create_time >= to_date(:'2024-03-18 14:26','yyyy-mm-dd hh24:mi:ss')
AND t.create_time < to_date(:'2024-03-19 20:26', 'yyyy-mm-dd hh24:mi:ss')
GROUP BY
t.FINAL_CHECK_LEVEL, total.total_count, case when uu.original_order is not null and uu.original_order <> '' then uu.original_order else u.work_order_name end;
这样就修复了语法错误,并且查询结果中的百分比将会保留三位小数。请注意,您需要根据实际情况修改其他部分的参数值和筛选条件。
内容由零声教学AI助手提供,问题来源于学员提问




