Home
Search results “Oracle max over partition”
Over clause in SQL Server
 
09:13
over partition by in sql server 2008 sql server over clause partition partition by clause in sql server 2008 over partition by clause in sql In this video we will discuss the power and use of Over clause in SQL Server. The OVER clause combined with PARTITION BY is used to break up data into partitions. Syntax : function (...) OVER (PARTITION BY col1, Col2, ...) The specified function operates for each partition. For example : COUNT(Gender) OVER (PARTITION BY Gender) will partition the data by GENDER i.e there will 2 partitions (Male and Female) and then the COUNT() function is applied over each partition. Any of the following functions can be used. Please note this is not the complete list. COUNT(), AVG(), SUM(), MIN(), MAX(), ROW_NUMBER(), RANK(), DENSE_RANK() etc. Example : SQl Script to create Employees table Create Table Employees ( Id int primary key, Name nvarchar(50), Gender nvarchar(10), Salary int ) Go Insert Into Employees Values (1, 'Mark', 'Male', 5000) Insert Into Employees Values (2, 'John', 'Male', 4500) Insert Into Employees Values (3, 'Pam', 'Female', 5500) Insert Into Employees Values (4, 'Sara', 'Female', 4000) Insert Into Employees Values (5, 'Todd', 'Male', 3500) Insert Into Employees Values (6, 'Mary', 'Female', 5000) Insert Into Employees Values (7, 'Ben', 'Male', 6500) Insert Into Employees Values (8, 'Jodi', 'Female', 7000) Insert Into Employees Values (9, 'Tom', 'Male', 5500) Insert Into Employees Values (10, 'Ron', 'Male', 5000) Go Write a query to retrieve total count of employees by Gender. Also in the result we want Average, Minimum and Maximum salary by Gender. This can be very easily achieved using a simple GROUP BY query as show below. SELECT Gender, COUNT(*) AS GenderTotal, AVG(Salary) AS AvgSal, MIN(Salary) AS MinSal, MAX(Salary) AS MaxSal FROM Employees GROUP BY Gender What if we want non-aggregated values (like employee Name and Salary) in result set along with aggregated values You cannot include non-aggregated columns in the GROUP BY query. SELECT Name, Salary, Gender, COUNT(*) AS GenderTotal, AVG(Salary) AS AvgSal, MIN(Salary) AS MinSal, MAX(Salary) AS MaxSal FROM Employees GROUP BY Gender The above query will result in the following error : Column 'Employees.Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause One way to achieve this is by including the aggregations in a subquery and then JOINING it with the main query as shown in the example below. Look at the amount of T-SQL code we have to write. SELECT Name, Salary, Employees.Gender, Genders.GenderTotals, Genders.AvgSal, Genders.MinSal, Genders.MaxSal FROM Employees INNER JOIN (SELECT Gender, COUNT(*) AS GenderTotals, AVG(Salary) AS AvgSal, MIN(Salary) AS MinSal, MAX(Salary) AS MaxSal FROM Employees GROUP BY Gender) AS Genders ON Genders.Gender = Employees.Gender Better way of doing this is by using the OVER clause combined with PARTITION BY SELECT Name, Salary, Gender, COUNT(Gender) OVER(PARTITION BY Gender) AS GenderTotals, AVG(Salary) OVER(PARTITION BY Gender) AS AvgSal, MIN(Salary) OVER(PARTITION BY Gender) AS MinSal, MAX(Salary) OVER(PARTITION BY Gender) AS MaxSal FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/09/over-clause-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/09/over-clause-in-sql-server_29.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 79916 kudvenkat
T-SQL: Over() and Partition By
 
04:17
Show how to use OVER and PARTITION BY to get groups of data with aggregation.
Views: 4532 MidnightDBA
ORACLE Analytic Functions for Data Warehousing 2/ Arabic
 
12:32
ORACLE Analytic Functions for Data Warehousing 2/ Arabic FIRST_VALUE last_VALUE row_number() --FIRST_VALUE and LAST_VALUE Analytic Functions select EMPLOYEE_ID, FIRST_NAME, HIRE_DATE from employees order by hire_date; select EMPLOYEE_ID, FIRST_NAME, HIRE_DATE , min(HIRE_DATE) over ( ) first_HIRE_DATE from employees select EMPLOYEE_ID, FIRST_NAME, HIRE_DATE , FIRST_VALUE(HIRE_DATE) over ( ) first_HIRE_DATE from employees order by hire_date; select EMPLOYEE_ID, FIRST_NAME, HIRE_DATE , max(HIRE_DATE ) over ( ) last_HIRE_DATE from employees select EMPLOYEE_ID, FIRST_NAME, HIRE_DATE , last_VALUE(HIRE_DATE ) over ( ) last_HIRE_DATE from employees order by HIRE_DATE drop table student_exam_result; CREATE TABLE student_exam_result (student_id number, exame_name varchar2(100), exame_try number, exame_results number ); insert into student_exam_result values(1,'calcluas',1,50); insert into student_exam_result values(1,'calcluas',2,66); insert into student_exam_result values(1,'calcluas',3,20); insert into student_exam_result values(2,'calcluas',1,66); insert into student_exam_result values(2,'calcluas',2,null); insert into student_exam_result values(2,'calcluas',3,7); insert into student_exam_result values(3,'calcluas',1,50); insert into student_exam_result values(3,'calcluas',2,98); insert into student_exam_result values(3,'calcluas',3,null); select * from student_exam_result select student_id, exame_name,exame_try,exame_results, last_value(exame_results) IGNORE NULLS over (PARTITION BY student_id, exame_name ) last_grade from student_exam_result order by student_id, exame_name, exame_try select student_id, exame_name,exame_try,exame_results, last_value(exame_results) IGNORE NULLS over (PARTITION BY student_id, exame_name ) last_grade, max(exame_results) over (PARTITION BY student_id, exame_name ) max_grade, avg(exame_results) over (PARTITION BY student_id, exame_name ) avg_grade from student_exam_result order by student_id, exame_name, exame_try ------------------------ select employee_id,first_name ,row_number() over(order by employee_id ) from employees select employee_id,first_name ,rownum from employees select employee_id,first_name ,department_id, row_number() over(partition by department_id order by employee_id ) from employees
Views: 551 khaled alkhudari
Row Number function in SQL Server
 
07:24
sql server row_number example sql server row number by partition sql server row_number over partition by order by In this video we will discuss Row_Number function in SQL Server. This is continuation to Part 108. Please watch Part 108 from SQL Server tutorial before proceeding. Row_Number function Introduced in SQL Server 2005 Returns the sequential number of a row starting at 1 ORDER BY clause is required PARTITION BY clause is optional When the data is partitioned, row number is reset to 1 when the partition changes Syntax : ROW_NUMBER() OVER (ORDER BY Col1, Col2) Row_Number function without PARTITION BY : In this example, data is not partitioned, so ROW_NUMBER will provide a consecutive numbering for all the rows in the table based on the order of rows imposed by the ORDER BY clause. SELECT Name, Gender, Salary, ROW_NUMBER() OVER (ORDER BY Gender) AS RowNumber FROM Employees Please note : If ORDER BY clause is not specified you will get the following error The function 'ROW_NUMBER' must have an OVER clause with ORDER BY Row_Number function with PARTITION BY : In this example, data is partitioned by Gender, so ROW_NUMBER will provide a consecutive numbering only for the rows with in a parttion. When the partition changes the row number is reset to 1. SELECT Name, Gender, Salary, ROW_NUMBER() OVER (PARTITION BY Gender ORDER BY Gender) AS RowNumber FROM Employees Use case for Row_Number function : Deleting all duplicate rows except one from a sql server table. Discussed in detail in Part 4 of SQL Server Interview Questions and Answers video series. Text version of the video http://csharp-video-tutorials.blogspot.com/2015/09/rownumber-function-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/09/rownumber-function-in-sql-server_30.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 74943 kudvenkat
Rank and Dense Rank in SQL Server
 
10:08
rank and dense_rank example difference between rank and dense_rank with example rank vs dense_rank in sql server 2008 sql server difference between rank and dense_rank In this video we will discuss Rank and Dense_Rank functions in SQL Server Rank and Dense_Rank functions Introduced in SQL Server 2005 Returns a rank starting at 1 based on the ordering of rows imposed by the ORDER BY clause ORDER BY clause is required PARTITION BY clause is optional When the data is partitioned, rank is reset to 1 when the partition changes Difference between Rank and Dense_Rank functions Rank function skips ranking(s) if there is a tie where as Dense_Rank will not. For example : If you have 2 rows at rank 1 and you have 5 rows in total. RANK() returns - 1, 1, 3, 4, 5 DENSE_RANK returns - 1, 1, 2, 3, 4 Syntax : RANK() OVER (ORDER BY Col1, Col2, ...) DENSE_RANK() OVER (ORDER BY Col1, Col2, ...) RANK() and DENSE_RANK() functions without PARTITION BY clause : In this example, data is not partitioned, so RANK() function provides a consecutive numbering except when there is a tie. Rank 2 is skipped as there are 2 rows at rank 1. The third row gets rank 3. DENSE_RANK() on the other hand will not skip ranks if there is a tie. The first 2 rows get rank 1. Third row gets rank 2. SELECT Name, Salary, Gender, RANK() OVER (ORDER BY Salary DESC) AS [Rank], DENSE_RANK() OVER (ORDER BY Salary DESC) AS DenseRank FROM Employees RANK() and DENSE_RANK() functions with PARTITION BY clause : Notice when the partition changes from Female to Male Rank is reset to 1 SELECT Name, Salary, Gender, RANK() OVER (PARTITION BY Gender ORDER BY Salary DESC) AS [Rank], DENSE_RANK() OVER (PARTITION BY Gender ORDER BY Salary DESC) AS DenseRank FROM Employees Use case for RANK and DENSE_RANK functions : Both these functions can be used to find Nth highest salary. However, which function to use depends on what you want to do when there is a tie. Let me explain with an example. If there are 2 employees with the FIRST highest salary, there are 2 different business cases 1. If your business case is, not to produce any result for the SECOND highest salary, then use RANK function 2. If your business case is to return the next Salary after the tied rows as the SECOND highest Salary, then use DENSE_RANK function Since we have 2 Employees with the FIRST highest salary. Rank() function will not return any rows for the SECOND highest Salary. WITH Result AS ( SELECT Salary, RANK() OVER (ORDER BY Salary DESC) AS Salary_Rank FROM Employees ) SELECT TOP 1 Salary FROM Result WHERE Salary_Rank = 2 Though we have 2 Employees with the FIRST highest salary. Dense_Rank() function returns, the next Salary after the tied rows as the SECOND highest Salary WITH Result AS ( SELECT Salary, DENSE_RANK() OVER (ORDER BY Salary DESC) AS Salary_Rank FROM Employees ) SELECT TOP 1 Salary FROM Result WHERE Salary_Rank = 2 You can also use RANK and DENSE_RANK functions to find the Nth highest Salary among Male or Female employee groups. The following query finds the 3rd highest salary amount paid among the Female employees group WITH Result AS ( SELECT Salary, Gender, DENSE_RANK() OVER (PARTITION BY Gender ORDER BY Salary DESC) AS Salary_Rank FROM Employees ) SELECT TOP 1 Salary FROM Result WHERE Salary_Rank = 3 AND Gender = 'Female' Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/rank-and-denserank-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/rank-and-denserank-in-sql-server_1.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 69612 kudvenkat
SQL TOP, RANK, DENSE_RANK, ROW_NUMBER Functions
 
08:27
Jamie King of Neumont University demonstrating various SQL ranking functions.
Views: 21703 Jamie King
ORACLESQL14 - group by, over (partition by)
 
03:19
Kod SQL: http://pastebin.com/9aDLJKkf Zapytania agregujące np. liczące, sumujące w grupach np. liczące ludzi w poszczególnych krajach z użyciem group by jak i over ( PARTITION BY)
Window functions in SQL Server
 
11:00
sql server window function example window function sql server example sql server rows range clause sql server rows between 1 preceding and 1 following In this video we will discuss window functions in SQL Server In SQL Server we have different categories of window functions Aggregate functions - AVG, SUM, COUNT, MIN, MAX etc.. Ranking functions - RANK, DENSE_RANK, ROW_NUMBER etc.. Analytic functions - LEAD, LAG, FIRST_VALUE, LAST_VALUE etc... OVER Clause defines the partitioning and ordering of a rows (i.e a window) for the above functions to operate on. Hence these functions are called window functions. The OVER clause accepts the following three arguments to define a window for these functions to operate on. ORDER BY : Defines the logical order of the rows PARTITION BY : Divides the query result set into partitions. The window function is applied to each partition separately. ROWSor RANGE clause : Further limits the rows within the partition by specifying start and end points within the partition. The default for ROWS or RANGE clause is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW Let us understand the use of ROWS or RANGE clause with an example. Compute average salary and display it against every employee We might think the following query would do the job. SELECT Name, Gender, Salary, AVG(Salary) OVER(ORDER BY Salary) AS Average FROM Employees As you can see from the result, the above query does not produce the overall salary average. It produces the average of the current row and the rows preceeding the current row. This is because, the default value of ROWS or RANGE clause (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) is applied. To fix this, provide an explicit value for ROWS or RANGE clause as shown below. ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING tells the window function to operate on the set of rows starting from the first row in the partition to the last row in the partition. SELECT Name, Gender, Salary, AVG(Salary) OVER(ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS Average FROM Employees The same result can also be achieved by using RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING Well, what is the difference between ROWS and RANGE We will discuss this in a later video The following query can be used if you want to compute the average salary of 1. The current row 2. One row PRECEDING the current row and 3. One row FOLLOWING the current row SELECT Name, Gender, Salary, AVG(Salary) OVER(ORDER BY Salary ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS Average FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/window-functions-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/window-functions-in-sql-server_7.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 54555 kudvenkat
rank in oracle
 
03:22
in this tutorial i teach rank in oracle
SQL. SUM() OVER. Сумма накопленным итогом и общая сумма по полю.
 
09:54
В видео рассказывается, как посчитать сумму накопленным итогом, а так же общую сумму по полю. P.S. задавайте вопросы в комментариях и высказывайте свое мнение и пожелания
SQL Tutorial - Window Functions
 
12:41
Another fantastic SQL Tutorial brought to you by BeardedDev. In this video we begin to explore Window Functions and their purpose within SQL Server. Window Functions are used for performing data analysis calculations and address an important need compared to the GROUP BY clause that we are able to return the underlying data in the same query. This video shows an example of the differences between the GROUP BY clause and Window Functions. Window Functions were first introduced in SQL Server 2005 but further enhancements and support was added in SQL Server 2012. We look at the OVER clause and PARTITION BY. Window Functions can only be included within SELECT or ORDER BY clauses. Functions Available: Aggregate - COUNT, SUM, MIN, MAX, AVG Offset - FIRST_VALUE, LAST_VALUE, LEAD, LAG Statistical - PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DIST Windows Functions also have FRAMES ROWS RANGE Window Functions are a powerful tool within SQL Server and I am excited to bring more videos and tutorials working with Window Functions in the future. Code: WITH CTE AS ( SELECT Sales_Id , SUM(Line_Total) AS Total FROM Sales_Details GROUP BY Sales_Id ) SELECT * FROM CTE AS A INNER JOIN Sales_Details AS B ON A.Sales_Id = B.Sales_Id SELECT Sales_Id , Sales_Date , Item , Price , Quantity , Line_Total , COUNT(Line_Total) OVER(PARTITION BY Sales_Id) AS Line_Count , SUM(Line_Total) OVER(PARTITION BY Sales_Id) AS Sales_Total , SUM(Line_Total) OVER(PARTITION BY Sales_Date) AS Daily_Total , SUM(Line_Total) OVER() AS Total FROM Sales_Details ORDER BY Sales_Total
Views: 7389 BeardedDev
Over Partition - DateTime
 
06:42
Les dejamos un ejemplo de como usar Over Partition en campos DateTime en SQL Server para obtener el registro más reciente según fecha.
Views: 253 Kaizen Force
How to find Top Three Salaries from employee table ?
 
07:27
Hello guys in this video i m showing to you how to retrieve the top most salary from table. Oracle database Unbeatable,Unbreakable Platform..
Views: 6995 Oracle World
How to find nth Highest Salary in SQL ( 6 Methods )
 
13:57
This video describes how to find out nth highest salary, different / various methods / ways/types to find nth highest/lowest salary/income value using SQL server.Simple ways to get/extract particular amount.It give brief explanation with live/real time/practical examples.This is one of the most interview question in SQL. How to retrieve nth position of record of from table? , SQL Server interview question and answers.Query to select top max salary from given table.
Views: 26011 Tech Jago
Row Number Vs Rank Vs Dense Rank
 
07:04
This video shows the difference between row_number, rank and dense_rank analytical functions in oracle database with appropriate easy to understand examples, along with it the video demonstrates the different output obtained when using either of the three functions. Apart from simple explanation of the function we also show how partition by and order by clause can be used with the functions for tacking day to day scenarios. If you want more such videos of exciting and amazing 'difference between' concepts, check out the links below : union and union all : https://youtu.be/n9FqQOd8liY char and varchar2 : https://youtu.be/039qzwjWf4k replace and translate : https://youtu.be/HKYF77BGzOE procedure and function : https://youtu.be/q3LmOenL120 in and exists : https://youtu.be/REX4IjRYlFw delete and truncate : https://youtu.be/u76wMm2byXo %type and %rowtype : https://youtu.be/MlLUFeZ_3eM
Views: 2344 Kishan Mashru
RANK Analytic Function in SQL with an Example
 
05:37
RANK() Analytic Function: RANK calculates the rank of a value in a group of values. The return type is NUMBER. If two or more rows tie for a rank, each tied rows receives the same rank. For example, if the two top employees have the same salary value, they are both ranked one. The employee with the next highest salary is ranked number three, because there are two rows that are ranked higher. Therefore, the RANK function does not always return consecutive integers. The sort order that is used for the whole query determines the order in which the rows appear in a result set. PARTITION BY clause: Divides the query result set into partitions. The window function is applied to each partition separately and computation restarts for each partition. ORDER BY clause: Defines the logical order of the rows within each partition of the result set. That is, it specifies the logical order in which the window functioncalculation is performed. Query used in Video: select ename,sal,deptno,RANK() OVER(PARTITION BY deptno ORDER BY sal) from emp; Video Explanation: See here 6th row assigned the value '6',not '5' because 4th and 5th rows have same value for salary. Its the same for 12 and 13 rows also. we did not mention anything on OVER clause except ORDER BY. If you want apply RANK() by department wise, we can use PARTITION BY clause. PARTION BY works like GROUP BY in aggregates!
Views: 6539 WingsOfTechnology
Learn Oracle SQL : The Hierarchical Query Clause
 
11:19
http://bit.ly/oracle-sql-course | Get the complete course today. Learn Oracle SQL : The Hierarchical Query Clause: In this video, I show you how to use the Hierarchical Query Clause in Oracle SQL to build a basic hierarchical query. This is an excerpt of the course "The Ultimate Oracle SQL Course" which you can get at a heavily discounted price here: http://bit.ly/oracle-sql-course ================ You can find additional Oracle SQL related articles and educational content in my blog here: http://standout-dev.com/
Views: 5296 Oracle SQL
Sql Training Online - Cast Function
 
04:08
Learn about the Cast function in the SQL Language. Visit http://www.SqlTrainingOnline.com for 30 more FREE videos. The Microsoft SQL Server 2012 cast function is used to convert or change a column datatype when you are querying or filtering in a SQL statement You can visit me at any of the following: SQL Training Online: http://www.sqltrainingonline.com Twitter: http://www.twitter.com/sql_by_joey Google+: https://plus.google.com/#100925239624117719658/posts LinkedIn: http://www.linkedin.com/in/joeyblue Facebook: http://www.facebook.com/sqltrainingonline
Views: 14411 Joey Blue
Oracle Sql :  Lecture 40: GROUP BY with multiple columns
 
05:01
Oracle Sql: GROUP BY with multiple columns https://www.youtube.com/channel/UCnBpiBIOtRgMsk4G7Ri1jbQ
Views: 1993 Oracle SQL
SQL Tutorial - Window Functions - Calculate Running Totals, Averages
 
13:06
Another fantastic SQL Tutorial brought to you by BeardedDev. If you are new to working with Window Functions check out this video: https://youtu.be/H6OTMoXjNiM In this video we learn how to use Window Functions to calculate running totals and running averages. This video teaches about Window Frames: Rows Range Preceding Current Row Following Window Frames are a filtered portion of a partition. Window Functions were first introduced in SQL Server 2005 but further enhancements and support was added in SQL Server 2012. Window Functions can only be included within SELECT or ORDER BY clauses. Functions Available: Aggregate - COUNT, SUM, MIN, MAX, AVG Ranking - ROW_NUMBER, RANK, DENSE_RANK, NTILE Offset - FIRST_VALUE, LAST_VALUE, LEAD, LAG Statistical - PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DIST Windows Functions also have FRAMES ROWS RANGE Window Functions are a powerful tool within SQL Server and I am excited to bring more videos and tutorials working with Window Functions in the future. SQL: SELECT Sales_Id , Sales_Date , Sales_Total , SUM(Sales_Total) OVER(ORDER BY Sales_Date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Running Total] FROM dbo.Sales_2 WHERE Sales_Cust_Id = 3 ORDER BY Sales_Date SELECT Sales_Id , Sales_Date , Sales_Total , SUM(Sales_Total) OVER(ORDER BY Sales_Date ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS [Running Total] FROM dbo.Sales_2 WHERE Sales_Cust_Id = 3 ORDER BY Sales_Date SELECT Sales_Id , Sales_Date , Sales_Total , SUM(Sales_Total) OVER(ORDER BY Sales_Date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS [Running Total] FROM dbo.Sales_2 WHERE Sales_Cust_Id = 3 ORDER BY Sales_Date SELECT Sales_Id , Sales_Date , Sales_Total , SUM(Sales_Total) OVER(ORDER BY Sales_Date ROWS UNBOUNDED PRECEDING) AS [Running Total] FROM dbo.Sales_2 WHERE Sales_Cust_Id = 3 ORDER BY Sales_Date SELECT Sales_Id , Sales_Date , Sales_Total , SUM(Sales_Total) OVER(ORDER BY Sales_Date ROWS UNBOUNDED PRECEDING) AS [Running Total] , CAST(AVG(Sales_Total) OVER(ORDER BY Sales_Date ROWS UNBOUNDED PRECEDING) AS DECIMAL(8, 2)) AS [Running Average] FROM dbo.Sales_2 WHERE Sales_Cust_Id = 3 ORDER BY Sales_Date
Views: 2060 BeardedDev
SQL Server 2008 Partitioned Table and Parallelism
 
05:45
Detailed Article for "Partitioned Table and Parallelism" is available at : http://sqlserver-training.com/sql-server-2008-partitioned-table-parallelism-concept-video Follow us at more Updates at ----------------------------------------- Website : http://sqlserver-training.com/ Twitter : http://twitter.com/dbatag/ Facebook : http://facebook.com/dbatag/ Linked In : http://in.linkedin.com/in/dbatag/ ================================ SQL Server 2008 has removed the bottleneck of single-thread per partition over partitioned tables, which was found in SQL Server 2005. The previous bottleneck can cause performance problems under certain circumstances: On systems with many CPUs, if the table schema has less partitions than there are CPUs, then not all the CPUs will be used to process the query. Some examples: On a 32-way box, a query over a 12-partition table (e.g. a sales table partitioned by month) will only use 12 threads (one on each of 12 CPUs). This means 20 CPUs are potentially idle. On a 4-way box, a query over a 12-partition table only accesses a single partition so will only use one thread (on one CPU). This means 3 CPUs are potentially idle. On tables that have skewed data such that one partition is much larger than another, the length of time the query takes to complete will be bounded by the single thread processing the largest partition. As part of the set of improvements in SQL Server 2008 for data warehousing there will be an option to change the threading behavior for queries over partitioned tables. The new, alternative model is that all available threads process part of each partition and then move into the next partition. This allows all available CPUs to take part in processing the query, which should lead to a drop in the query completion time. The Following video shows, SQL Server 2008 -- Partitioned Table & Parallelism feature and shows graphically, how SQL Server 2008 has improved performance of Partitioned Tables. Visit the following link for more details and SQL Server Tutorials http://sqlserver-training.com/sql-server-2008-partitioned-table-parallelism-concept-video
Views: 17731 DBATAG
Part 6   Transform rows into columns in sql server
 
08:53
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/06/part-6-transform-rows-into-columns-in.html This is another common sql server interview question. We will be using Countries table in this example. SQL to create the table Create Table Countries ( Country nvarchar(50), City nvarchar(50) ) GO Insert into Countries values ('USA','New York') Insert into Countries values ('USA','Houston') Insert into Countries values ('USA','Dallas') Insert into Countries values ('India','Hyderabad') Insert into Countries values ('India','Bangalore') Insert into Countries values ('India','New Delhi') Insert into Countries values ('UK','London') Insert into Countries values ('UK','Birmingham') Insert into Countries values ('UK','Manchester') Here is the interview question. Write a sql query to transpose rows to columns. Using PIVOT operator we can very easily transform rows to columns. Select Country, City1, City2, City3 From ( Select Country, City, 'City'+ cast(row_number() over(partition by Country order by Country) as varchar(10)) ColumnSequence from Countries ) Temp pivot ( max(City) for ColumnSequence in (City1, City2, City3) ) Piv
Views: 179575 kudvenkat
GROUP BY with Aggregate functions in SQL statement
 
25:01
Using "GROUP BY" clause with Aggregate functions in SQL statement Check the whole "SQL Server Basics" series here: https://www.youtube.com/playlist?list=PLU9JMEzjCv14f3cWDhubPaddxRvx1reKR Check my SQL blog at: http://sqlwithmanoj.com/ Check my SQL FB Page at: https://www.facebook.com/sqlwithmanoj
Views: 36423 SQL with Manoj
SQL Aggregation queries using Group By, Sum, Count and Having
 
10:01
From SQL Queries Joes 2 Pros (Vol2) ch4.1. Learn up to write aggregated queries.
Views: 162393 Joes2Pros SQL Trainings
SQL ORDER BY With Multiple Columns
 
03:50
Jamie King of Neumont University demonstrating ORDER BY in regards to multiple columns.
Views: 6912 Jamie King
Running Sum using Oracle
 
08:35
Running Sum using Oracle
Views: 1002 CONNECT TO LEARN
SQL ROW NUMBER Functions | Row Number in SQL Server
 
12:33
Video talks about Ranking functions in SQL server Row Number in SQL Server SQL Server Rank Rank in SQL server The Row_Number function This function works by assigning continuous ranking to the records, without skipping any number in the result set, whether it is partitioned or no Order_By : Order by clause in sql , This clause decides how the ranking or numbering of the data starts. Partition_By : Partition by clause in sql, This clause basically provides the grouping functionality on the result set data. Please check my channel for more videos .. https://www.youtube.com/channel/UCgWvQ6cBxZwABl_hL48ayXg Also part of SQL server Training Videos SQL tutorials
Views: 713 Training2SQL MSBI
SQL:Max/Min Functions
 
03:38
In this tutorial, you'll learn how to use max min functions in sql queries. PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database (since version 7), TimesTen in-memory database (since version 11.2.1), and IBM DB2 (since version 9.7).[1] Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database. PL/SQL includes procedural language elements such as conditions and loops. It allows declaration of constants and variables, procedures and functions, types and variables of those types, and triggers. It can handle exceptions (runtime errors). Arrays are supported involving the use of PL/SQL collections. Implementations from version 8 of Oracle Database onwards have included features associated with object-orientation. One can create PL/SQL units such as procedures, functions, packages, types, and triggers, which are stored in the database for reuse by applications that use any of the Oracle Database programmatic interfaces. PL/SQL works analogously to the embedded procedural languages associated with other relational databases. For example, Sybase ASE and Microsoft SQL Server have Transact-SQL, PostgreSQL has PL/pgSQL (which emulates PL/SQL to an extent), and IBM DB2 includes SQL Procedural Language,[2] which conforms to the ISO SQL’s SQL/PSM standard. The designers of PL/SQL modeled its syntax on that of Ada. Both Ada and PL/SQL have Pascal as a common ancestor, and so PL/SQL also resembles Pascal in several aspects. However, the structure of a PL/SQL package does not resemble the basic Object Pascal program structure as implemented by a Borland Delphi or Free Pascal unit. Programmers can define public and private global data-types, constants and static variables in a PL/SQL package.[3] PL/SQL also allows for the definition of classes and instantiating these as objects in PL/SQL code. This resembles usage in object-oriented programming languages like Object Pascal, C++ and Java. PL/SQL refers to a class as an "Abstract Data Type" (ADT) or "User Defined Type" (UDT), and defines it as an Oracle SQL data-type as opposed to a PL/SQL user-defined type, allowing its use in both the Oracle SQL Engine and the Oracle PL/SQL engine. The constructor and methods of an Abstract Data Type are written in PL/SQL. The resulting Abstract Data Type can operate as an object class in PL/SQL. Such objects can also persist as column values in Oracle database tables. PL/SQL is fundamentally distinct from Transact-SQL, despite superficial similarities. Porting code from one to the other usually involves non-trivial work, not only due to the differences in the feature sets of the two languages,[4] but also due to the very significant differences in the way Oracle and SQL Server deal with concurrency and locking. There are software tools available that claim to facilitate porting including Oracle Translation Scratch Editor,[5] CEITON MSSQL/Oracle Compiler [6] and SwisSQL.[7] The StepSqlite product is a PL/SQL compiler for the popular small database SQLite. PL/SQL Program Unit A PL/SQL program unit is one of the following: PL/SQL anonymous block, procedure, function, package specification, package body, trigger, type specification, type body, library. Program units are the PL/SQL source code that is compiled, developed and ultimately executed on the database. The basic unit of a PL/SQL source program is the block, which groups together related declarations and statements. A PL/SQL block is defined by the keywords DECLARE, BEGIN, EXCEPTION, and END. These keywords divide the block into a declarative part, an executable part, and an exception-handling part. The declaration section is optional and may be used to define and initialize constants and variables. If a variable is not initialized then it defaults to NULL value. The optional exception-handling part is used to handle run time errors. Only the executable part is required. A block can have a label. Package Packages are groups of conceptually linked functions, procedures, variables, PL/SQL table and record TYPE statements, constants, cursors etc. The use of packages promotes re-use of code. Packages are composed of the package specification and an optional package body. The specification is the interface to the application; it declares the types, variables, constants, exceptions, cursors, and subprograms available. The body fully defines cursors and subprograms, and so implements the specification. Two advantages of packages are: Modular approach, encapsulation/hiding of business logic, security, performance improvement, re-usability. They support object-oriented programming features like function overloading and encapsulation. Using package variables one can declare session level (scoped) variables, since variables declared in the package specification have a session scope.
Views: 3900 radhikaravikumar
Rows Unbounded Preceding, Following in SQL Server
 
11:35
Click here to Subscribe to IT PORT Channel : https://www.youtube.com/channel/UCMjmoppveJ3mwspLKXYbVlg From SQL Server 2012, This feature enabled to OVER BY Windowing Functions The ROWS limits the rows within a partition by specifying a fixed number of rows preceding or following the current row. Preceding and following rows are defined based on the ordering in the ORDER BY clause ROWS BETWEEN 1 PRECEDING AND CURRENT ROW – Aggregates 2 Between Last Row and Current Row ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING – Aggregates 2 Current Row and Next Row ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW – Aggregates all Rows before Current Row with Current Row ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING – Aggregates all the Rows After Current Row With Current Row ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING – Aggregates all Rows
Views: 1179 IT Port
Part 1   How to find nth highest salary in sql
 
11:45
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/05/part-1-how-to-find-nth-highest-salary_17.html This is a very common SQL Server Interview Question. There are several ways of finding the nth highest salary. By the end of this video, we will be able to answer all the following questions as well. How to find nth highest salary in SQL Server using a Sub-Query How to find nth highest salary in SQL Server using a CTE How to find the 2nd, 3rd or 15th highest salary Let's use the following Employees table for this demo Use the following script to create Employees table Create table Employees ( ID int primary key identity, FirstName nvarchar(50), LastName nvarchar(50), Gender nvarchar(50), Salary int ) GO Insert into Employees values ('Ben', 'Hoskins', 'Male', 70000) Insert into Employees values ('Mark', 'Hastings', 'Male', 60000) Insert into Employees values ('Steve', 'Pound', 'Male', 45000) Insert into Employees values ('Ben', 'Hoskins', 'Male', 70000) Insert into Employees values ('Philip', 'Hastings', 'Male', 45000) Insert into Employees values ('Mary', 'Lambeth', 'Female', 30000) Insert into Employees values ('Valarie', 'Vikings', 'Female', 35000) Insert into Employees values ('John', 'Stanmore', 'Male', 80000) GO To find the highest salary it is straight forward. We can simply use the Max() function as shown below. Select Max(Salary) from Employees To get the second highest salary use a sub query along with Max() function as shown below. Select Max(Salary) from Employees where Salary [ (Select Max(Salary) from Employees) To find nth highest salary using Sub-Query SELECT TOP 1 SALARY FROM ( SELECT DISTINCT TOP N SALARY FROM EMPLOYEES ORDER BY SALARY DESC ) RESULT ORDER BY SALARY To find nth highest salary using CTE WITH RESULT AS ( SELECT SALARY, DENSE_RANK() OVER (ORDER BY SALARY DESC) AS DENSERANK FROM EMPLOYEES ) SELECT TOP 1 SALARY FROM RESULT WHERE DENSERANK = N To find 2nd highest salary we can use any of the above queries. Simple replace N with 2. Similarly, to find 3rd highest salary, simple replace N with 3. Please Note: On many of the websites, you may have seen that, the following query can be used to get the nth highest salary. The below query will only work if there are no duplicates. WITH RESULT AS ( SELECT SALARY, ROW_NUMBER() OVER (ORDER BY SALARY DESC) AS ROWNUMBER FROM EMPLOYEES ) SELECT SALARY FROM RESULT WHERE ROWNUMBER = 3
Views: 832895 kudvenkat
SQL Row Number / Window Function Example - Top NY Baby Names by Year
 
10:58
Using BigQuery's free tier (1TB per month) we explore baby name data and incorporate the basics of row_number,() where clauses and sub querying to filter inner queries. This was "live" so you see a few errors and my thought process. https://cloud.google.com/bigquery/pricing. A great way to learn SQL (applicable to postgressql, oracle, mssql server and others).
Views: 334 Jeffrey James
SQL Rank function
 
11:24
Video talks about rank functions in sql server dense rank in sql server sql rank function sql dense_rank function Step by step SQL Training videos SQL Tutorial for more videos https://www.youtube.com/channel/UCgWvQ6cBxZwABl_hL48ayXg
Views: 724 Training2SQL MSBI
Calculate running total in SQL Server 2012
 
06:23
running total sql server cumulative total in ms sql server running total column In this video we will discuss how to calculate running total in SQL Server 2012 and later versions. We will use the following Employees table for the examples in this video. SQL Script to create Employees table Create Table Employees ( Id int primary key, Name nvarchar(50), Gender nvarchar(10), Salary int ) Go Insert Into Employees Values (1, 'Mark', 'Male', 5000) Insert Into Employees Values (2, 'John', 'Male', 4500) Insert Into Employees Values (3, 'Pam', 'Female', 5500) Insert Into Employees Values (4, 'Sara', 'Female', 4000) Insert Into Employees Values (5, 'Todd', 'Male', 3500) Insert Into Employees Values (6, 'Mary', 'Female', 5000) Insert Into Employees Values (7, 'Ben', 'Male', 6500) Insert Into Employees Values (8, 'Jodi', 'Female', 7000) Insert Into Employees Values (9, 'Tom', 'Male', 5500) Insert Into Employees Values (10, 'Ron', 'Male', 5000) Go SQL Query to compute running total without partitions SELECT Name, Gender, Salary, SUM(Salary) OVER (ORDER BY ID) AS RunningTotal FROM Employees SQL Query to compute running total with partitions SELECT Name, Gender, Salary, SUM(Salary) OVER (PARTITION BY Gender ORDER BY ID) AS RunningTotal FROM Employees What happens if I use order by on Salary column If you have duplicate values in the Salary column, all the duplicate values will be added to the running total at once. In the example below notice that we have 5000 repeated 3 times. So 15000 (i.e 5000 + 5000 + 5000) is added to the running total at once. SELECT Name, Gender, Salary, SUM(Salary) OVER (ORDER BY Salary) AS RunningTotal FROM Employees So when computing running total, it is better to use a column that has unique data in the ORDER BY clause. Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/calculate-running-total-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/calculate-running-total-in-sql-server_3.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 50320 kudvenkat
SQL Server Aggregate functions and the OVER clause
 
57:32
Follow the Books: http://amzn.to/1RjjJCf SQL Server Training for the Microsoft 70-461 exam. This session includes Aggregate functions and the windowing functions (OVER, PARTITION BY). Slides and scripts available at: www.AaronBuma.com
Views: 3741 Aaron Buma
Difference between rows and range
 
05:52
range vs rows in sql server difference between rows clause and range clause in sql server range clause vs rows clause in sql server sql server running total query running total example in sql server In this video we will discuss the difference between rows and range in SQL Server. This is continuation to Part 116. Please watch Part 116 from SQL Server tutorial before proceeding. Let us understand the difference with an example. We will use the following Employees table in this demo. SQL Script to create the Employees table Create Table Employees ( Id int primary key, Name nvarchar(50), Salary int ) Go Insert Into Employees Values (1, 'Mark', 1000) Insert Into Employees Values (2, 'John', 2000) Insert Into Employees Values (3, 'Pam', 3000) Insert Into Employees Values (4, 'Sara', 4000) Insert Into Employees Values (5, 'Todd', 5000) Go Calculate the running total of Salary and display it against every employee row The following query calculates the running total. We have not specified an explicit value for ROWS or RANGE clause. SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary) AS RunningTotal FROM Employees So the above query is using the default value which is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW This means the above query can be re-written using an explicit value for ROWS or RANGE clause as shown below. SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal FROM Employees We can also achieve the same result, by replacing RANGE with ROWS SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal FROM Employees What is the difference between ROWS and RANGE To understand the difference we need some duplicate values for the Salary column in the Employees table. Execute the following UPDATE script to introduce duplicate values in the Salary column Update Employees set Salary = 1000 where Id = 2 Update Employees set Salary = 3000 where Id = 4 Go Now execute the following query. Notice that we get the running total as expected. SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal FROM Employees The following query uses RANGE instead of ROWS SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal FROM Employees Notice we don't get the running total as expected. So, the main difference between ROWS and RANGE is in the way duplicate rows are treated. ROWS treat duplicates as distinct values, where as RANGE treats them as a single entity. All together side by side. The following query shows how running total changes 1. When no value is specified for ROWS or RANGE clause 2. When RANGE clause is used explicitly with it's default value 3. When ROWS clause is used instead of RANGE clause SELECT Name, Salary, SUM(Salary) OVER(ORDER BY Salary) AS [Default], SUM(Salary) OVER(ORDER BY Salary RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Range], SUM(Salary) OVER(ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS [Rows] FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/difference-between-rows-and-range.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/difference-between-rows-and-range_8.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 32086 kudvenkat
RANK Aggregate Function in SQL with an Example
 
01:40
RANK() Aggregate Function: RANK calculates the rank of a value in a group of values. The return type is NUMBER. Query used in video: select RANK(5000) WITHIN GROUP (ORDER BY sal) "Rank" from emp;
Views: 1031 WingsOfTechnology
SQL in Oracle 11g Tutorial #11: Aggregate Function(MAX,MIN,SUM,AVG,STDDEV,VARIANCE) in SQL
 
03:31
SQL in Oracle 11g Tutorial #11: Aggregate Function(MAX,MIN,SUM,AVG,STDDEV,VARIANCE) in SQL. Thanks for Watching my Channel “Learn TechToTech”. Please subscribe my channel for getting first updates after uploading video.Social Media pages of Channel are: 1. My Website : www.learnfromrakesh.com 2. My Twitter: https://twitter.com/LearnTechtotech 3. Facebook Page: https://www.facebook.com/LearnTechToTech 4. Blogger : https://learntechtotech.blogspot.in/ 5. Google+ : https://learntechtotech.blogspot.in/ 6. Pinterest : https://in.pinterest.com/LearnTechToTech/ 7. LinkedIn: https://www.linkedin.com/in/Learntechtotech/ Playlist of Different Technology: 1. Operating System : https://goo.gl/q6SfrW 2. Python Programming Language : https://goo.gl/L8b5dc 3. C Language : https://goo.gl/SwvDu9 4. C language for Placement: https://goo.gl/AaQBa4 5. Java: https://goo.gl/M8F2uy 6. MySql : https://goo.gl/vdJbHQ 7. Android Mobile Application Development: https://goo.gl/M6woaT 8. Kotlin Programming Language : https://goo.gl/GXE5cd 9. Go Programming: https://goo.gl/Ua3xYW 10. Internet of Things(IoT): https://goo.gl/f2afkY 11. Oracle 11g : https://goo.gl/zds8r2 12. C++ : https://goo.gl/C1psMT
Views: 61 Learn TechToTech
DENSE_RANK Analytic Function in SQL with an Example
 
04:10
DENSE_RANK() Analytic Function: DENSE_RANK calculates the rank of a value in a group of values. The return type is NUMBER. If two or more rows tie for a rank, each tied rows receives the same rank. For example, if the two top employees have the same salary value, they are both ranked one. The employee with the next highest salary is ranked number two. This is one more than the number of distinct rows that come before this row. Therefore, the numbers returned by the DENSE_RANK function do not have gaps and always have consecutive ranks. The sort order that is used for the whole query determines the order in which the rows appear in a result set.This implies that a row ranked number one does not have to be the first row in the partition. PARTITION BY clause: Divides the query result set into partitions. The window function is applied to each partition separately and computation restarts for each partition. ORDER BY clause: Defines the logical order of the rows within each partition of the result set. That is, it specifies the logical order in which the window functioncalculation is performed. Query used in Video: select ename,deptno,sal,DENSE_RANK() OVER (PARTITION BY deptno ORDER BY SAL) from emp; Video Explanation: Here 6th row assigned with Rank-5. same for 12,13 rows. So this function always returns consecutive numbers. If you want apply DENSE_RANK() by department wise, we can use PARTITION BY clause. PARTION BY works like GROUP BY in aggregates!
Views: 1405 WingsOfTechnology
Oracle Analytic Functions
 
09:33
Learn Advanced Oracle Analytic Functions. SQL is a language that allows you to perform queries to answer a wide range of questions about your data. While standard SQL is quite powerful, there are many questions that it cannot answer at all or that it can only answer with complex and inefficient SQL workarounds. Questions about running totals, percent of total, and ranking within a group fall into this area. Also, more complex issues such as Top-N within a group and aggregates over a range also fall in this arena. These questions can be easily answered via a new class of SQL statements called Analytic Functions. This presentation will show you how to use Oracle's Analytic Function extensions to SQL to answer these questions simply and efficiently.
Views: 4840 SkillBuilders
Part 8   SQL Query to find department with highest number of employees
 
04:04
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/06/part-8-sql-query-to-find-department.html Scenario asked in the SQL Server Interview Based on the above two tables write a SQL Query to get the name of the Department that has got the maximum number of Employees. To answer this question it will be helpful if you the knowledge of JOINS & GROUP BY in SQL Server. We discusses these in Parts 11 & 12 of SQL Server Tutorial video series. SQL query that retrieves the department name with maximum number of employees SELECT TOP 1 DepartmentName FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID GROUP BY DepartmentName ORDER BY COUNT(*) DESC Scenario asked in the SQL Server Interview Based on the above two tables write a SQL Query to get the name of the Department that has got the maximum number of Employees. To answer this question it will be helpful if you the knowledge of JOINS & GROUP BY in SQL Server. We discusses these in Parts 11 & 12 of SQL Server Tutorial video series. SQL query that retrieves the department name with maximum number of employees SELECT TOP 1 DepartmentName FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID GROUP BY DepartmentName ORDER BY COUNT(*) DESC
Views: 112338 kudvenkat
Let's Learn SQL! Lesson 68 : The Partition By and Qualify Statements in RANK
 
04:28
Explore SQL with Tom Coffing of Coffing Data Warehousing! In this lesson, learn about using Partition By and Qualify with the Rank Command!
Rank and Dense Rank in SQL with Example
 
05:57
Rank and Dense Rank in SQL with Example
Views: 152 Bangalore Techie
SQL Tutorial - Window Functions - Ranking
 
17:32
Another fantastic SQL Tutorial brought to you by BeardedDev. If you are new to working with Window Functions check out this video: https://youtu.be/H6OTMoXjNiM In this video we explore ranking functions available as part of Window Functions: ROW_NUMBER() RANK() DENSE_RANK() NTILE() This tutorial shows an example of when to use each ranking function and the differences between them. Window Functions were first introduced in SQL Server 2005 but further enhancements and support was added in SQL Server 2012. We look at the OVER clause and PARTITION BY. Window Functions can only be included within SELECT or ORDER BY clauses. Functions Available: Aggregate - COUNT, SUM, MIN, MAX, AVG Ranking - ROW_NUMBER, RANK, DENSE_RANK, NTILE Offset - FIRST_VALUE, LAST_VALUE, LEAD, LAG Statistical - PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DIST Windows Functions also have FRAMES ROWS RANGE Window Functions are a powerful tool within SQL Server and I am excited to bring more videos and tutorials working with Window Functions in the future. ROW_NUMBER - unique incrementing integers RANK - same rank for same values DENSE_RANK - same rank for same values NTILE - assigns tile numbers based on number of tiles requested SQL: SELECT Sales_Id , Sales_Total , ROW_NUMBER() OVER(ORDER BY Sales_Total DESC) AS rownum , RANK() OVER(ORDER BY Sales_Total DESC) AS rnk , DENSE_RANK() OVER(ORDER BY Sales_Total DESC) AS dense , NTILE(3) OVER(ORDER BY Sales_Total DESC) AS ntle FROM dbo.Sales_2 SELECT Sales_Id , NTILE(10) OVER(ORDER BY Sales_Total DESC) AS ntle FROM dbo.Sales_2
Views: 1641 BeardedDev
SQL: Analytical Functions
 
09:20
In this tutorial, you'll learn how to use the analytical functions..
Views: 35462 radhikaravikumar
SQL Server Aggregate functions and the OVER clause.
 
57:32
SQL Server Training for the Microsoft 70-461 exam. This session includes Aggregate functions and the windowing functions (OVER, PARTITION BY).
Views: 1761 Steve Stedman
SQL Server video :- Explain aggregate functions,group by clause and having keyword ?
 
09:25
For more such videos visit http://www.questpond.com See our other Step by Step video series below :- Learn Angular tutorial for beginners https://tinyurl.com/ycd9j895 Learn MVC Core step by step :- http://tinyurl.com/y9jt3wkv Learn MSBI Step by Step in 32 hours:- https://goo.gl/TTpFZN Learn Xamarin Mobile Programming Step by Step :- https://goo.gl/WDVFuy Learn Design Pattern Step by Step in 8 hours:- https://goo.gl/eJdn0m Learn C# Step by Step in 100 hours :- https://goo.gl/FNlqn3 Learn Data structures & algorithm in 8 hours :-https://tinyurl.com/ybx29c5s Learn SQL Server Step by Step in 16 hours:- http://tinyurl.com/ja4zmwu Learn Javascript in 2 hours :- http://tinyurl.com/zkljbdl Learn SharePoint Step by Step in 8 hours:- https://goo.gl/XQKHeP Learn TypeScript in 45 Minutes :- https://goo.gl/oRkawI Learn webpack in 50 minutes:- https://goo.gl/ab7VJi Learn Visual Studio code in 10 steps for beginners:- https://tinyurl.com/lwgv8r8 Learn Tableau step by step :- https://tinyurl.com/kh6ojyo Preparing for C# / .NET interviews start here http://www.youtube.com/watch?v=gaDn-sVLj8Q visit for 600+ videos @ http://www.questpond.com In this video we will try to understand aggregate function,group by clause and having keyword. This is also one of the favorite SQL Server interview questions as well. We are also distributing a 100 page Ebook ".NET Interview Question and Answers". If you want this ebook please share this video in your facebook/twitter/linkedin account and email us on [email protected] with the shared link and we will email you the PDF.
Views: 171545 Questpond
PIVOT Tutorial - generating dynamic column with PIVOT Interview Question SQL
 
14:14
In this lecture you will learn about PIVOT operator and using it to generate dynamic columns.PIVOT is very use full operator to convert values into columns. PIVOT: •Convert your output from (values)vertical order to horizontal(making columns) one Topic to cover: •PIVOT example •PIVOT syntax •Interview Question •PIVOT on northwind •Dynamic PIVOT query http://www.techsapphire.in/index/pivot_sql_lesson_with_generating_dynamic_columns_with_pivot/0-158
Views: 27232 techsapphire
Select Top N Query
 
02:22
http://zerotoprotraining.com Select Top N Query Category: Oracle SQL Tags: Select Top N Query
Views: 1945 HandsonERP
Grouping Sets in SQL Server
 
09:36
grouping sets examples in sql server sql server grouping sets order by grouping sql server 2008 grouping sets example sql server group by union all Grouping sets is a new feature introduced in SQL Server 2008. Let us understand Grouping sets with an example. We want to calculate Sum of Salary by Country and Gender. We can very easily achieve this using a Group By query as shown below Select Country, Gender, Sum(Salary) as TotalSalary From Employees Group By Country, Gender Within the same result set we also want Sum of Salary just by Country. To achieve the above result we could combine 2 Group By queries using UNION ALL as shown below. Select Country, Gender, Sum(Salary) as TotalSalary From Employees Group By Country, Gender UNION ALL Select Country, NULL, Sum(Salary) as TotalSalary From Employees Group By Country Within the same result set we also want Sum of Salary just by Gender. We can achieve this by combining 3 Group By queries using UNION ALL as shown below Select Country, Gender, Sum(Salary) as TotalSalary From Employees Group By Country, Gender UNION ALL Select Country, NULL, Sum(Salary) as TotalSalary From Employees Group By Country UNION ALL Select NULL, Gender, Sum(Salary) as TotalSalary From Employees Group By Gender Finally we also want the grand total of Salary. In this case we are not grouping on any particular column. So both Country and Gender columns will be NULL in the resultset. To achieve this we will have to combine the fourth query using UNION ALL as shown below. Select Country, Gender, Sum(Salary) as TotalSalary From Employees Group By Country, Gender UNION ALL Select Country, NULL, Sum(Salary) as TotalSalary From Employees Group By Country UNION ALL Select NULL, Gender, Sum(Salary) as TotalSalary From Employees Group By Gender UNION ALL Select NULL, NULL, Sum(Salary) as TotalSalary From Employees There are 2 problems with the above approach. The query is huge as we have combined different Group By queries using UNION ALL operator. This can grow even more if we start to add more groups The Employees table has to be accessed 4 times, once for every query. If we use Grouping Sets feature introduced in SQL Server 2008, the amount of T-SQL code that you have to write will be greatly reduced. The following Grouping Sets query produce the same result as the above UNION ALL query. Select Country, Gender, Sum(Salary) TotalSalary From Employees Group BY GROUPING SETS ( (Country, Gender), -- Sum of Salary by Country and Gender (Country), -- Sum of Salary by Country (Gender) , -- Sum of Salary by Gender () -- Grand Total ) The order of the rows in the result set is not the same as in the case of UNION ALL query. To control the order use order by as shown below. Select Country, Gender, Sum(Salary) TotalSalary From Employees Group BY GROUPING SETS ( (Country, Gender), -- Sum of Salary by Country and Gender (Country), -- Sum of Salary by Country (Gender) , -- Sum of Salary by Gender () -- Grand Total ) Order By Grouping(Country), Grouping(Gender), Gender Text version of the video http://csharp-video-tutorials.blogspot.com/2015/09/grouping-sets-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/09/grouping-sets-in-sql-server_19.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists
Views: 45505 kudvenkat

Medical records clerk cover letter example
Example of a great cover letter for resume
Electricians cv cover letter
Rn cover letter tips that actually got
Article writing service