Youdao Written Questions:
Server Monitoring table Server_status, when the server state occurs server_status changes in the data table will be inserted a record, state 0 indicates that the shutdown 1 is normal, SQL query Server A's downtime start time and end time, There is a status record for more than one server in the table.
svr_id |
Svr_name |
Status_time |
STATUS |
1 |
A |
2013-10-31 00:00:00 |
1 |
2 |
B |
2013-10-31 00:00:00 |
1 |
1 |
A |
2014-11-31 00:00:00 |
0 |
2 |
B |
2014-11-31 00:00:00 |
0 |
3 |
C |
2014-11-31 00:00:00 |
0 |
... |
... |
... |
... |
 
Select S1.svr_name, S1.status_time start_date, S2.status_time end_date from server_status s1, server_status S2 where = s2.svr_id and = 1 and = 0 and S1.svr_name='A'
, today I saw someone using the case grammar, so I tried to write a bit
SelectSvr_name, CaseStatus when 1 ThenStatus_timeEnd asStart_time, CaseStatus when 0 ThenStatus_timeEnd asEnd_time fromServer_statuswhereSvr_name= 'A'
Don't know if there is any better way ...
SQL Select Case When statement