开发者

Comparing multiple rows of data in sql

开发者 https://www.devze.com 2023-04-11 21:16 出处:网络
Howzit guys! I have to compare multiple rows of data with each other and i would really appreciate your help

Howzit guys!

I have to compare multiple rows of data with each other and i would really appreciate your help

I have a table in sql called Technicians. this table contains in开发者_运维百科formation about a technician such as, [Tech_id, Name, Surname, Tel, Cell, Status, Last_Available_time].

There are 3 status types: 'Available', 'Semi Available' and 'unavailable'

*Semi available meaning that a technician has jobs assigned to him but of mostly low priority. Last_available_time is set to datetime*

I need to get the technician with a status of 'available' and the longest last_available_time

I'm still a student.

My sql code:

select * from Technician
where (_Status='Available')


Just get the first record, ordered by their available date:

SELECT TOP 1 * 
FROM Technician
WHERE _status = 'Available'
ORDER BY Last_Available_Time

That will give one available technician, with the oldest available time.

0

精彩评论

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