daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. USE [AdventureWorks2017];
  2.  
  3. SELECT DISTINCT(YEAR([OrderDate])) AS 'Years'
  4. FROM [Sales].[SalesOrderHeader]
  5. ORDER BY 'Years';
  6.  
  7. SELECT *
  8. FROM [Sales].[SalesOrderHeader]
  9. WHERE YEAR([OrderDate]) =   (SELECT MIN(YEAR([OrderDate]))
  10.                              FROM [Sales].[SalesOrderHeader]);
  11.  
  12. SELECT YEAR([OrderDate]) AS 'Year',
  13.        MONTH([OrderDate]) AS 'Month',
  14.        COUNT(*) AS 'Amount of orders'
  15. FROM [Sales].[SalesOrderHeader]
  16. WHERE MONTH([OrderDate]) = 5
  17. GROUP BY YEAR([OrderDate]),
  18.          MONTH([OrderDate])
  19. ORDER BY YEAR([OrderDate]);
  20.  
  21. SELECT  [Sales].[Customer].[CustomerID] AS 'Client ID',
  22.         CONCAT([LastName],', ',[FirstName]) AS 'Name' ,
  23.         COUNT(*) AS 'Amount of orders'
  24. FROM [Sales].[Customer]
  25. INNER JOIN [Person].[Person]
  26.     ON ([BusinessEntityID] = [CustomerID])
  27. LEFT JOIN [Sales].[SalesOrderHeader]
  28.     ON [Sales].[SalesOrderHeader].[CustomerID]  = [Sales].[Customer].[CustomerID]
  29. GROUP BY [Sales].[Customer].[CustomerID],
  30.          [FirstName],
  31.          [LastName]
  32. HAVING COUNT(*) >= 25
  33. ORDER BY COUNT(*) DESC ;
  34.  
  35.  
  36. SELECT YEAR([OrderDate]) AS 'Year',
  37.        MONTH([OrderDate]) AS 'Month',
  38.        DAY([OrderDate]) AS 'Day',
  39.        COUNT(*) 'Amount of orders',
  40.        SUM([SubTotal]) 'Total Price'
  41. FROM [Sales].[SalesOrderHeader]
  42. LEFT JOIN [Sales].[SalesOrderDetail]
  43.     ON [Sales].[SalesOrderDetail].[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID]
  44. GROUP BY YEAR([OrderDate]),
  45.          MONTH([OrderDate]),
  46.          DAY([OrderDate])
  47. ORDER BY YEAR([OrderDate]),
  48.          MONTH([OrderDate]),
  49.          DAY([OrderDate]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top