-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY_1.sql
More file actions
116 lines (84 loc) · 1.88 KB
/
DAY_1.sql
File metadata and controls
116 lines (84 loc) · 1.88 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# to check all the database
show databases;
# select database;
use classicmodels;
# SELECT STATEMENTS -----------------------------------
/*
Follow this sysntax for select statements
SELECT select_list
FROM table_name;
*/
# 1. select all columns from the table
SELECT * FROM ORDERS;
# 3. select single columns from the table
SELECT
firstname
FROM
employees;
# 2. select multiple columns
SELECT
lastname, firstname, jobtitle
FROM
employees;
# Sorting data --------------------------------------
/*
The following illustrates the syntax of the ORDER BY clause:
SELECT
select_list
FROM
table_name
ORDER BY
column1 [ASC|DESC],
column2 [ASC|DESC],
...;
*/
# 1. sort the customers by the values in the contactLastName column in ascending order.
SELECT
contactLastname,
contactFirstname
FROM
customers
ORDER BY
contactLastname asc;
# 2. sort customers by lastname in descending order
SELECT
contactLastname,
contactFirstname
FROM
customers
ORDER BY
contactLastname DESC;
select * from customes;
SELECT
contactlastname, contactfirstname
FROM
customers
ORDER BY contactlastname desc;
# 3. sort customers by last name in descending order and then
# first name by ascending order
SELECT
contactLastname,
contactFirstname
FROM
customers
ORDER BY
contactLastname DESC,
contactFirstname ASC;
# 4. selects the order line items from the orderdetails table.
# calculates the subtotal for each line item and sorts the result set
# based on the subtotal.
select * from orderdetails;
SELECT
orderNumber, productCode, orderlinenumber, quantityOrdered * priceEach
FROM
orderdetails
ORDER BY quantityOrdered * priceEach DESC;
# OR
SELECT
orderNumber,
orderLineNumber,
quantityOrdered * priceEach AS subtotal
FROM
orderdetails
ORDER BY subtotal DESC;
######################## DAY 1 END ##############