Posts

Showing posts from 2019

Views in SQL

What is a View? A view is nothing more than a  saved SQL query . A view can also be considered as a  virtual table . View script  Create view VIEW_NAME AS SELECT T1. CUSTEMOR _NAME , T1.CUST_ID , T1.Address,  T2.Order_units From CUSTERMORTABLE  AS T1 Inner join   ORDERS AS T2 ON T1.CUST_ID =T2.CUST_ID Where order_units > = 60  

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 ...

SQL for Analytics

Click on bellow Links to explore more   part 1 -   How to CREATE DATABASE AND TABLE and DATA TYPES information part 2 -   working with DATABASE, What is Constraints ?what are they Part 3 -  All about Group by, Having ,Order by PART 4 -  FUNCTIONS IN SQL PART 5 -  Joins in SQL

class 5 - SQL Operators

SQL Arithmetic Operators Operator Description Example + Add Try it - Subtract Try it * Multiply Try it / Divide Try it % Modulo Try it SQL Bitwise Operators Operator Description & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR SQL Comparison Operators Operator Description Example = Equal to Try it > Greater than Try it < Less than Try it >= Greater than or equal to Try it <= Less than or equal to Try it <> Not equal to Try it SQL Compound Operators Operator Description += Add equals -= Subtract equals *= Multiply equals /= Divide equals %= Modulo equals &= Bitwise AND equals ^-= Bitwise exclusive equals |*= Bitwise OR equals SQL Logical Operators Operator Description Example ALL TRUE if all of the subquery values meet the condition Try it AND TRUE if all the conditions separated by AND is TRUE Try it ANY TRUE if any of the subquery values meet the condition Try it BETWEEN TRUE if the operand is within the...

class 4 - SQL COMMANDS and sample code to Create tables with constraints

- List of SQL commands SQL, 'Structured Query Language', is a programming language designed to manage data stored in relational databases. SQL operates through simple, declarative statements. This keeps data accurate and secure, and helps maintain the integrity of databases, regardless of size. Here's an appendix of commonly used commands. COMMANDS ALTER TABLE ALTER TABLE table_name ADD column datatype;   ALTER TABLE  lets you add columns to a table in a database. AND SELECT column_name(s) FROM table_name WHERE column_1 = value_1 AND column_2 = value_2;   AND  is an operator that combines two conditions. Both conditions must be true for the row to be included in the result set. AS SELECT column_name AS 'Alias' FROM table_name;   AS  is a keyword in SQL that allows you to rename a column or table using an  alias . AVG SELECT AVG(column_name) FROM table_name;   AVG()  is an aggregate function that return...