当前位置:网站首页>MySQL uses the where condition to find strange results: solve
MySQL uses the where condition to find strange results: solve
2022-06-25 05:49:00 【CSDN Q & A】
The phenomenon and background of the problem :
I combine queries with multiple tables , Finally, it is wrapped with a table , Named query where group_status='7', But the result is group_status='9', Super weird , I've never seen anything like this , Can't explain !
Problem related code , Do not paste screenshots

Source code :
SELECT group_status,a12.* FROM (
SELECT CASE WHEN a11.group_id IS NOT NULL THEN a11.group_id ELSE concat(a11.cycle, a11.dept_id) END id, a11.cycle, a11.dept_id, a11.parent_id, a11.dept_name, a11.dept_long_name, a11.group_id, a11.manager, a11.do_time_begin, a11.do_time_end, a11.do_times, a11.cnt_dept, a11.cnt, a11.je, a11.cnt_gets, a11.je_gets, a11.left_full, a11.left_poor, a11.remain, a11.group_checked_je, eff_get_fp_cnt, all_get_fp_cnt,
CASE WHEN group_checked_je >= je THEN '1'
WHEN checked_cnt > 0 THEN '1'
WHEN a11.je_gets >= je THEN '7'
WHEN a11.je_gets < je THEN '8'
WHEN a11.group_id IS NULL THEN '9' END group_status,
a11.can_gets_cnt FROM (SELECT a10.cycle, a10.dept_id, a10.parent_id, a10.dept_name, a10.dept_long_name, a10.group_id, a10.manager, a10.do_time_begin, a10.do_time_end, a10.do_times, count(0) cnt_dept, sum(CASE WHEN a10.bxed0 > 0 THEN 1 ELSE 0 END) cnt, sum(a10.bxed0) je, sum(CASE WHEN a10.bxed0 > 0 AND a10.je_need = 0 THEN 1 ELSE 0 END) cnt_gets, sum(user_je_eff) je_gets, sum(CASE WHEN a10.bxed0 > 0 AND a10.je_need > 0 AND a10.user_left_fp_je >= a10.je_need THEN 1 ELSE 0 END) left_full, sum(CASE WHEN a10.bxed0 > 0 AND a10.je_need > 0 AND a10.user_left_fp_je < a10.je_need THEN 1 ELSE 0 END) left_poor, sum(CASE WHEN a10.je_need > 0 THEN 1 ELSE 0 END) remain, sum(a10.user_checked_je) group_checked_je, sum(a10.eff_get_fp_cnt) eff_get_fp_cnt, sum(a10.all_get_fp_cnt) all_get_fp_cnt, sum(a10.checked_cnt) checked_cnt, sum(a10.can_gets_cnt) can_gets_cnt FROM (SELECT a9.cycle, a9.dept_id, a9.parent_id, a9.dept_name, a9.dept_long_name, a9.user_id, a9.login_name, a9.user_name, a9.bxed, a9.bxed0, a9.group_id, a9.manager, a9.do_time_begin, a9.do_time_end, a9.do_times, a9.user_je_eff, a9.user_je_exp, a9.user_checked_je, a9.eff_get_fp_cnt, a9.all_get_fp_cnt, a9.checked_cnt, ifnull(sum(b9.jshjxx), 0) user_left_fp_je, CASE WHEN sum(b9.jshjxx) = NULL THEN 0 ELSE count(b9.id) END user_left_fp_cnt, CASE WHEN a9.bxed0 <= 0 THEN 0 WHEN a9.bxed0 > 0 AND a9.user_je_eff >= a9.bxed0 THEN 0 ELSE a9.bxed0 - a9.user_je_eff END je_need, CASE WHEN (CASE WHEN a9.bxed0 <= 0 THEN 0 WHEN a9.bxed0 > 0 AND a9.user_je_eff >= a9.bxed0 THEN 0 ELSE a9.bxed0 - a9.user_je_eff END) > 0 AND (ifnull(sum(b9.jshjxx), 0)) > 0 THEN 1 ELSE 0 END can_gets_cnt FROM (SELECT a8.cycle, a8.dept_id, a8.parent_id, a8.dept_name, a8.dept_long_name, a8.user_id, a8.login_name, a8.user_name, a8.bxed, a8.group_id, a8.manager, a8.do_time_begin, a8.do_time_end, a8.do_times, a8.bxed0, sum(CASE WHEN a8.check_status <> '-1' THEN a8.jshjxx ELSE 0 END) user_je_eff, sum(CASE WHEN a8.check_status = '-1' THEN a8.jshjxx ELSE 0 END) user_je_exp, sum(CASE WHEN a8.check_status = '1' THEN a8.jshjxx ELSE 0 END) user_checked_je, sum(CASE WHEN a8.check_status <> '-1' THEN 1 ELSE 0 END) eff_get_fp_cnt, sum(CASE WHEN a8.check_status IS NOT NULL THEN 1 ELSE 0 END) all_get_fp_cnt, sum(CASE WHEN a8.check_status IS NOT NULL AND check_status = '1' THEN 1 ELSE 0 END) checked_cnt FROM (SELECT a7.cycle, a7.dept_id, a7.parent_id, a7.dept_name, a7.dept_long_name, a7.user_id, a7.login_name, a7.user_name, a7.bxed, a7.group_id, a7.manager, a7.do_time_begin, a7.do_time_end, a7.do_times, a7.inv_id, a7.check_status, b7.jshjxx, a7.bxed0 FROM (SELECT a6.cycle, a6.dept_id, a6.parent_id, a6.dept_name, a6.dept_long_name, a6.user_id, a6.login_name, a6.user_name, a6.bxed, a6.group_id, a6.manager, a6.do_time_begin, a6.do_time_end, a6.do_times, b6.inv_id, b6.status check_status, a6.bxed0 FROM (SELECT a5.cycle, a5.dept_id, a5.parent_id, a5.dept_name, a5.dept_long_name, a5.user_id, a5.login_name, a5.user_name, a5.bxed, CASE WHEN b5.bxed0 IS NULL THEN a5.bxed WHEN b5.bxed0 = 0 THEN 0 ELSE a5.bxed END bxed0, a5.group_id, a5.manager, a5.do_time_begin, a5.do_time_end, a5.do_times, b5.id igu_id FROM (SELECT a4.cycle, a4.dept_id, a4.parent_id, a4.dept_name, a4.dept_long_name, a4.user_id, a4.login_name, a4.user_name, a4.bxed, b4.id group_id, b4.manager, b4.do_time_begin, b4.do_time_end, b4.do_times FROM (SELECT a3.cycle, a3.dept_id, a3.parent_id, a3.dept_name, a3.dept_long_name, a3.user_id, a3.login_name, a3.user_name, sum(a3.bxed) bxed FROM (SELECT a2.cycle, a2.dept_id, a2.parent_id, a2.dept_name, a2.dept_long_name, a2.user_id, a2.login_name, a2.user_name, b2.bxed FROM (SELECT a1.cycle, a1.dept_id, a1.parent_id, a1.dept_name, a1.dept_long_name, a1.user_id, a1.login_name, a1.user_name, b1.post_id FROM (SELECT '2022-01' cycle, a.dept_id, a.parent_id, a.dept_name, a.leader dept_long_name, b.user_id, b.login_name, b.user_name FROM sys_dept a LEFT JOIN sys_user AS b ON a.dept_id = b.dept_id WHERE a.status = '0' AND b.status = '0' AND a.del_flag = '0' AND b.del_flag = '0') a1 LEFT JOIN sys_user_post b1 ON a1.user_id = b1.user_id) a2 LEFT JOIN sys_post b2 ON a2.post_id = b2.post_id WHERE b2.status = '0') a3 GROUP BY a3.cycle, a3.dept_id, a3.dept_name, a3.dept_long_name, a3.user_id, a3.login_name, a3.user_name) a4 LEFT JOIN invoice_gets_group b4 ON a4.cycle = b4.cycle AND a4.dept_id = b4.dept_id) a5 LEFT JOIN invoice_gets_user b5 ON a5.group_id = b5.group_id AND a5.login_name = b5.login_name) a6 LEFT JOIN invoice_gets_user_list b6 ON a6.igu_id = b6.igu_id) a7 LEFT JOIN invoice b7 ON a7.inv_id = b7.id) a8 GROUP BY a8.cycle, a8.dept_id, a8.parent_id, a8.dept_name, a8.dept_long_name, a8.user_id, a8.login_name, a8.user_name, a8.bxed, a8.group_id, a8.manager, a8.do_time_begin, a8.do_time_end, a8.do_times, a8.bxed0) a9 LEFT JOIN invoice b9 ON a9.login_name = b9.user_name AND b9.status = '1' AND b9.kprq LIKE concat(substr('2022-01', 1, 4), '%') GROUP BY a9.cycle, a9.dept_id, a9.parent_id, a9.dept_name, a9.dept_long_name, a9.user_id, a9.login_name, a9.user_name, a9.bxed, a9.bxed0, a9.group_id, a9.manager, a9.do_time_begin, a9.do_time_end, a9.do_times, a9.user_je_eff, a9.user_je_exp) a10 GROUP BY a10.cycle, a10.dept_id, a10.parent_id, a10.dept_name, a10.dept_long_name, a10.group_id, a10.manager, a10.do_time_begin, a10.do_time_end, a10.do_times) a11
) a12
WHERE cycle = '2022-01'
AND a12.group_status = '7' ;
Operation results and error reporting contents :
The query condition is 7, It turns out that 9
My solution ideas and tried methods
What I want to achieve
Why does this happen ? solve
Take the answer :
Displayed in the first column group_status Not at all where Conditions correspond to a12. group_status Value , There should be another column behind it group_status.
边栏推荐
- UVA816 Abbott’s Revenge
- Uva1103 ancient pictograph recognition
- Dynamic programming example 2 leetcode62 unique paths
- [pan Wai 1] Huawei computer test
- Dynamic programming example 1 leetcode 322 coin change
- [JS basic review] scope, this, closure
- A method of automatic continuation of previous tables in word table
- CSDN cerebral palsy bug has wasted nearly two hours of hard work
- Fundamentals of C language
- [untitled]
猜你喜欢

16 application problem solving

2.20 learning content

How to add an external header file in vs?
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
MySQL transaction learning notes (I) first encounter

Get the first letter of Chinese phonetic alphabet in Excel and capitalize it

Interface learning

What is the use of the subprocess module

Uva1103 ancient pictograph recognition

Use of MySQL variables
随机推荐
Kubevela v1.2 release: the graphical operation console velaux you want is finally here!
Design of IM login server and message server
Vscode voice notes to enrich information (Part 1)
Deep learning non local neural networks
Ethernet
JSON Library Tutorial from scratch (I): starting to learn and organize notes
Go Methods and Interfaces
Instant messaging project (I)
Mirror image of binary tree
1.6.3 use tcpdump to observe DNS communication process
Common cluster deployment schemes in redis
First blog
Transformations of pytorch torch torch vision
SAP ui5 Application Development Tutorial Part 30 - parameter transfer in the routing process of SAP ui5
Use of pytorch tensorboard
Tutorial 35 of SAP ui5 application development - how to deploy locally developed SAP ui5 applications to ABAP server for trial reading
Simple student management system
Stack and Queue
Technology Review: what is the evolution route of container technology? What imagination space is there in the future?
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications