课程: SQL Practice: Basic Queries
Solution: Get sorted data from a table
- [Instructor] This code challenge uses just one of the tables in this database, the Customers table. This table has many columns, starting with the primary key of CustomerID and continuing with a whole bunch of different columns for first name, last name, and so on. In this challenge, you're asked to return just a few of the columns sorted by the last name and then the first name. The beginning code selects everything from the Customers table, and when you test the code with this solution, you'll get incorrect output and it'll show that you're returning everything in that database table sorted by the primary key, the CustomerID. Now I'm going to paste in my solution. This time, I'm only returning three columns: the FirstName, the LastName, and the Email column. I'm getting the data from the same table, the Customers table, but now I'm sorting the data by the LastName and then the FirstName columns. Notice that I specify asc for ascending on both columns. That isn't actually necessary because that's the default, but if you want to be explicit, you can put those in. And when I test my code, I get back the expected response, the same data but now sorted alphabetically. And this time, I'm only getting back to three requested columns: FirstName, LastName, and Email. So that's my solution to this challenge. What's yours?
内容
-
-
-
Solution: Get sorted data from a table1 分钟 35 秒
-
(已锁定)
Solution: Retrieve data from multiple tables1 分钟 29 秒
-
(已锁定)
Solution: Retrieve data filtered on a range1 分钟 41 秒
-
(已锁定)
Solution: Retrieve aggregated data2 分钟 12 秒
-
(已锁定)
Solution: Get data filtered with a string pattern1 分钟 31 秒
-
(已锁定)
Solution: Find the most expensive order1 分钟 55 秒
-
(已锁定)
Solution: Find the average of orders2 分钟 5 秒
-
-