Showing posts with label Concat and Trim Commands. Show all posts
Showing posts with label Concat and Trim Commands. Show all posts

Tuesday, November 24, 2015

SQL Mathematical Functions, Concat and Trim Commands

SQL Average

The "Average" keyword is used to find average of specified column in a table or the number of rows that match a specific criterion. To find the average prices from sales table given below
ItemQuantityPriceReductionTotal
Item15400102000
Item26300101800
Item3315545
Item4230560
Item523005600
Item66400102400

select avg(price) Average-Price from sales
The result of the above mentioned query is as shown below
Average-Price
240.833

SQL Count

SQL Mathematical Function, Count keyword is used to find the no of rows in a table or the number of rows that match a specific criterion. To find the no of rows in sales table following SQL query is used.
select count(*) Sales-Count from sales
Sales-Count
6

SQL MAX

SQL Max keyword is used to find maximum value of specified column in a table or the number of rows that match a specific criterion. To find the maximum prices from sales table following SQL query is used.
select max(price) Max-Price from sales
Max-Price
400

SQL Min

SQL Min keyword is used to find minimum value of specified column in a table or the number of rows that match a specific criterion. To find the maximum prices from sales table following SQL query is used
select min(price) Min-Price from sales
Min-Price
15

SQL Sum

SQL Sum keyword is used to find total value specified column in a table or the number of rows that match a specific criterion. To find the total prices from sales table following SQL query is used
select sum(price) Total from sales
Max-Price
1445

SQL Concat

SQL concat function is used to append columns or append string to a columns. For example, to append employee name & Age of the table given below, following query is used.
Employee_IDEmployee_NameAge
1John28
2Alex24
3James35
4Roy22
5Kay44
For oracle
select employee_name || '_' || age from employee
For SQL Server
select employee_name + '_' + age from employee