The Language of SQL- P23

The Language of SQL- P23: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. | 96 Chapter 10 Summarizing Data Here s an example of the DISTINCT keyword used with the following SongTitles table SongID Artist Album Title 1 The Beatles Abbey Road Come Together 2 The Beatles Abbey Road Sun King 3 The Beatles Revolver Yellow Submarine 4 The Rolling Stones Let It Bleed Monkey Man 5 The Rolling Stones Flowers Ruby Tuesday 6 Paul McCartney Ram Smile Away Let s say you want to see a list of artists in the table. This can be accomplished with SELECT DISTINCT Artist FROM SongTitles ORDER BY Artist The results are Artist Paul McCartney The Beatles The Rolling Stones The DISTINCT keyword is always placed immediately after the SELECT keyword. The DISTINCT specifies that only unique values of the columnlist that follow are to be brought back. In this case there are only three unique artists so only three rows are returned. If you want to see unique combinations of both artists and albums you d issue SELECT DISTINCT Artist Aggregate Functions 97 Album FROM SongTitles ORDER BY Artist Album and the results would be Artist Album Paul McCartney Ram The Beatles Abbey Road The Beatles Revolver The Rolling Stones Flowers The Rolling Stones Let It Bleed Notice that Abbey Road is only listed once even though there are two songs from that album in the table. This is because the DISTINCT keyword causes only unique values from the listed columns to be shown. Aggregate Functions The functions we discussed in Chapter 4 were all scalar functions. These functions were all performed on a single number or value. In contrast aggregate functions are meant to be used with groups of data. The mostly widely used aggregate functions are COUNT SUM AVG MIN and MAX. These provide counts sums averages and minimum and maximum values of groups of data. All of our aggregate function examples will be taken from the following two tables with data about students fees and grades. The Fees table contains FeeID Student FeeType Fee 1 George Gym 30 2 George Lunch 10 3 George Trip 8 4 Janet Gym 30

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.