Home
Search results “Lead over partition in oracle”
Lead and Lag functions in SQL Server 2012
 
07:27
In this video we will discuss about Lead and Lag functions. Lead and Lag functions Introduced in SQL Server 2012 Lead function is used to access subsequent row data along with current row data Lag function is used to access previous row data along with current row data ORDER BY clause is required PARTITION BY clause is optional Syntax LEAD(Column_Name, Offset, Default_Value) OVER (ORDER BY Col1, Col2, ...) LAG(Column_Name, Offset, Default_Value) OVER (ORDER BY Col1, Col2, ...) Offset - Number of rows to lead or lag. Default_Value - The default value to return if the number of rows to lead or lag goes beyond first row or last row in a table or partition. If default value is not specified NULL is returned. We will use the following Employees table for the examples in this video SQL Script to create the 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', 1000) Insert Into Employees Values (2, 'John', 'Male', 2000) Insert Into Employees Values (3, 'Pam', 'Female', 3000) Insert Into Employees Values (4, 'Sara', 'Female', 4000) Insert Into Employees Values (5, 'Todd', 'Male', 5000) Insert Into Employees Values (6, 'Mary', 'Female', 6000) Insert Into Employees Values (7, 'Ben', 'Male', 7000) Insert Into Employees Values (8, 'Jodi', 'Female', 8000) Insert Into Employees Values (9, 'Tom', 'Male', 9000) Insert Into Employees Values (10, 'Ron', 'Male', 9500) Go Lead and Lag functions example WITHOUT partitions : This example Leads 2 rows and Lags 1 row from the current row. When you are on the first row, LEAD(Salary, 2, -1) allows you to move forward 2 rows and retrieve the salary from the 3rd row. When you are on the first row, LAG(Salary, 1, -1) allows us to move backward 1 row. Since there no rows beyond row 1, Lag function in this case returns the default value -1. When you are on the last row, LEAD(Salary, 2, -1) allows you to move forward 2 rows. Since there no rows beyond the last row 1, Lead function in this case returns the default value -1. When you are on the last row, LAG(Salary, 1, -1) allows us to move backward 1 row and retrieve the salary from the previous row. SELECT Name, Gender, Salary, LEAD(Salary, 2, -1) OVER (ORDER BY Salary) AS Lead_2, LAG(Salary, 1, -1) OVER (ORDER BY Salary) AS Lag_1 FROM Employees Lead and Lag functions example WITH partitions : Notice that in this example, Lead and Lag functions return default value if the number of rows to lead or lag goes beyond first row or last row in the partition. SELECT Name, Gender, Salary, LEAD(Salary, 2, -1) OVER (PARTITION By Gender ORDER BY Salary) AS Lead_2, LAG(Salary, 1, -1) OVER (PARTITION By Gender ORDER BY Salary) AS Lag_1 FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/lead-and-lag-functions-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/lead-and-lag-functions-in-sql-server_5.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: 46824 kudvenkat
Oracle Partition By clause, Oracle Analytic Functions tutorial
 
09:09
More about analytic functions, visit http://www.learn-with-video-tutorials.com Oracle Analytic Functions and Over By Partition clause enable calculating cumulative and moving aggregates returning multiple rows for each group.
What the PARTITION BY clause does in Analytic Functions Oracle SQL
 
09:14
In this tutorial video we will learn how to use PARTITION BY clause in Analytic Functions Oracle SQL
Views: 1682 Spod ssppoodd
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: 7414 BeardedDev
Oracle Partition By clause, Oracle Analytic Functions tutorial
 
09:09
Oracle Analytic Functions and Over By Partition clause enable calculating cumulative and moving aggregates returning multiple rows for each group
PARTITION BY in Oracle SQL  | Oracle SQL Tutorials | By Mr.Murali
 
31:56
PARTITION BY in Oracle SQL | Oracle SQL Tutorials | By Mr.Murali ►For Registration : https://goo.gl/r6kJbB ►Call: +91-8179191999 ► Visit Our Website: http://nareshit.in/ http://nareshit.com/ ► About NareshIT: "Naresh IT is the Best Software Training Institute for Hadoop, Salesforce, AWS, DevOps, Sprak, Data Science, Python, Tableau, RPA ,Java, C#.NET, ASP.NET, Oracle, Testing Tools, Silver light, Linq, SQL Server, Selenium, Android, iPhone, C Language, C++, PHP and Digital Marketing in Hyderabad, Chennai and Vijayawada, India which provides online and classroom training classes" ►For Registration : https://goo.gl/r6kJbB ►Call: India- 8179191999, USA- 404-232-9879 Email: [email protected] ►Our Online Training Features: 1.Training with Real-Time Experts 2.Industry Specific Scenario’s 3.Flexible Timings 4.Soft Copy of Material 5.Share Video's of each and every session. Check The Below Links: ►For Course Reg : https://goo.gl/r6kJbB ► Subscribe to Our Channel: https://goo.gl/q9ozyG ► Circle us on G+: https://plus.google.com/NareshIT ► Like us on Facebook: https://www.facebook.com/NareshIT ► Follow us on Twitter: https://twitter.com/nareshitech ► Visit Our Website: http://nareshit.in/ http://nareshit.com/
Views: 4146 Naresh i Technologies
Oracle LAG & LEAD Functions / Arabic
 
11:23
--The LAG function is used to access data from a previous row --LAG (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause) --value_expression - Can be a column or a built-in function, except for other analytic functions. --offset - The number of rows preceeding/following the current row, from which the data is to be retrieved. The default value is 1. --default - The value returned if the offset is outside the scope of the window. The default value is NULL. -- The LEAD function is used to return data from the next row. --LEAD (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)
Views: 601 khaled alkhudari
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: 1663 BeardedDev
Difference between Row Number, Rank and Dense Rank | Oracle SQL Tutorial | Mr.Murali
 
20:46
►For Registration : https://goo.gl/r6kJbB ►Call: +91-8179191999 ► Visit Our Website: http://nareshit.in/ http://nareshit.com/ ► About NareshIT: "Naresh IT is the Best Software Training Institute for Hadoop, Salesforce, AWS, DevOps, Sprak, Data Science, Python, Tableau, RPA ,Java, C#.NET, ASP.NET, Oracle, Testing Tools, Silver light, Linq, SQL Server, Selenium, Android, iPhone, C Language, C++, PHP and Digital Marketing in Hyderabad, Chennai and Vijayawada, India which provides online and classroom training classes" ►For Registration : https://goo.gl/r6kJbB ►Call: India- 8179191999, USA- 404-232-9879 Email: [email protected] ►Our Online Training Features: 1.Training with Real-Time Experts 2.Industry Specific Scenario’s 3.Flexible Timings 4.Soft Copy of Material 5.Share Video's of each and every session. Check The Below Links: ►For Course Reg : https://goo.gl/r6kJbB ► Subscribe to Our Channel: https://goo.gl/q9ozyG ► Circle us on G+: https://plus.google.com/NareshIT ► Like us on Facebook: https://www.facebook.com/NareshIT ► Follow us on Twitter: https://twitter.com/nareshitech ► Visit Our Website: http://nareshit.in/ http://nareshit.com/
Views: 8204 Naresh i Technologies
SQL: Rank & Dense_rank functions
 
06:47
In this tutorial, you'll learn the difference between rank() and dense_rank() functions..
Views: 26030 radhikaravikumar
SQL Tutorial - Window Functions - Lag and Lead
 
08:10
Another video brought to you by BeardedDev, bringing you tutorials on Business Intelligence, SQL Programming and Data Analysis. In this video I talk about using Lag and Lead in Windows Functions. This video covers the requirements to pass the exam: If you would like to follow along with the tutorial please run the SQL below: IF OBJECT_ID(N'dbo.Sales', N'U') IS NOT NULL DROP TABLE dbo.Sales; GO CREATE TABLE dbo.Sales ( Sales_Id INT NOT NULL IDENTITY(1, 1) CONSTRAINT PK_Sales_Sales_Id PRIMARY KEY , Sales_Customer_Id INT NOT NULL , Sales_Date DATETIME2 NOT NULL , Sales_Amount DECIMAL (16, 2) NOT NULL ) INSERT INTO dbo.Sales (Sales_Customer_Id, Sales_Date, Sales_Amount) VALUES (1, '20180102', 54.99) , (1, '20180103', 72.99) , (1, '20180104', 34.99) , (1, '20180115', 29.99) , (1, '20180121', 67.00) Lag and Lead are useful for performing trend analysis, in the example I show how we can display a customer spending trend. Lag will show the previous value. Lead will show the next value. Lag and Lead accept multiple parameters as demonstrated in the video: LAG([Column], [Offset], [Value if NULL]) The example of LAG and LEAD in the video can be shown by executing the below SQL query: SELECT Sales_Customer_Id , Sales_Date , LAG(Sales_Amount, 2, 0) OVER(PARTITION BY Sales_Customer_Id ORDER BY Sales_Date) AS PrevValue , Sales_Amount , LEAD(Sales_Amount, 2, 0) OVER(PARTITION BY Sales_Customer_Id ORDER BY Sales_Date) AS NextValue FROM dbo.Sales Please feel free to post comments.
Views: 1123 BeardedDev
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: 6551 WingsOfTechnology
OVER clause in Oracle Database
 
08:00
OVER clause in Oracle
Views: 15 Adam Tech
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: 54606 kudvenkat
FIRST VALUE function in SQL Server
 
02:48
In this video we will discuss FIRST_VALUE function in SQL Server FIRST_VALUE function Introduced in SQL Server 2012 Retrieves the first value from the specified column ORDER BY clause is required PARTITION BY clause is optional Syntax : FIRST_VALUE(Column_Name) OVER (ORDER BY Col1, Col2, ...) FIRST_VALUE function example WITHOUT partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the entire table. SELECT Name, Gender, Salary, FIRST_VALUE(Name) OVER (ORDER BY Salary) AS FirstValue FROM Employees FIRST_VALUE function example WITH partitions : In the following example, FIRST_VALUE function returns the name of the lowest paid employee from the respective partition. SELECT Name, Gender, Salary, FIRST_VALUE(Name) OVER (PARTITION BY Gender ORDER BY Salary) AS FirstValue FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/firstvalue-function-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/firstvalue-function-in-sql-server_6.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: 31597 kudvenkat
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: 79970 kudvenkat
SQL: LEAD Function
 
06:30
In this tutorial, you'll learn how to make use of lead function in oracle sql 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: 1766 radhikaravikumar
Oracle Tutorial || Oracle|Adv Sql | Analytical Functions Part-1 by basha
 
33:24
DURGASOFT is INDIA's No.1 Software Training Center offers online training on various technologies like JAVA, .NET , ANDROID,HADOOP,TESTING TOOLS ,ADF,INFORMATICA,TABLEAU,IPHONE,OBIEE,ANJULAR JS, SAP... courses from Hyderabad & Bangalore -India with Real Time Experts. Mail us your requirements to [email protected] so that our Supporting Team will arrange Demo Sessions. Ph:Call +91-8885252627,+91-7207212428,+91-7207212427,+91-8096969696. http://durgasoft.com http://durgasoftonlinetraining.com https://www.facebook.com/durgasoftware http://durgajobs.com https://www.facebook.com/durgajobsinfo......
SQL Ranking Functions: Part 1 The Over Clause
 
08:51
Overview of the SQL Ranking functions, focusing on the OVER clause, which must have an ORDER BY part, and might also have a PARTITION BY part.
Views: 377 Database by Doug
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: 5327 Oracle SQL
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
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
SQL: Analytical Functions
 
09:20
In this tutorial, you'll learn how to use the analytical functions..
Views: 35516 radhikaravikumar
How to Code Oracle Analytic Functions
 
52:40
Many more free Oracle Database and SQL tutorials at http://skillbuilders.com/free-oracle-tutorials. 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: 25889 SkillBuilders
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: 69811 kudvenkat
LAST VALUE function in SQL Server
 
05:35
last_value function in sql server 2008 sql server last_value function returns incorrect data sql server last_value function example sql server last_value function with partition example LAST_VALUE function in SQL Server In this video we will discuss LAST_VALUE function in SQL Server. LAST_VALUE function Introduced in SQL Server 2012 Retrieves the last value from the specified column ORDER BY clause is required PARTITION BY clause is optional ROWS or RANGE clause is optional, but for it to work correctly you may have to explicitly specify a value Syntax : LAST_VALUE(Column_Name) OVER (ORDER BY Col1, Col2, ...) LAST_VALUE function not working as expected : In the following example, LAST_VALUE function does not return the name of the highest paid employee. This is because we have not specified an explicit value for ROWS or RANGE clause. As a result it is using it's default value RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. SELECT Name, Gender, Salary, LAST_VALUE(Name) OVER (ORDER BY Salary) AS LastValue FROM Employees LAST_VALUE function working as expected : In the following example, LAST_VALUE function returns the name of the highest paid employee as expected. Notice we have set an explicit value for ROWS or RANGE clause to ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING This tells the LAST_VALUE function that it's window starts at the first row and ends at the last row in the result set. SELECT Name, Gender, Salary, LAST_VALUE(Name) OVER (ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LastValue FROM Employees LAST_VALUE function example with partitions : In the following example, LAST_VALUE function returns the name of the highest paid employee from the respective partition. SELECT Name, Gender, Salary, LAST_VALUE(Name) OVER (PARTITION BY Gender ORDER BY Salary ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS LastValue FROM Employees Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/lastvalue-function-in-sql-server.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/lastvalue-function-in-sql-server_9.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 Full SQL Server Course https://www.youtube.com/playlist?list=PL4cyC4G0M1RQ_Rm52cQ4CcOJ_T_HXeMB4 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: 31274 kudvenkat
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: 75034 kudvenkat
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
Lead And Lag Functions in sql server
 
04:56
Lead and Lag functions in Sql Server
Views: 654 Techie Savy
Oracle Performance Tuning - Lead and Lag
 
04:19
A brief overview about Lead and Lag analytic function in Oracle
Views: 1274 Saurabh Kumar
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: 2346 Kishan Mashru
exchange Partition , Move partition in oracle
 
08:42
exchange Partition , Move partition in oracle Possible operations with partitions SQL Tutorial SQL Tutorial for beginners PLSQL Tutorial PLSQL Tutorial for beginners PL/SQL Tutorial PL SQL Tutorial PL SQL Tutorial for beginners PL/SQL Tutorial for beginners Oracle SQL Tutorial Add Drop Rename Split Move ( Moving from Tablespace to tablespace) Exchange (Table to Table(non Partitioned table)) not partitioned only exchanging data (p)
Views: 929 TechLake
KISS series on Analytics: 11 Window clause examples
 
03:39
Welcome to the KISS video series. Solving problems that typically required complicated SQL in the past, that can now be easily solved with Analytic SQL syntax. In this session, we look at more examples with the window clause. The sample problem we'll solve is: Use the WINDOW clause to sum across 1 row either side of the current row. Scripts: https://livesql.oracle.com/apex/livesql/file/content_CQXSUXL3VBUVDY45G4ASDXXI6.html Watch the entire Analytics playlist at https://www.youtube.com/playlist?list=PLJMaoEWvHwFJDyhMLCkNSSUQWw9waFkIj ========================================­­­­­============== Copyright © 2015 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.
Views: 1228 Connor McDonald
T-SQL: Over() and Partition By
 
04:17
Show how to use OVER and PARTITION BY to get groups of data with aggregation.
Views: 4616 MidnightDBA
ORACLE Analytic Functions for Data Warehousing 1/ Arabic
 
16:59
ORACLE Analytic Functions for Data Warehousing 1/ Arabic --analytic functions allow developers to perform tasks in SQL that were previously confined to procedural languages. -- let's start by aggregate functions ( sum, avg, count,...) select * from EMPLOYEES; select avg(salary) from employees; select DEPARTMENT_ID, avg(salary) from employees group by DEPARTMENT_ID order by 1 /* Analytic functions also operate on subsets of rows, similar to aggregate functions in GROUP BY queries, but they do not reduce the number of rows returned by the query */ select avg(salary) from employees; select employee_id, first_name,salary,(select avg(salary) from employees) avg_sal from EMPLOYEES; --analytic_function([ arguments ]) OVER (analytic_clause) --The analytic_clause breaks down into the following optional elements. --[ query_partition_clause ] [ order_by_clause [ windowing_clause ] ] select employee_id, first_name,salary, avg(salary) over() avg_sal from EMPLOYEES; select employee_id, first_name,salary, avg(salary) over( order by EMPLOYEE_ID ) from EMPLOYEES; select DEPARTMENT_ID, avg(salary) from employees group by DEPARTMENT_ID order by 1 select employee_id, first_name,salary,DEPARTMENT_ID, avg(salary) over(PARTITION BY DEPARTMENT_ID) avg_sal_dept from EMPLOYEES; select employee_id, first_name,salary,DEPARTMENT_ID, avg(salary) over(PARTITION BY DEPARTMENT_ID order by employee_id ) from EMPLOYEES drop table concan_card; create table concan_card ( rec_serial number primary key, game_name varchar2(100), game_round number, player_name varchar2(100), game_round_score number ); insert into concan_card values(1,'GAME1',1,'ahmed', -60); insert into concan_card values(2,'GAME1',1,'khaled', 200); insert into concan_card values(3,'GAME1',1,'ali', 30); insert into concan_card values(4,'GAME1',2,'ahmed', 10); insert into concan_card values(5,'GAME1',2,'khaled', -30); insert into concan_card values(6,'GAME1',2,'ali', 100); insert into concan_card values(7,'GAME1',3,'ahmed', -30); insert into concan_card values(8,'GAME1',3,'khaled', 100); insert into concan_card values(9,'GAME1',3,'ali', 6); select * from concan_card select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY player_name order by player_name,game_round ) from concan_card select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY player_name order by rec_serial ) from concan_card select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY game_name,player_name order by rec_serial ) from concan_card insert into concan_card values(10,'GAME2',1,'ahmed', -60); insert into concan_card values(11,'GAME2',1,'khaled', 200); insert into concan_card values(12,'GAME2',1,'ali', 30); insert into concan_card values(13,'GAME2',2,'ahmed', 10); insert into concan_card values(14,'GAME2',2,'khaled', -30); insert into concan_card values(15,'GAME2',2,'ali', 100); insert into concan_card values(16,'GAME2',3,'ahmed', -30); insert into concan_card values(17,'GAME2',3,'khaled', 100); insert into concan_card values(18,'GAME2',3,'ali', 6); select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY player_name order by player_name,game_round ) from concan_card select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY player_name order by rec_serial ) from concan_card select rec_serial,game_name ,game_round,player_name, game_round_score, sum(game_round_score) over ( PARTITION BY game_name,player_name order by rec_serial ) from concan_card
Views: 3777 khaled alkhudari
SQL Query Training   70 461 TOP Ranking and Analytic functions
 
01:26:16
Additional Training: http://amzn.to/1RjjJCf Other Trainings: www.AaronBuma.com/free-sql-server-training/ We cover features around the TOP(N) in your query, followed by using the RANK(), DENSE_RANK and ROW_NUMBER. Then on to Analytic Functions to help with your statistical analysis of data. Similar to aggregate functions, analytics functions compute over a group of rows with multiple results within each group. Learn how to properly use each of these analytics functions in combination with enhancements to the OVER clause. Learn the value of CUME_DIST and PERCENT_RANK in your analysis, use LAST_VALUE and FIRST_VALUE along with PERCENTILE_DISC, PERCENTILE_CONT, LEAD and LAG you can look at data in the next and previous row. For previous presentations and notifications of upcoming events, checkout my blog: www.AaronBuma.com or follow @AaronDBuma Slides and scripts are also available at: www.AaronBuma.com
Views: 9043 Aaron Buma
Analytical functions in oracle part 1
 
16:19
Rank ,Dense Rank and Row number function in oracle
Views: 223 DataSmith
How to Code Oracle FIRST LAST Aggregate Functions
 
06:35
Learn Advanced Oracle SQL Aggregate functions FIRST and LAST. View all lessons in this tutorial at http://www.skillbuilders.com/advanced-aggregations-with-oracle-sql
Views: 762 SkillBuilders
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: 2100 BeardedDev
LAG analytical function in plsql.
 
14:18
How to use LAG analytical function in plsql to find the nth nearest record from the top.Watch this pl sql tutorial on lag analytical functions in oracle to find out records with nth lagging values.
Views: 492 Subhroneel Ganguly
Difference between rank dense rank and row number in SQL
 
04:43
row_number vs rank vs dense_rank in sql server dense_rank vs rank vs row_number sql server rank dense_rank row_number in sql server In this video we will discuss the similarities and difference between RANK, DENSE_RANK and ROW_NUMBER functions in SQL Server. Similarities between RANK, DENSE_RANK and ROW_NUMBER functions Returns an increasing integer value starting at 1 based on the ordering of rows imposed by the ORDER BY clause (if there are no ties) ORDER BY clause is required PARTITION BY clause is optional When the data is partitioned, the integer value is reset to 1 when the partition changes SQL Script to create the 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', 6000) Insert Into Employees Values (2, 'John', 'Male', 8000) Insert Into Employees Values (3, 'Pam', 'Female', 4000) Insert Into Employees Values (4, 'Sara', 'Female', 5000) Insert Into Employees Values (5, 'Todd', 'Male', 3000) Notice that no two employees in the table have the same salary. So all the 3 functions RANK, DENSE_RANK and ROW_NUMBER produce the same increasing integer value when ordered by Salary column. SELECT Name, Salary, Gender, ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RowNumber, RANK() OVER (ORDER BY Salary DESC) AS [Rank], DENSE_RANK() OVER (ORDER BY Salary DESC) AS DenseRank FROM Employees You will only see the difference when there ties. Now let's include duplicate values for Salary column. To do this First delete existing data from the Employees table DELETE FROM Employees Insert new rows with duplicate valuse for Salary column Insert Into Employees Values (1, 'Mark', 'Male', 8000) Insert Into Employees Values (2, 'John', 'Male', 8000) Insert Into Employees Values (3, 'Pam', 'Female', 8000) Insert Into Employees Values (4, 'Sara', 'Female', 4000) Insert Into Employees Values (5, 'Todd', 'Male', 3500) Notice 3 employees have the same salary 8000. When you execute the following query you can clearly see the difference between RANK, DENSE_RANK and ROW_NUMBER functions. SELECT Name, Salary, Gender, ROW_NUMBER() OVER (ORDER BY Salary DESC) AS RowNumber, RANK() OVER (ORDER BY Salary DESC) AS [Rank], DENSE_RANK() OVER (ORDER BY Salary DESC) AS DenseRank FROM Employees Difference between RANK, DENSE_RANK and ROW_NUMBER functions ROW_NUMBER : Returns an increasing unique number for each row starting at 1, even if there are duplicates. RANK : Returns an increasing unique number for each row starting at 1. When there are duplicates, same rank is assigned to all the duplicate rows, but the next row after the duplicate rows will have the rank it would have been assigned if there had been no duplicates. So RANK function skips rankings if there are duplicates. DENSE_RANK : Returns an increasing unique number for each row starting at 1. When there are duplicates, same rank is assigned to all the duplicate rows but the DENSE_RANK function will not skip any ranks. This means the next row after the duplicate rows will have the next rank in the sequence. Text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/difference-between-rank-denserank-and.html Slides http://csharp-video-tutorials.blogspot.com/2015/10/difference-between-rank-denserank-and_2.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: 38533 kudvenkat
NTILE function in SQL Server
 
05:10
In this video we will discuss NTILE function in SQL Server NTILE function 1. Introduced in SQL Server 2005 2. ORDER BY Clause is required 3. PARTITION BY clause is optional 4. Distributes the rows into a specified number of groups 5. If the number of rows is not divisible by number of groups, you may have groups of two different sizes. 6. Larger groups come before smaller groups For example NTILE(2) of 10 rows divides the rows in 2 Groups (5 in each group) NTILE(3) of 10 rows divides the rows in 3 Groups (4 in first group, 3 in 2nd & 3rd group) Syntax : NTILE (Number_of_Groups) OVER (ORDER BY Col1, Col2, ...) 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 NTILE function without PARTITION BY clause : Divides the 10 rows into 3 groups. 4 rows in first group, 3 rows in the 2nd & 3rd group. SELECT Name, Gender, Salary, NTILE(3) OVER (ORDER BY Salary) AS [Ntile] FROM Employees What if the specified number of groups is GREATER THAN the number of rows NTILE function will try to create as many groups as possible with one row in each group. With 10 rows in the table, NTILE(11) will create 10 groups with 1 row in each group. SELECT Name, Gender, Salary, NTILE(11) OVER (ORDER BY Salary) AS [Ntile] FROM Employees NTILE function with PARTITION BY clause : When the data is partitioned, NTILE function creates the specified number of groups with in each partition. The following query partitions the data into 2 partitions (Male & Female). NTILE(3) creates 3 groups in each of the partitions. SELECT Name, Gender, Salary, NTILE(3) OVER (PARTITION BY GENDER ORDER BY Salary) AS [Ntile] FROM Employees Link for all dot net and sql server video tutorial playlists https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1 Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/10/ntile-function-in-sql-server.html
Views: 35804 kudvenkat
Oracle LISTAGG Function
 
04:57
https://www.databasestar.com/oracle-listagg/ The Oracle LISTAGG function allows you to aggregate or combine string values from multiple rows into a single row. For example, it turns this data: FIRST_NAME Adam Brad Carrie Into this data: FIRST_NAME Adam, Brad, Carrie The same data is shown, but it’s in one row and not multiple. It’s a valuable string manipulation function, and once you know what it is and how it works, you’ll be able to use it in your queries as needed. So what does it look like? The function is: LISTAGG ( measure_expr [, delimiter]) WITHIN GROUP (order_by_clause) [OVER query_partition_clause] These parameters are: measure_expr: This is a column or expression that you want to concatenate the values of. In the example above, it was the first_name column. Mandatory. delimiter: This is the character between each of the measure_expr values. Optional, the default is a comma. order_by_clause: This is the order that the values from the measure_expr are listed. Mandatory. query_partition_clause: This allows you to use LISTAGG as an analytic function, allowing you to show LISTAGG in groups for different rows. One thing to be aware of is that the output of the Oracle LISTAGG function is limited to 4,000 bytes. If you get more than this, you’ll receive an error. The most common way around this that I’ve seen is to write a custom function and use a CLOB. Watch the video to find out more and see some examples. For more information about the Oracle LISTAGG function, including all of the SQL shown in this video and the examples, read the related article here: https://www.databasestar.com/oracle-listagg/
Views: 2222 Database Star
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: 50458 kudvenkat
LEAD, LAG in SQL Server
 
08:48
Click here to Subscribe to IT PORT Channel : https://www.youtube.com/channel/UCMjmoppveJ3mwspLKXYbVlg From SQL Server 2012, this feature enhanced to OVER Windowing Functions Accesses data from a subsequent row in the same result set without the use of a self-join. LEAD provides access to a row at a given physical offset that follows the current row. LAG provides access to a row at a given physical offset that before the current row. Using this analytic function in a SELECT statement, We can compare value of current row with Previous Or Following Rows.
Views: 322 IT Port
SQL: WITH Clause
 
06:11
In this tutorial, you'll learn will learn how to use with clause 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: 11530 radhikaravikumar
LISTAGG in Oracle
 
03:16
The theoretic description related to LISTAGG in Oracle to achieve the required which is shown in the Video.
Views: 1161 Techie Rajesh

Free printable cover letter samples
Custom writing service
Unf admissions essay layout
Annotated bibliography mla example 2014 jeep
Cover letter for pharmacy intern position