Posts

Showing posts from October, 2019

SQL Functions

Functions in SQL server can be broadly divided into 2 categoris 1.  Built-in functions 2.  User Defined functions There are several built-in functions,we will look at the most common string functions available. Functions – Function accept only input parameters, perform actions and return the result. A  function  can   return an only a single value or a table. We can't use a  function  to Insert, Update, Delete records in the database tables. Note – some functions need input parameters , some functions not required   Different Types of  SQL  Server &  SQL  Database  Functions .-              1.Aggregate functions  2.Mathematical functions   3.Conversation functions   4.Null functions   5.String functions (Text Functions)   6.Date and Time functions   7.Analytical functions  -(Ranking Functions ,Window...

Group by and Having ,Order by

Image
Group By -  In SQL Server we have got lot of aggregate functions. Examples 1. Count() 2. Sum() 3. avg() 4. Min() 5. Max() Group by  clause is used to group a selected set of rows into a set of summary rows by the values of one or more columns or expressions. It is always used in conjunction with one or more aggregate functions. I want an sql query, which gives total salaries paid by City. The output should be as shown below. Query for retrieving total salaries by city : We are applying SUM() aggregate function on Salary column, and grouping by city column. This effectively  adds, all salaries of employees with in the same city. Select  City,  SUM (Salary)  as  TotalSalary  from  tblEmployee Group by  City Note:  If you omit, the group by clause and try to execute the query, you get an error -  Column 'tblEmployee.City' is invalid in the select list  because it is not ...