mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 10:01:38 +00:00
[sql/en] fix semicolons (#4915)
This commit is contained in:
parent
b6bc1197b0
commit
2c0eb04886
@ -4,6 +4,7 @@ filename: learnsql.sql
|
|||||||
contributors:
|
contributors:
|
||||||
- ["Bob DuCharme", "http://bobdc.com/"]
|
- ["Bob DuCharme", "http://bobdc.com/"]
|
||||||
- ["Th3G33k", "https://github.com/Th3G33k"]
|
- ["Th3G33k", "https://github.com/Th3G33k"]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Structured Query Language (SQL) is an [ISO/IEC 9075](https://www.iso.org/standard/63555.html) standard language for creating and working with databases stored in a set of tables. Implementations usually add their own extensions to the language; [Comparison of different SQL implementations](http://troels.arvin.dk/db/rdbms/) is a good reference on product differences.
|
Structured Query Language (SQL) is an [ISO/IEC 9075](https://www.iso.org/standard/63555.html) standard language for creating and working with databases stored in a set of tables. Implementations usually add their own extensions to the language; [Comparison of different SQL implementations](http://troels.arvin.dk/db/rdbms/) is a good reference on product differences.
|
||||||
@ -65,16 +66,16 @@ SELECT DISTINCT title FROM titles ORDER BY title ASC;
|
|||||||
|
|
||||||
-- Use the comparison operators (=, >, <, >=, <=, <>) and
|
-- Use the comparison operators (=, >, <, >=, <=, <>) and
|
||||||
-- the conditional keywords (AND, OR) to refine your queries.
|
-- the conditional keywords (AND, OR) to refine your queries.
|
||||||
SELECT * FROM departments WHERE dept_no = 'd001' OR dept_no = 'd002'
|
SELECT * FROM departments WHERE dept_no = 'd001' OR dept_no = 'd002';
|
||||||
|
|
||||||
-- Same as above.
|
-- Same as above.
|
||||||
SELECT * FROM departments WHERE dept_no IN ('d001', 'd0002')
|
SELECT * FROM departments WHERE dept_no IN ('d001', 'd002');
|
||||||
|
|
||||||
-- Opposite of the above.
|
-- Opposite of the above.
|
||||||
SELECT * FROM departments WHERE dept_no NOT IN ('d001', 'd0002')
|
SELECT * FROM departments WHERE dept_no NOT IN ('d001', 'd002');
|
||||||
|
|
||||||
-- Select in a given range.
|
-- Select in a given range.
|
||||||
SELECT * from departments WHERE dept_no BETWEEN 'd001' AND 'd0002'
|
SELECT * from departments WHERE dept_no BETWEEN 'd001' AND 'd002';
|
||||||
|
|
||||||
-- Show the number of rows in the departments table.
|
-- Show the number of rows in the departments table.
|
||||||
SELECT COUNT(*) FROM departments;
|
SELECT COUNT(*) FROM departments;
|
||||||
@ -91,15 +92,15 @@ SELECT COUNT(*) FROM departments WHERE dept_name LIKE '%en%';
|
|||||||
-- Retrieve the total number of employees, by department number,
|
-- Retrieve the total number of employees, by department number,
|
||||||
-- with the condition of having more than 100 employees.
|
-- with the condition of having more than 100 employees.
|
||||||
SELECT dept_no, COUNT(dept_no) FROM dept_emp GROUP BY dept_no
|
SELECT dept_no, COUNT(dept_no) FROM dept_emp GROUP BY dept_no
|
||||||
HAVING COUNT(dept_no) > 100
|
HAVING COUNT(dept_no) > 100;
|
||||||
|
|
||||||
-- Aliases, using the optional keyword AS, can be used for column/table names.
|
-- Aliases, using the optional keyword AS, can be used for column/table names.
|
||||||
SELECT COUNT(A.*) AS total_employees, COUNT(B.*) total_departments
|
SELECT COUNT(A.*) AS total_employees, COUNT(B.*) total_departments
|
||||||
FROM employees AS A, departments B
|
FROM employees AS A, departments B;
|
||||||
|
|
||||||
-- Common date format is "yyyy-mm-dd".
|
-- Common date format is "yyyy-mm-dd".
|
||||||
-- However, it can vary according to the implementation, the operating system, and the session's locale.
|
-- However, it can vary according to the implementation, the operating system, and the session's locale.
|
||||||
SELECT * FROM dept_manager WHERE from_date >= '1990-01-01'
|
SELECT * FROM dept_manager WHERE from_date >= '1990-01-01';
|
||||||
|
|
||||||
-- A JOIN of information from multiple tables: the titles table shows
|
-- A JOIN of information from multiple tables: the titles table shows
|
||||||
-- who had what job titles, by their employee numbers, from what
|
-- who had what job titles, by their employee numbers, from what
|
||||||
@ -117,7 +118,7 @@ FROM titles INNER JOIN employees ON
|
|||||||
-- UNION selects distinct rows, UNION ALL selects all rows.
|
-- UNION selects distinct rows, UNION ALL selects all rows.
|
||||||
SELECT * FROM departments WHERE dept_no = 'd001'
|
SELECT * FROM departments WHERE dept_no = 'd001'
|
||||||
UNION
|
UNION
|
||||||
SELECT * FROM departments WHERE dept_no = 'd002'
|
SELECT * FROM departments WHERE dept_no = 'd002';
|
||||||
|
|
||||||
-- SQL syntax order is:
|
-- SQL syntax order is:
|
||||||
-- SELECT _ FROM _ JOIN _ ON _ WHERE _ GROUP BY _ HAVING _ ORDER BY _ UNION
|
-- SELECT _ FROM _ JOIN _ ON _ WHERE _ GROUP BY _ HAVING _ ORDER BY _ UNION
|
||||||
|
Loading…
Reference in New Issue
Block a user