Basic queries Flashcards

1
Q

query data in columns c1 and c2 from table t

A

SELECT c1, c2 FROM t;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Query all data from a table

A

SELECT * FROM t;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

query data and filter rows with a condition

A

SELECT c1, c2 FROM t

WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Sort result set in ascending or descending order

A

SELECT c1, c2 FROM t

ORDER BY c1 ACS [DESC];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

query distinct rows from a tale

A

SELECT DISTINCT c1, c2 FROM t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

query how many rows are in a table

A

SELECT COUNT(*) FROM t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

find number of rows in a certain value of c1

A

SELECT c1, COUNT(*) FROM t

GROUP BY c1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

find the total number of c1

A

SELECT SUM(c1) FROM t;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

find total number c2 of every c1 type of data

A

SELECT c1, SUM(c2) FROM t

GROUP BY c1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

find the largest or smallest value in column c2

A

SELECT MAX(c2) [MIN(c2)] FROM t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

query the names of the most downloaded apps in each category

A

SELECT name, category, MAX(downloads)
FROM fake_apps
GROUP BY category;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

get the average value in column c1

A

SELECT AVG(c1) FROM t;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly