开发者

Simple SQL Ordering Question

If I had the following relation

Staff (staffNo(PK), fName, lName, 开发者_如何学编程position, sex, DOB)

How would I go about writing a query which produced a list of all details of all female staff ordered by their second name then their first name?

My guess is:

SELECT * FROM Staff ORDER BY fName ASC, lName ASC WHERE sex = 'f'

Is this correct?


Well, you can try this out to see if this is correct :)

But you should swap where predicate with order by clause, and ordering predicates as well: if you want to sort by the last name at first - you should specify last name first in the order by.


SELECT * FROM staff WHERE sex = 'F' ORDER BY lName ASC, fName ASC

You had fName and lName the wrong way round, and your ORDER BY comes after the WHERE


Try this query:

SELECT * FROM Staff WHERE sex = 'f' order by lName, fName;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜