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 2ad7e1d

Browse files
authored
Update Commonly Used SQL Functions.md
1 parent 98a22a9 commit 2ad7e1d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎basics/Commonly Used SQL Functions.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,47 @@ Returns the rounded value of a number.
7878
```sql
7979
SELECT ROUND(salary, 2) FROM employees
8080
```
81+
```sql
82+
-- Round the salary to the nearest whole number
83+
SELECT ROUND(salary) FROM employees;
84+
```
8185
## 12. CURRENT_DATE()
8286
Returns the current date.
8387
Retrieves the current date from the system.
8488
```sql
8589
SELECT CURRENT_DATE()
8690
```
91+
```sql
92+
-- Select the current date and an employee's name
93+
SELECT CURRENT_DATE(), first_name FROM employees;
94+
```
8795
## 13. CURRENT_TIME()
8896
Returns the current time.
8997
Retrieves the current time from the system.
9098
```sql
9199
SELECT CURRENT_TIME()
92100
```
101+
```sql
102+
-- Select the current time and an employee's name
103+
SELECT CURRENT_TIME(), first_name FROM employees;
104+
```
93105
## 14. DATE_FORMAT()
94106
Formats a date according to a specified format.
95107
Returns a formatted date string.
96108
```sql
97109
SELECT DATE_FORMAT(hire_date, '%Y-%m-%d') FROM employees
98110
```
111+
```sql
112+
-- Format the hire date as day-month-year
113+
SELECT DATE_FORMAT(hire_date, '%d-%m-%Y') FROM employees;
114+
```
99115
## 15. GROUP_CONCAT()
100116
Concatenates strings from a group of rows into a single string.
101117
Returns a concatenated string with values from a group.
102118
```sql
103119
SELECT department, GROUP_CONCAT(first_name) AS employees FROM employees GROUP BY department
104120
```
121+
```sql
122+
-- Concatenate all employee names in each department separated by a semicolon
123+
SELECT department, GROUP_CONCAT(first_name ORDER BY first_name ASC SEPARATOR '; ') AS employees FROM employees GROUP BY department;
124+
```

0 commit comments

Comments
(0)

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