我有一个表,其中可能的值是null,0(不好),1(好)和3(不/适用)。我必须严格按照顺序只选择null和等于1的值。我的疑问太长了。你能帮我把它弄短一点吗?
create table cv.cv_interview_status
(
id int auto_increment
primary key,
type varchar(255) not null,
date varchar(255) not null,
issue varchar(255) not null,
recruiter varchar(255) not null,
department varchar(255) not null,
position varchar(255) not null,
feedback_department tinyint null,
contacted_hr tinyint null,
office_interview tinyint null,
department_testing tinyint null,
department_acceptance tinyint null,
add_cv tinyint null,
psychological_test tinyint null,
department_interview tinyint null,
accepted_not_accepted tinyint null,
salary_request_to_ceo tinyint null,
ceo_feedback tinyint null,
salary_offer tinyint null,
accept_salary_offer tinyint null,
hr_documentation tinyint null,
hr_legal_requirements tinyint null,
date_created datetime default CURRENT_TIMESTAMP not null
);
SELECT *
FROM cv_interview_status
WHERE 1
AND (
(`feedback_department` IS NULL)
OR
(
`feedback_department` = 1
AND `contacted_hr` IS NULL
AND `office_interview` IS NULL
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` IS NULL
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` = 1
AND `office_interview` = 1
AND `department_testing` IS NULL
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` IS NULL
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` IS NULL
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` IS NULL
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` IS NULL
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` IS NULL
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` IS NULL
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` IS NULL
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer`IS NULL
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer` = 1
AND `accept_salary_offer` IS NULL
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
OR
(
`feedback_department` = 1
AND `contacted_hr` =1
AND `office_interview` = 1
AND `department_testing` = 1
AND `department_acceptance` = 1
AND `add_cv` = 1
AND `psychological_test` = 1
AND `department_interview` = 1
AND `accepted_not_accepted` = 1
AND `salary_request_to_ceo` = 1
AND `ceo_feedback` = 1
AND `salary_offer` = 1
AND `accept_salary_offer` = 1
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
);
这个表的过滤器工作得很好,但是查询太长了,你能给予建议我如何重构它吗?
解决方案:
SELECT
*
FROM
cv_interview_status
WHERE
( `feedback_department` IS NULL )
OR (
`feedback_department` = 1
AND (
( IFNULL( `contacted_hr`, 1 )
* IFNULL( `office_interview`, 1 )
* IFNULL( `department_testing`, 1 )
* IFNULL( `department_acceptance`, 1 )
* IFNULL( `add_cv`, 1 )
* IFNULL( `psychological_test`, 1 )
* IFNULL( `department_interview`, 1 )
* IFNULL( `accepted_not_accepted`, 1 )
* IFNULL( `salary_request_to_ceo`, 1 )
* IFNULL( `ceo_feedback`, 1 )
* IFNULL( `salary_offer`, 1 )
* IFNULL( `accept_salary_offer`, 1 )
) = 1 )
AND `hr_documentation` IS NULL
AND `hr_legal_requirements` IS NULL
)
3条答案
按热度按时间vohkndzv1#
我需要的查询只选择值1(确定)和空,但你查询选择和值0(不确定)-奥尔加
只需使用另一个NULL替换即可。例如
wn9m85ua2#
不知道这是否行得通:
5vf7fwbs3#