datetime tune date into pad dynamic cursor money percent sp job isnumeric while over update
FREE TRIAL  SQL 2012 PROGRAMMING  SEARCH
SQL Server Scripts SQL 2005 SQL 2008 Articles
SQL JOBS NEWS FORMAT DEV JOBS
How to create product list by category?

Execute the following SQL Server T-SQL script in Management Studio Query Editor to list all products by category applying a CTE.

-- SQL CTE - Common Table Expression - SQL group by - SQL inner join

USE Northwind

GO

WITH cteCategory

     AS (SELECT   c.CategoryID,

                  NoOfProducts = count(* )

         FROM     Categories c

                  INNER JOIN Products p

                    ON c.CategoryID = p.CategoryID

         GROUP BY c.CategoryID)

SELECT   c.CategoryName,

         p.ProductName,

         p.UnitPrice,

         cnum.NoOfProducts

FROM     Categories c

         INNER JOIN Products p

           ON c.CategoryID = p.CategoryID

         INNER JOIN cteCategory cnum

           ON c.CategoryID = cnum.CategoryID

ORDER BY c.CategoryName

GO

/* Partial results

 

CategoryName      ProductName             UnitPrice   NoOfProducts

Beverages         Chai                    18.00       12

Beverages         Chang                   19.00       12

Beverages         Guaraná Fantástica      4.50        12

Beverages         Sasquatch Ale           14.00       12

Beverages         Steeleye Stout          18.00       12

Beverages         Côte de Blaye           263.50      12

Beverages         Chartreuse verte        18.00       12

*/

 

Exam Prep 70-461
Exam 70-461