Laboratoriya mashg’ulotlarida berilgan topshiriqlar Создание таблиц
Download 416.23 Kb.
|
SQL command 29-11-2021 (5)
- Bu sahifa navigatsiya:
- IN Operator Examples
- Example
ORDER BY DESC Example The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by the "Country" column: Example SELECT * FROM Customers ORDER BY Country DESC; ORDER BY Several Columns Example The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the "CustomerName" column. This means that it orders by Country, but if some rows have the same Country, it orders them by CustomerName: Example SELECT * FROM Customers ORDER BY Country, CustomerName; ORDER BY Several Columns Example 2 The following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country" and descending by the "CustomerName" column: Example SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC; SQL LIKE Examples The following SQL statement selects all customers with a CustomerName starting with "a":
Example SELECT * FROM Customers WHERE CustomerName LIKE 'a%'; The SQL COUNT(), AVG() and SUM() Functions COUNT() Example The following SQL statement finds the number of products: Example SELECT COUNT(ProductID) FROM Products; AVG() Example The following SQL statement finds the average price of all products: Example SELECT AVG(Price) FROM Products; SUM() Example The following SQL statement finds the sum of the "Quantity" fields in the "OrderDetails" table: Example SELECT SUM(Quantity) FROM OrderDetails; IN Operator ExamplesThe following SQL statement selects all customers that are located in "Germany", "France" or "UK": ExampleSELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK'); BETWEEN Example The following SQL statement selects all products with a price between 10 and 20: Example SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; SQL GROUP BY Examples The following SQL statement lists the number of customers in each country: Example SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country; The following SQL statement lists the number of customers in each country, sorted high to low: Example SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country ORDER BY COUNT(CustomerID) DESC; 8 Laboratoriya ishlariga topshiriq SQL HAVING Examples The following SQL statement lists the number of customers in each country. Only include countries with more than 5 customers: Example SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country HAVING COUNT(CustomerID) > 5; The following SQL statement lists the number of customers in each country, sorted high to low (Only include countries with more than 5 customers): ExampleSELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country HAVING COUNT(CustomerID) > 5 ORDER BY COUNT(CustomerID) DESC; Download 416.23 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling