아래 필드가있는 테이블이 있습니다.사례 명세서에 여러 조건이 있습니다.
id, user_id, shipping_type, inv_type, invoice_no.
inv_type은 ENUM (지역/국제)입니다.
나는 각 행의 송장을 받고 싶습니다. inv_type = 'local'이라면 invoice_no에 alias를 'local_inv_no'로 지정하고, international이면 'int_inv_no'를 별칭으로 사용합니다. 둘 중 하나가 null이면 null로 'local_inv_no'또는 결과로 null로 int_inv_no가 표시됩니다.
다음은 최근 시도입니다.
$sql = "select case when b.inv_type='local'
then (case when b.invoice_no is NULL then 'n' else b.invoice_no end 'local_inv')
else
when n.inv_type='int' then (case when b.invoice_no is NULL then 'n' else b.invoice_no end 'int_inv')
end 'inv_status'
from user_invoice b
where b.user_id = '$active_id'
";
그러나 결과는 나에게 줄 것 같습니다.
원하는 결과와 함께 DDL 및/또는 sqlfiddle을 제공하는 것이 좋습니다. 그리고 "결과를주지 않는다"? 이 쿼리는 오류 메시지를 생성합니다! – Strawberry