Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Truy vấn này trả lời một câu hỏi đơn giản: có bao nhiêu Chủ tịch của các bên khác nhau? Nếu bạn nhìn vào một phần của truy vấn SELECT bên, COUNT (bên) FROM tên GROUP BY bên, nó sẽ liệt kê bên tổng thống mỗi tên bảng. Thêm hai bộ phận khác . chọn bên, COUNT (bên) FROM tên GROUP BY bên; . thay đổi mọi thứ. | 13. Type SELECT COUNT age AVG age FROM names then press ENTER. The query results should look like this mysql SELECT COUNT age AVG age FROM names -------------- -----._z__ I COUNT age I AVG age I ---------- ----------- I 20 I 56. 0500 I 1 row in set o. 03 sec mysql This query does two things COUNT the number of presidents in the names table. Calculate the AVG average age of these presidents when they took office. RUNNING QUERIES 83 14. Type SELECT party COUNT party FROM names GROUP BY party then press ENTER. The query results should look like this mysql SELECT party COUNT party FROM names GROUP BY COUNT party Democratic Republican Federa list R e pu b1i can Whig 6 4 2 4 4 5 r ows O.O2 sec J r This query answers a simple question how many presidents were in each of the different parties If you look at a portion of the query. SELECT party COUNT party FROM names GROUP BY party .it lists the party for each president in the names table. Adding the other two parts. SELECT party COUNT party FROM names GROUP BY party .changes things. Instead of listing all 20 presidents the list will now be GROUPed into sub lists of presidents of like parties and then COUNTed. In the end you see one row for each party - a total of 5 rows. Each row contains the party name and the number of presidents affiliated with that party. 84 RUNNING QUERIES Add query criteria Up to this point you ve only queried from one table. Now use multiple tables in a query 1. Type SELECT quote last FROM quotes names WHERE quotes.id names.id ORDER By last then press ENTER. The query results should look like this yourusemame g localhost home yourusemame Shell - Konsole Session Edit view Bookmarks Settings Help mysql SELECT quote . id ORDER BY last FROM quotes names WHERE quotes. id names Ql quot e last and whatever may of our passions and evidence. I Adams I Liberty can not be preserved without general eop 1 e. inc 1 ina t i ons be our wishes our they cannot alter knowledge among p An honorab1e I Adams I than a .