Let's say.. I have two statements
select min(Log_In_Time) from tbl where (event_ID=4)
select max(Log_Off_Time) from tbl where (event_ID=5)
How can I combine that 2 statement into one select statement which is r开发者_Python百科esulted in 2 column like..
select min(Log_In_Time), max(Log_Off_Time) from tbl where ???????????????????
You can do this with a CASE statement:
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
select min(Log_In_Time) from tbl where (event_ID=4)
union all
select max(Log_Off_Time) from tbl where (event_ID=5)
精彩评论