组合多个选择语句

时间:2015-01-06 10:21:14

标签: sql select

我想从2个表中选择多行数据,我还需要选择大小写;例如:

select h.enquiry_id, h.hire_type, h.dry_drop, h.mobile_timestamp, s.signature_time, s.printed_name,
Convert (varchar,(s.signature_time-h.mobile_timestamp),108) as difference
from hire h
join signature s on s.hire_id = h.id
where s.typ = 0

select case
when dry_drop = 0 then 'no'
when dry_drop = 1 then 'yes'
end as dry_drop
from hire

select case
when collection = 0 then 'no'
when collection = 1 then 'yes'
end as collection
from hire

我需要知道如何将这三个选择语句合并为一个,任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

您可以直接使用:

SELECT h.enquiry_id
,h.hire_type
,h.dry_drop
,h.mobile_timestamp
,s.signature_time
,s.printed_name
,Convert(VARCHAR, (s.signature_time - h.mobile_timestamp), 108) AS difference
,CASE 
    WHEN dry_drop = 0
        THEN 'no'
    WHEN dry_drop = 1
        THEN 'yes'
    END AS dry_drop_Case
,CASE 
    WHEN COLLECTION = 0
        THEN 'no'
    WHEN COLLECTION = 1
        THEN 'yes'
    END AS collection_Case
FROM hire h
INNER JOIN signature s ON s.hire_id = h.id
WHERE s.typ = 0

希望这有助于...... !!!