Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SQL Queries from these tables: a. Write a SELECT statement using a single table

ID: 3740824 • Letter: S

Question

SQL Queries from these tables:

a. Write a SELECT statement using a single table that includes an arithmetic calculation and a single row function(i.e TRUNC, ROUND, etc).   Format the number using a conversion function and format model. Include a column alias to mask the calculation.

b. Write a SELECT statement listing 2 columns (after the SELECT key word). Include a GROUP function with a restriction. Specify the sort order.

c. Write 1 inner join using at least 3 tables and specify at least 1 restriction. If you do not have 3 related tables to support this, explain and work with 2 tables.

C ID |$ C LASTS: C FIRST )? C MI C STATES. C ZIP |?C DPHONE C EPHONE 3.C USERID |?C PASSWORD )? C BIRTHDATE: C ADDRESS 10-DEC-67 9815 Circle Dr Tallahassee FL 14-AUG-58 172 Alto Park 12-APR-60 C_CITY 1 Graham Neal 2 Sanchez Myra 3 Smith Lisa 4 Phelp Paul(null) 18-JAN-81 994 Kirkman Rd. Northpoint NY 5 Lewis Sheila A 6 James Thomas E 32308 9045551897 904558599 grahamn barbiecar 42180 4185551791 4185556643 sanchezmt qwert5 51875 3075557841 3075559852 smithlm joshua5 11795 4825554788 4825558219 phelpp hold98er 37812 3525554972 352555181l lewissa 125pass 87195 7615553485 7615553319 jamest nokstell Seattle WA 850 East Main Santa AnaCA 30-AUG-78 01-JUN-73 195 College Blvd. Newton 348 Rice Lane GA Radcliff WY

Explanation / Answer

Please find my answer:

A)

In the above query we have used arithmetic operations, alias names and single row function round.

b)

SELECT State, Count(CustomerID) As NumberOfCustomers

FROM Customers

WHERE State <> "NY"

GROUP BY State

HAVING Count(CustomerID) >10

ORDER BY Count(CustomerID) DESC;

In the above we used sort and group by clause with selection of two columns.

C)

SELECT O.OrderNumber, CONVERT(date,O.OrderDate) AS Date,

P.ProductName, I.Quantity, I.UnitPrice

FROM [Order] O

JOIN OrderItem I ON O.Id = I.OrderId

JOIN Product P ON P.Id = I.ProductId

ORDER BY O.OrderNumber

In the above query we used 3 tables with 1 inner join and order by condition