开发者

2 results with 2 where in one select statement in sql-server

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜