The Language of SQL- P14

The Language of SQL- P14:Research has shown that, being pressed for time, most readers tend to skip the introduction of any book they happen to read and then proceed immediately to the first real chapter. With that fact firmly in mind, we will only cover relatively unimportant material in the introduction, such as an explanation of what you will and will not learn by reading this book. | Sorting by a Calculated Field 51 intention is to sort first by LastName and then by FirstName so you need to list the LastName column first. Sorting by a Calculated Field We re now going to throw in our knowledge of calculated fields and aliases from Chapter 3 to illustrate some further possibilities. This SELECT SELECT LastName FirstName AS Name FROM Customers ORDER BY Name returns this data Name Harper Brenda Lopez Natalie Smith Janet Smith William As seen you are able to refer to a column alias Name in the ORDER BY clause. This illustrates another reason as to why aliases are often useful. Also note the design of the calculated field itself. You inserted a comma and a space between the last and first name columns to separate them and to show the name in a commonly used format. Conveniently this format also works well for sorting. The ability to display names in this format with a comma separating the last and first name is a handy trick to keep in mind. Users very often want to see names arranged in this manner. But what if you want to put the calculated field directly in the ORDER BY clause without also using it as a column alias Similar to the above you could also specify SELECT FirstName LastName FROM Customers ORDER BY LastName FirstName 52 Chapter 5 Sorting Data This would display FirstName LastName Brenda Harper Natalie Lopez Janet Smith William Smith The data is sorted the same as in the prior example. The only difference is that you re now specifying a calculated field in the ORDER BY clause without making use of column aliases. More on Sort Sequences In the previous examples all of the data is character data consisting of letters from A to Z. There are no numbers or special characters. Additionally there has been no consideration of upper- and lowercase letters. In an ascending sort would the word dog appear before or after DOG Each database lets users specify or customize collation settings which provide details on how data is sorted. The settings vary

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.