Skip to content

Commit c3cd5fb

Browse files
authored
Update Basics.sql
1 parent b120c89 commit c3cd5fb

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Basics.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,47 @@ FROM CEO
5454
--if we switch to master databases, we need to specify the path
5555
SELECT *
5656
FROM SQLTutorial.dbo.company
57+
ORDER BY compName DESC, foundingYear --order by multiple columns, and only compName is ordered descendingly
5758

59+
--which will be the same as specifying by column number
60+
SELECT *
61+
FROM SQLTutorial.dbo.company
62+
ORDER BY 2 DESC, 5
63+
64+
/*
65+
Where Statement: helps limit or specify what kind of data you want to return
66+
=, <>, <, >, <=, >=, And, Or, Like, Null, Not Null, In
67+
*/
68+
SELECT * FROM CEO
69+
WHERE yeartoCEO >2000 AND birthPlace = 'Shanghai'
70+
71+
--where lastName starts with C
72+
SELECT * FROM CEO
73+
WHERE lastName like 'C%'
74+
--where lastName has C
75+
SELECT * FROM CEO
76+
WHERE lastName like '%C%'
77+
--where firstName end with y and has n in it
78+
SELECT * FROM CEO
79+
WHERE firstName like '%n%y'
80+
81+
82+
SELECT * FROM CEO
83+
WHERE lastName IS NULL --return nothing
84+
SELECT * FROM CEO
85+
WHERE lastName IS NOT NULL --return everything
86+
87+
--in is like a multiple equal statement
88+
SELECT * FROM CEO
89+
WHERE firstName IN ('Tim', 'Andy')
90+
91+
92+
/*Group by, Order by*/
93+
SELECT country, count(country) AS CountCountry
94+
FROM city
95+
WHERE city like 'S%'
96+
GROUP BY country
97+
ORDER BY CountCountry DESC --default as ASC
5898

5999

60100
/*What is the first name of the CEO of the company headquartered in Paris?*/

0 commit comments

Comments
 (0)