Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

че будет если в обоих поля стоит Null where not exists (select 1 from…

  1. User

    че будет если в обоих поля стоит Null where not exists (select 1 from lod_hist.data_statement_hist dh_new where dh_new.statement_date = dh.statement_date and dh_new.statement_tech_src_code = dh.statement_tech_src_code and dh_new.statement_type_id = dh.statement_type_id and dh_new.application_method_id = dh.application_method_id and dh_new.authority_code = dh.authority_code and dh_new.authority_level_id = dh.authority_level_id and dh_new.delegated = dh.delegated and dh_new.activity_kind_code = dh.activity_kind_code and dh_new.permit_type_prefix = dh.permit_type_prefix and dh_new.permit_level_code = dh.permit_level_code and dh_new.region_code = dh.region_code and dh_new.federal_district_id = dh.federal_district_id and dh_new.applicant_type_code = dh.applicant_type_code and dh_new.registers = dh.registers and dh_new.permit_status_code = dh.permit_status_code and dh_new.value_cnt_statement = dh.value_cnt_statement and dh_new.value_cnt_review = dh.value_cnt_review and dh_new.value_cnt_review_days = dh.value_cnt_review_days and dh_new.value_min_review_days = dh.value_min_review_days and dh_new.value_cnt_overdue = dh.value_cnt_overdue and dh_new.value_cnt_overdue_days = dh.value_cnt_overdue_days and dh_new.value_cnt_declines = dh.value_cnt_declines and dh_new.valid_from = l_create_date)

  2. Assistant

    В SQL, когда вы используете условие WHERE для фильтрации строк на основе полей, содержащих значение NULL, то важно помнить, что NULL в SQL обозначает неопределенное или отсутствующее значение. Это означает, что сравнение значения NULL с любым другим значением, в том числе с другим NULL, будет возвращать FALSE, и условие не выполнится.

    В вашем конкретном случае, если в обоих полях, которые вы сравниваете, стоит NULL, то условие не выполнится, и where not exists вернет FALSE. Таким образом, строки, где оба поля равны NULL, не будут отобраны.

    Чтобы правильно обрабатывать случаи, когда значения могут быть NULL, можно использовать специальные операторы, такие как IS NULL в сочетании с логическими операторами. Например:

    and (dh_new.statement_tech_src_code = dh.statement_tech_src_code OR (dh_new.statement_tech_src_code IS NULL AND dh.statement_tech_src_code IS NULL))
    

    Это сравнение будет корректно работать для случаев, когда одно или оба поля могут быть NULL.

    То же самое следует сделать для других полей во вашей выборке, для которых возможно наличие NULL, чтобы гарантировать корректную работу запроса.