मॉड्यूल 1 · पाठ 4 का 4पाठ्यक्रम में 4/57~8 min
मॉड्यूल पाठ (4/4)
ORDER BY के साथ क्रमबद्ध करें
SQL does not guarantee the order of the rows returned by a SELECT: if you
want a deterministic order, you have to ask for it explicitly with
ORDER BY:
SQL
SELECT <colonne>
FROM <tabella>
[WHERE <condizione>]
ORDER BY <colonna> [ASC|DESC] [, <altra-colonna> [ASC|DESC] …];ASCis the default: ascending order (1 → 9, A → Z, old → recent).DESCsorts descending (9 → 1, Z → A, recent → old).- You can sort by multiple columns: the second criterion breaks ties of the first.
Examples
SQL
-- Dal più recente assunto al più vecchio:
SELECT first_name, last_name, hired_on
FROM employees
ORDER BY hired_on DESC;
-- Per dipartimento crescente, poi per stipendio decrescente:
SELECT *
FROM employees
ORDER BY department_id, salary DESC;Try it
व्यायाम#sql.m1.l4.e1
प्रयास: 0लोड हो रहा है...
Extract last name (last_name) and salary (salary) of all employees, sorted from the highest salary to the lowest.
संपादक लोड हो रहा है...
संकेत दिखाएँ
ORDER BY salary DESC puts the highest-paid employees first.
3 प्रयासों के बाद समाधान उपलब्ध है
Review exercise
व्यायाम#sql.m1.l4.e2
प्रयास: 0लोड हो रहा है...
Extract last name (last_name), department_id and salary (salary) of all employees, sorted first by department_id ascending and, within the same department, from the highest salary to the lowest.
संपादक लोड हो रहा है...
संकेत दिखाएँ
You can pass two columns separated by a comma to ORDER BY, each with its own ASC or DESC.
3 प्रयासों के बाद समाधान उपलब्ध है