Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

SQL and Power Bi

The document provides SQL queries and concepts related to data manipulation and retrieval, including removing duplicates using Common Table Expressions (CTEs), finding highest and second highest salaries by department, and calculating average salaries. It also covers SQL join types, constraints, and differences between various SQL functions and operations. Additionally, it discusses the structure of employee data and includes example queries for practical application.

Uploaded by

durga prasad
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL and Power Bi

The document provides SQL queries and concepts related to data manipulation and retrieval, including removing duplicates using Common Table Expressions (CTEs), finding highest and second highest salaries by department, and calculating average salaries. It also covers SQL join types, constraints, and differences between various SQL functions and operations. Additionally, it discusses the structure of employee data and includes example queries for practical application.

Uploaded by

durga prasad
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL Query to remove duplicates using CTE.

SQL Query to find highest salary department w

SQL Query to find 2nd highest salary departme

Average Salary department wise


Left Join Syntax and output for two tables
Right Join Syntax and output for two tables
Inner Join Syntax and output for two tables
Full Outer Join Syntax and output for two tables
Constrainst in SQL
Difference between Union and Union ALL
Difference between Rank and Dense Rank
Windows functions in SQL
Stored Procedures in SQL
Slowly Chaning Dimensions
Views and temporary tables
Data warehousing concepts
Sub queries in SQL
CTE- Common Table expression- temporary named result set that you can
reference within a SELECT,INSERT,UPDATE,DEL statement. CTE can also be used in
view. It is defined by WITH clause can include one or more CTE separated by Department
comma… Syntax With cteReports(emp_id,firstName.LastName,depart_id,salary)
WITH table_nameCTE AS.
(
SELECT*, ROW_NUMBER() over (PARTITION BY ID ORDER BY ID) as < alias_name >
FROM table_name.
)
DELETE FROM table_nameCTE WHERE alias_name >1.
SELECT DEPT_ID, MAX(SALARY) as highest salary FROM employee GROUP BY departme department_
DEPT_ID; nt_id name

select *from employee


group by salary 1 Sales
order by salary desc limit 1,1;
SELECT department_id, AVG(salary) as average salary FROM employees GROUP BY 2 Marketing
department_id;
3 IT

UNIQUE - Ensures that all values in a column are different


PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY - Prevents actions that would destroy links between tables
CHECK - Ensures that the values in a column satisfies a specific condition
DEFAULT - Sets a default value for a column if no value is specified
CREATE INDEX - Used to create and retrieve data from the database very quickly
Employee

employee_id first_name last_name deprtment_id salary

1 John Smith 1 60000

2 Jane Doe 2 75000


3 Michael Johnson 1 80000
4 Emily Williams 3 55000
5 David Brown 2 70000
QUESTIONS

ELECT * FROM employees WHERE salary > ALL(SELECT avg(salary)FROM employees GROUP BY department_id);

You might also like