让我们说..我有两个陈述
select min(Log_In_Time) from tbl where (event_ID=4)
select max(Log_Off_Time) from tbl where (event_ID=5)
如何将该2语句组合成一个select语句,该语句产生2列,如..
select min(Log_In_Time), max(Log_Off_Time) from tbl where ???????????????????
答案 0 :(得分:2)
您可以使用CASE语句执行此操作:
Select
MIN (case when event_ID = 4 then Log_In_Time else null end) as MinTime,
MAX (case when event_ID = 5 then Log_Off_Time else null end) as MaxTime
from tbl
答案 1 :(得分:0)
select min(Log_In_Time) from tbl where (event_ID=4)
union all
select max(Log_Off_Time) from tbl where (event_ID=5)