SQL 问题修改

23 天前
 imyasON
求大佬看下怎么改,ai 问不出来。
执行会出现 ( 1054 - Unknown column 'ai.record_node_history' in 'field list'),
该字段再表里是有的,因为 groupBy 子查询导致的吗 ?


SELECT ai.form_id AS formId
FROM approval_info ai
LEFT JOIN approval_config ac
ON ai.form_id = ac.form_id
AND ai.process_progress = ac.approval_node
WHERE
ac.corp_id = 'dayReport'
AND ai.end_state = 0
AND ai.launch_time >= '2024-10-01'
AND ai.launch_time <= '2024-10-31'
AND ai.process_progress != 0
AND FIND_IN_SET('liuys', ac.current_node_approver) > 0
AND NOT EXISTS (
SELECT 1
FROM approval_record ar
WHERE ar.approval_info_id = ai.approval_info_id
AND ar.approver_node != ai.process_progress
AND ar.accessory_url != ai.object_id
AND ar.approver_user_id = 'liuys'
AND ar.approver_count = (
SELECT COUNT(*)
FROM (
-- 计算 record_node_history 中 process_progress 出现的次数
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ai.record_node_history, ',', numbers.n), ',', -1) AS node
FROM (
SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8
UNION ALL SELECT 9 UNION ALL SELECT 10
) numbers
WHERE CHAR_LENGTH(ai.record_node_history) - CHAR_LENGTH(REPLACE(ai.record_node_history, ',', '')) + 1 >= numbers.n
) AS temp
-- 比较 record_node_history 中的节点与当前 process_progress
WHERE temp.node = CAST(ai.process_progress AS CHAR)
)
)
ORDER BY ai.form_id
LIMIT 10 OFFSET 0;
1170 次点击
所在节点    数据库
5 条回复
mx3y
23 天前
SELECT ai.form_id AS formId
FROM approval_info ai
LEFT JOIN approval_config ac ON ai.form_id = ac.form_id AND ai.process_progress = ac.approval_node
WHERE ac.corp_id = 'dayReport'
AND ai.end_state = 0
AND ai.launch_time >= '2024-10-01'
AND ai.launch_time <= '2024-10-31'
AND ai.process_progress != 0
AND FIND_IN_SET('liuys', ac.current_node_approver) > 0
AND NOT EXISTS (
SELECT 1
FROM approval_record ar
WHERE ar.approval_info_id = ai.approval_info_id
AND ar.approver_node != ai.process_progress
AND ar.accessory_url != ai.object_id
AND ar.approver_user_id = 'liuys'
AND ar.approver_count = (
SELECT COUNT(*)
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ai.record_node_history, ',', numbers.n), ',', -1) AS node
FROM (
SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8
UNION ALL SELECT 9 UNION ALL SELECT 10
) numbers
WHERE CHAR_LENGTH(ai.record_node_history) - CHAR_LENGTH(REPLACE(ai.record_node_history, ',', '')) + 1 >= numbers.n
) AS temp
WHERE temp.node = CAST(ai.process_progress AS CHAR)
)
)
ORDER BY ai.form_id
LIMIT 10 OFFSET 0;
imyasON
23 天前
@mx3y #1 执行后和我一样的报错提示
wengyanbin
23 天前
还是给下表结构还有部分数据吧,纯看着没什么问题。
imyasON
22 天前
@wengyanbin #3 三张表贴到附言里了
wengyanbin
21 天前
@imyasON 再给点 mock 的数据。没数据玩不转

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1084530

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX