Home > database >  ORACLE how to query a field, but the field values of the other two field conditions at the same time
ORACLE how to query a field, but the field values of the other two field conditions at the same time

Time:09-21

SELECT
"' AS HC_NO,
The CASE WHEN (' 444 'IN (SELECT A.t emplate_code FROM McS_doc_form_records WHERE template_code=' 444 '))
AND (' 00002 'IN (SELECT A.n ode_code FROM McS_doc_form_records WHERE node_code=' 00002 '))
) THEN (SELECT A.S TRING_VALUE from McS_doc_form_records A)
END AS INHOSP_INDEX_NO - hospital,

The CASE WHEN (' 444 'IN (SELECT A.t emplate_code FROM McS_doc_form_records WHERE template_code=' 444 '))
AND (' 00001 'IN (SELECT A.n ode_code FROM McS_doc_form_records WHERE node_code=' 00001 '))
) THEN (SELECT A.S TRING_VALUE from McS_doc_form_records A)
END AS PAT_NAME - patient name

The FROM McS_doc_form_records A

Consult everybody a great god, and I think from a table in the database by means of case retrieval from multiple fields, one of the two fields values, two other fields need to take a fixed value to obtain the data to, and finally the AS an alias, I try to write a SQL to run smoothly, but the result fields are null, if can't use case when then this statement?

CodePudding user response:

Test data are given, and your expectations as a result, the use of excel,

CodePudding user response:


I just want to according to node_code and template_code, check String_Value this field below the name and the second line of the two pieces of information

CodePudding user response:

Can't see your figure, look from SQL, part of the case when, change to the
The SELECT A.S TRING_VALUE from McS_doc_form_records where A node_code='00002' and template_code='444'
Not line?
  • Related