-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.pks
145 lines (50 loc) · 2.82 KB
/
first.pks
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
Use the above link and enter all the commands I have entered below to perform basic SQL operations :
1.) Displaying whole table :-
SELECT * FROM tablename
2.) To display a few columns :
select column_1 , column_2 from tablename
3.) To display only one row :
select * from tabename where value = "Needed Value"
4.) To get whole name for a less known value :( Darshan is name but I only know Dar)
select*from tablename where column_1 like name = "Dar%"
5. ) To get value for a specific data period :
select*from tablename where date is between "DD-MM-YYYY" and "DD-MM-YYYY"
6.) To get average of any particuar column :
select AVG('column') from tablename
7.) To get count of any particuar column :
select count('column') from tablename
8.) To get minimun price in a columns :
select min(column_name) from tablename
9.) To change the name of column as well :
select min(column_name) as MinPrice from tablename
10.) To retrieve different categorical variables present in column :
select * from tablename group by columns_name
11.) To retreive in a sorted order :
select * from tablename order by column_name
12.) To get average of all columns in a order :
SELECT avg(column1) from tablename group by column1
EG :
SELECT categoryid,avg(price) from products group by categoryid
13.) To sort according to a particular ID in ascending order :
select*from table order by columnname asc
14.) To sort according to a particular ID in descending order :
select*from table order by columnname desc
15.) To sort according to a particular ID in descending order and get only first few values :
select*from table order by columnname desc limit 1 ( works the same as Pandas Head) .
16.) Using " in " to get a particular row value :
SELECT * from tablename where column in ("rowvalue1" , "rowvalue2" )
17.) Sub query in SQl
SELECT * FROM columns where column in (select column2 from tablename where column3 = "needed value")
18.) Creating a relation between two databases having a common column using "join":
select*from tablerow1 join tablerow2 on common_row1.table1 = common_row1.table2
19.) To arrange the above query in a order :
SELECT * FROM customers join orders on customers.customerID = orders.customerID order by customerID
20.) To get a specific row of the joined database :
SELECT * FROM customers join orders on customers.customerID = orders.customerID where rowname.tablename = neededvalue order by customerID
21.) To get rid of duplicate values :
select count(distinct , columnname) from table
22.) To get different categories in a particular column :
select distinct columnname from table
23.) Left Join
select*from tablerow1 leftjoin tablerow2 on commonrow1.table1 = commonrow2.table2