Escolar Documentos
Profissional Documentos
Cultura Documentos
DISTINCT, Aliases, scalar functions and CASE, using JOIN and MERGE; Filtering and sorting data, NULL
values
Introduce data types, data type usage, converting data types, understanding SQL Server function types
Aggregate functions, GROUP BY and HAVING clauses, subqueries; self-contained, correlated, and EXISTS; Views, inline-table
valued functions, and derived tables
| Lunch Break
Common
SUM
MIN
MAX
AVG
COUNT
COUNT_BIG
Statistical
STDEV
STDEVP
VAR
VARP
Other
CHECKSUM_AGG
GROUPING
GROUPING_ID
SELECT <select_list>
FROM <table_source>
WHERE <search_condition>
GROUP BY <group_by_list>;
Logical Order
Phase
Comments
SELECT
FROM
WHERE
GROUP BY
Creates groups
HAVING
Operates on groups
ORDER BY
Show only customers that have placed more than one order:
SELECT Cust.Customerid, COUNT(*) AS cnt
FROM Sales.Customer AS Cust
JOIN Sales.SalesOrderHeader AS Ord ON Cust.CustomerID =
ORD.CustomerID
GROUP BY Cust.CustomerID
HAVING COUNT(*) > 1;
SELECT <column_list>
FROM (
<derived_table_definition>
) AS <derived_table_alias>;
Have an alias
Have names for all
columns
Have unique names
for all columns
Not use an ORDER BY
clause (without TOP or
OFFSET/FETCH)
Not be referred to
multiple times in the
same query
Use internal or
external aliases for
columns
Refer to parameters
and/or variables
Be nested within other
derived tables
WITH CTE_year AS
(
SELECT YEAR(OrderDate) AS OrderYear, customerID
FROM Sales.SalesOrderHeader
)
SELECT orderyear, COUNT(DISTINCT CustomerID) AS CustCount
FROM CTE_year
GROUP BY OrderYear;
Common
SUM
MIN
MAX
AVG
COUNT
COUNT_BIG
Statistical
STDEV
STDEVP
VAR
VARP
Other
CHECKSUM_AGG
GROUPING
GROUPING_ID
DISTINCT, Aliases, scalar functions and CASE, using JOIN and MERGE; Filtering and sorting data, NULL
values
Introduce data types, data type usage, converting data types, understanding SQL Server function types
Aggregate functions, GROUP BY and HAVING clauses, subqueries; self-contained, correlated, and EXISTS; Views, inline-table
valued functions, and derived tables
| Lunch Break
2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in
the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because
Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information
provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.