-
Notifications
You must be signed in to change notification settings - Fork 10
/
samples.txt
59 lines (40 loc) · 1.84 KB
/
samples.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[connect to]
CONNECT TO 'db'
[basic select]
SELECT * FROM users
[order by]
SELECT * FROM users ORDER BY #userid ASC, productid DESC
[group by]
SELECT products.productname AS product, count(users.userid) AS quantity FROM users, products WHERE users.productid=products.productid GROUP BY product ORDER BY product DESC
[having]
SELECT products.productname AS product, count(users.userid) AS quantity FROM users, products WHERE users.productid=products.productid GROUP BY product HAVING quantity > 10 ORDER BY product DESC
[join 2 tables]
SELECT users.userid, users.username, products.productname FROM users, products WHERE users.productid=products.productid
[join 2 aliased tables]
SELECT u.userid, u.username, p.productname FROM users u, products p WHERE u.productid=p.productid
[join 3 tables]
SELECT users.username, products.productname, authors.authorname FROM users, products, authors WHERE (users.productid=products.productid) and products.authorid=authors.authorid)
[insert into]
INSERT INTO users (userid,username) VALUES (600,'user-600')
[update]
UPDATE users SET gender='male' WHERE userid=600
[delete]
DELETE FROM users WHERE userid=600
[calculated fields]
SELECT userid, username, (sofi*2) AS sofi2, sofi FROM users
[output functions]
SELECT userid, UPPER(username) as username, (sofi*2) AS sofi2, sofi FROM users
[alter table add column]
ALTER TABLE users ADD COLUMN email
[alter table drop column]
ALTER TABLE users DROP COLUMN email
[insert into select]
INSERT INTO users SELECT * FROM users
[update with calculation]
UPDATE users SET sofi=2*sofi
[update with format]
update users set userid=format(userid,'%.8d')
[dateadd function]
SELECT dateadd('m',1,birthday) AS newdate, username FROM users WHERE userid=1
[easter function]
SELECT easter(year(date)) as easterdate, username FROM users