Coder Social home page Coder Social logo

advancedsqlexercises's Introduction

AdvancedSQLExercises

Exercises using the WorldWideWebImporters Database and SQLPlayground.

https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak

Q1

Using the database WideWorldImporters, write a SQL query which reports the consistency between orders and their attached invoices. The resultset should report for each (CustomerID, CustomerName)

  1. the total number of orders: TotalNBOrders
  2. the number of invoices converted from an order: TotalNBInvoices
  3. the total value of orders: OrdersTotalValue
  4. the total value of invoices: InvoicesTotalValue
  5. the absolute value of the difference between c - d: AbsoluteValueDifference

Q2

For the CustomerId = 1060 (CustomerName = 'Anand Mudaliyar')

  • Identify the first InvoiceLine of his first Invoice, where "first" means the lowest respective IDs, and write an update query increasing the UnitPrice of this InvoiceLine by 20.

Q3

Using the database WideWorldImporters, write a T-SQL stored procedure called ReportCustomerTurnover. This procedure takes two parameters: Choice and Year, both integers.

  • When Choice = 1 and Year = , ReportCustomerTurnover selects all the customer names and their total monthly turnover (invoiced value) for the year .

  • When Choice = 2 and Year = , ReportCustomerTurnover selects all the customer names and their total quarterly (3 months) turnover (invoiced value) for the year .

  • When Choice = 3, the value of Year is ignored and ReportCustomerTurnover selects all the customer names and their total yearly turnover (invoiced value).

  • When no value is provided for the parameter Choice, the default value of Choice must be 1. When no value is provided for the parameter Year, the default value is 2013. This doesn't impact Choice = 3.

  • For Choice = 3, the years can be hard-coded within the range of [2013-2016].

  • NULL values in the resultsets are not acceptable and must be substituted to 0.

  • All output resultsets are ordered by customer names alphabetically.

Q4

In the database WideWorldImporters, write a SQL query which reports the highest loss of money from orders not being converted into invoices, by customer category. The name and id of the customer who generated this highest loss must also be identified. The resultset is ordered by highest loss. You should be able to write it in pure SQL, but if too challenging, you may use T-SQL and cursors.

Q5

In the database SQLPlayground, write a SQL query selecting all the customers' data who have purchased all the products AND have bought more than 50 products in total (sum of all purchases).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.