Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 68985cb

Browse files
authored
Update Commonly Used SQL Functions.md
1 parent 2ad7e1d commit 68985cb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎basics/Commonly Used SQL Functions.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,70 @@ Finds the highest value in a specified column.
3636
```sql
3737
SELECT MAX(salary) FROM employees
3838
```
39+
```sql
40+
-- Find the highest salary in each department
41+
SELECT department, MAX(salary) FROM employees GROUP BY department;
42+
```
3943
## 5. MIN()
4044
Returns the minimum value in a set of values.
4145
Finds the lowest value in a specified column.
4246
```sql
4347
SELECT MIN(salary) FROM employees
4448
```
49+
```sql
50+
-- Find the lowest salary in each department
51+
SELECT department, MIN(salary) FROM employees GROUP BY department;
52+
```
4553
## 6. CONCAT()
4654
Concatenates two or more strings together.
4755
Joins multiple strings into a single string.
4856
```sql
4957
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees
5058
```
59+
```sql
60+
-- Concatenate first name and last name with a comma separator
61+
SELECT CONCAT(first_name, ', ', last_name) AS full_name FROM employees;
62+
```
5163
## 7. SUBSTRING()
5264
Extracts a substring from a string.
5365
Returns a specified part of a string.
5466
```sql
5567
SELECT SUBSTRING(phone_number, 1, 3) AS area_code FROM employees
5668
```
69+
```sql
70+
-- Extract the first 5 characters of each employee's first name
71+
SELECT SUBSTRING(first_name, 1, 5) AS short_name FROM employees;
72+
```
5773
## 8. LOWER()
5874
Converts a string to lowercase.
5975
Returns the string with all characters in lowercase.
6076
```sql
6177
SELECT LOWER(first_name) FROM employees
6278
```
79+
```sql
80+
-- Convert email addresses to lowercase
81+
SELECT LOWER(email) FROM employees;
82+
```
6383
## 9. UPPER()
6484
Converts a string to uppercase.
6585
Returns the string with all characters in uppercase.
6686
```sql
6787
SELECT UPPER(last_name) FROM employees
6888
```
89+
```sql
90+
-- Convert department names to uppercase
91+
SELECT UPPER(department) FROM employees;
92+
```
6993
## 10. LENGTH()
7094
Returns the length of a string.
7195
Calculates the number of characters in a string.
7296
```sql
7397
SELECT LENGTH(first_name) AS name_length FROM employees
7498
```
99+
```sql
100+
-- Calculate the length of each employee's last name
101+
SELECT LENGTH(last_name) AS last_name_length FROM employees;
102+
```
75103
## 11. ROUND()
76104
Rounds a numeric value to a specified number of decimal places.
77105
Returns the rounded value of a number.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /