w3resource

AdventureWorks: SQL Exercises, Practice, Solution

SQL Queries: AdventureWorks Part-II [100 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

101. From the following table write a query in SQL to calculate the salary percentile for each employee within the 'Information Services' and 'Document Control' departments. The query should return the department, last name, rate, cumulative distribution (CUME_DIST), and percent rank (PERCENT_RANK) of the rate. The result set should be ordered by department in ascending order and rate in descending order.

Sample table: HumanResources.vemployeedepartmenthistory
businessentityid|title|firstname  |middlename      |lastname         |suffix|shift  |department                |groupname                           |startdate |enddate   |
----------------+-----+-----------+----------------+-----------------+------+-------+--------------------------+------------------------------------+----------+----------+
               1|     |Ken        |J               |Sánchez          |      |Day    |Executive                 |Executive General and Administration|2009-01-14|          |
               2|     |Terri      |Lee             |Duffy            |      |Day    |Engineering               |Research and Development            |2008-01-31|          |
               3|     |Roberto    |                |Tamburello       |      |Day    |Engineering               |Research and Development            |2007-11-11|          |
               4|     |Rob        |                |Walters          |      |Day    |Engineering               |Research and Development            |2007-12-05|2010-05-30|
               4|     |Rob        |                |Walters          |      |Day    |Tool Design               |Research and Development            |2010-05-31|          |
               5|Ms.  |Gail       |A               |Erickson         |      |Day    |Engineering               |Research and Development            |2008-01-06|          |
               6|Mr.  |Jossef     |H               |Goldberg         |      |Day    |Engineering               |Research and Development            |2008-01-24|          |
               7|     |Dylan      |A               |Miller           |      |Day    |Research and Development  |Research and Development            |2009-02-08|          |
               8|     |Diane      |L               |Margheim         |      |Day    |Research and Development  |Research and Development            |2008-12-29|          |
               9|     |Gigi       |N               |Matthew          |      |Day    |Research and Development  |Research and Development            |2009-01-16|          |
              10|     |Michael    |                |Raheem           |      |Day    |Research and Development  |Research and Development            |2009-05-03|          |
			-- more --

Click to view Full table

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

department          |lastname     |rate   |cumedist|pctrank           |
--------------------+-------------+-------+--------+------------------+
Document Control    |Arifin       |17.7885|     1.0|               1.0|
Document Control    |Kharatishvili|16.8269|     0.8|               0.5|
Document Control    |Norred       |16.8269|     0.8|               0.5|
Document Control    |Chai         |  10.25|     0.4|               0.0|
Document Control    |Berge        |  10.25|     0.4|               0.0|
Information Services|Trenary      |50.4808|     1.0|               1.0|
Information Services|Conroy       |39.6635|     0.9|0.8888888888888888|
Information Services|Ajenstat     |38.4615|     0.8|0.6666666666666666|
Information Services|Wilson       |38.4615|     0.8|0.6666666666666666|
Information Services|Sharma       |32.4519|     0.6|0.4444444444444444|
Information Services|Connelly     |32.4519|     0.6|0.4444444444444444|
Information Services|Bueno        |27.4038|     0.4|               0.0|
Information Services|Meyyappan    |27.4038|     0.4|               0.0|
Information Services|Bacon        |27.4038|     0.4|               0.0|
Information Services|Berg         |27.4038|     0.4|               0.0|

Click me to see the solution

102. From the following table write a query in SQL to return the name, list price, and the alias "LeastExpensive" for the product(s) that have the lowest list price within a given product subcategory (ProductSubcategoryID = 37). Ensure the query filters the results to this specific subcategory and correctly identifies the least expensive product(s).

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name               |listprice|leastexpensive     |
-------------------+---------+-------------------+
Patch Kit/8 Patches|     2.29|Patch Kit/8 Patches|

Click me to see the solution

103. From the following table write a query in SQL to return the employee with the fewest number of vacation hours compared to other employees with the same job title. Partitions the employees by job title and apply the first value to each partition independently.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

jobtitle                                |lastname         |vacationhours|fewestvacationhours|
----------------------------------------+-----------------+-------------+-------------------+
Accountant                              |Moreland         |           58|Moreland           |
Accountant                              |Seamans          |           59|Moreland           |
Accounts Manager                        |Liu              |           57|Liu                |
Accounts Payable Specialist             |Tomic            |           63|Tomic              |
Accounts Payable Specialist             |Sheperdigian     |           64|Tomic              |
Accounts Receivable Specialist          |Poe              |           60|Poe                |
Accounts Receivable Specialist          |Spoon            |           61|Poe                |
Accounts Receivable Specialist          |Walton           |           62|Poe                |
Application Specialist                  |Bueno            |           71|Bueno              |
Application Specialist                  |Bacon            |           72|Bueno              |
Application Specialist                  |Meyyappan        |           73|Bueno              |
Application Specialist                  |Berg             |           74|Bueno              |
...

Click me to see the solution

104. From the following table write a query in SQL to return the difference in sales quotas for a specific employee for the years 2012 and 2013. Returun BusinessEntityID, sales year, current quota, and previous quota.

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

businessentityid|salesyear|currentquota|previousquota|
----------------+---------+------------+-------------+
             275|   2012.0|      550000|            0|
             275|   2012.0|     1429000|       550000|
             275|   2012.0|     1324000|      1429000|
             275|   2012.0|      729000|      1324000|
             275|   2013.0|     1194000|       729000|
             275|   2013.0|     1575000|      1194000|
             275|   2013.0|     1218000|      1575000|
             275|   2013.0|      849000|      1218000|

Click me to see the solution

105. From the following table write a query in SQL to compare year-to-date sales between employees. Return TerritoryName, BusinessEntityID, SalesYTD, and sales of previous year i.e.PrevRepSales. Sort the result set in ascending order on territory name.

Sample table: Sales.vSalesPerson
businessentityid|title|firstname|middlename|lastname         |suffix|jobtitle                    |phonenumber        |phonenumbertype|emailaddress                |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|territoryname |territorygroup|salesquota|salesytd    |saleslastyear|
----------------+-----+---------+----------+-----------------+------+----------------------------+-------------------+---------------+----------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+--------------+--------------+----------+------------+-------------+
             274|     |Stephen  |Y         |Jiang            |      |North American Sales Manager|238-555-0197       |Cell           |[email protected]|             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |              |              |          | 559697.5639|            0|
             275|     |Michael  |G         |Blythe           |      |Sales Representative        |257-555-0154       |Cell           |[email protected]|             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |Northeast     |North America |    300000|3763178.1787| 1750406.4785|
             276|     |Linda    |C         |Mitchell         |      |Sales Representative        |883-555-0116       |Work           |[email protected]  |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |Southwest     |North America |    250000|4251368.5497| 1439156.0291|
             277|     |Jillian  |          |Carson           |      |Sales Representative        |517-555-0117       |Work           |[email protected]|             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |Central       |North America |    250000|3189418.3662| 1997186.2037|
             278|     |Garrett  |R         |Vargas           |      |Sales Representative        |922-555-0165       |Work           |[email protected]|             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |Canada        |North America |    250000|1453719.4653| 1620276.8966|
             279|     |Tsvi     |Michael   |Reiter           |      |Sales Representative        |664-555-0112       |Work           |[email protected]   |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |Southeast     |North America |    300000| 2315185.611| 1849640.9418|
             280|     |Pamela   |O         |Ansman-Wolfe     |      |Sales Representative        |340-555-0193       |Cell           |[email protected] |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |Northwest     |North America |    250000|1352577.1325|  1927059.178|
             281|     |Shu      |K         |Ito              |      |Sales Representative        |330-555-0120       |Cell           |[email protected]    |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |Southwest     |North America |    250000|2458535.6169| 2073505.9999|
             282|     |José     |Edvaldo   |Saraiva          |      |Sales Representative        |185-555-0169       |Work           |josé[email protected]   |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |Canada        |North America |    250000|2604540.7172| 2038234.6549|
             283|     |David    |R         |Campbell         |      |Sales Representative        |740-555-0182       |Work           |[email protected]  |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |Northwest     |North America |    250000|1573012.9383| 1371635.3158|
             284|Mr.  |Tete     |A         |Mensa-Annan      |      |Sales Representative        |615-555-0153       |Work           |[email protected]   |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |Northwest     |North America |    300000|1576562.1966|            0|
             285|Mr.  |Syed     |E         |Abbas            |      |Pacific Sales Manager       |926-555-0182       |Work           |[email protected]   |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |              |              |          | 172524.4512|            0|
             286|     |Lynn     |N         |Tsoflias         |      |Sales Representative        |1 (11) 500 555-0190|Cell           |[email protected]   |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |Australia     |Pacific       |    250000|1421810.9242| 2278548.9776|
             287|     |Amy      |E         |Alberts          |      |European Sales Manager      |775-555-0164       |Work           |[email protected]    |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |              |              |          |  519905.932|            0|
             288|     |Rachel   |B         |Valdez           |      |Sales Representative        |1 (11) 500 555-0140|Cell           |[email protected] |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |Germany       |Europe        |    250000|1827066.7118| 1307949.7917|
             289|     |Jae      |B         |Pak              |      |Sales Representative        |1 (11) 500 555-0145|Work           |[email protected]    |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |United Kingdom|Europe        |    250000|4116871.2277| 1635823.3967|
             290|     |Ranjit   |R         |Varkey Chudukatil|      |Sales Representative        |1 (11) 500 555-0117|Cell           |[email protected] |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |France        |Europe        |    250000|3121616.3202| 2396539.7601|

Click to view Full table

Sample Output:

territoryname|businessentityid|salesytd    |prevrepsales|
-------------+----------------+------------+------------+
Canada       |             282|2604540.7172|           0|
Canada       |             278|1453719.4653|2604540.7172|
Northwest    |             284|1576562.1966|           0|
Northwest    |             283|1573012.9383|1576562.1966|
Northwest    |             280|1352577.1325|1573012.9383|

Click me to see the solution

106. From the following tables, write a query in SQL to return the department, last name, rate, hire date, and the last hire date within each department partitioned by rate. The query should retrieve data for specific departments ('Information Services' and 'Document Control').

Sample table: HumanResources.vEmployeeDepartmentHistory
businessentityid|title|firstname  |middlename      |lastname         |suffix|shift  |department                |groupname                           |startdate |enddate   |
----------------+-----+-----------+----------------+-----------------+------+-------+--------------------------+------------------------------------+----------+----------+
               1|     |Ken        |J               |Sánchez          |      |Day    |Executive                 |Executive General and Administration|2009-01-14|          |
               2|     |Terri      |Lee             |Duffy            |      |Day    |Engineering               |Research and Development            |2008-01-31|          |
               3|     |Roberto    |                |Tamburello       |      |Day    |Engineering               |Research and Development            |2007-11-11|          |
               4|     |Rob        |                |Walters          |      |Day    |Engineering               |Research and Development            |2007-12-05|2010-05-30|
               4|     |Rob        |                |Walters          |      |Day    |Tool Design               |Research and Development            |2010-05-31|          |
               5|Ms.  |Gail       |A               |Erickson         |      |Day    |Engineering               |Research and Development            |2008-01-06|          |
               6|Mr.  |Jossef     |H               |Goldberg         |      |Day    |Engineering               |Research and Development            |2008-01-24|          |
               7|     |Dylan      |A               |Miller           |      |Day    |Research and Development  |Research and Development            |2009-02-08|          |
               8|     |Diane      |L               |Margheim         |      |Day    |Research and Development  |Research and Development            |2008-12-29|          |
               9|     |Gigi       |N               |Matthew          |      |Day    |Research and Development  |Research and Development            |2009-01-16|          |
              10|     |Michael    |                |Raheem           |      |Day    |Research and Development  |Research and Development            |2009-05-03|          |
			-- more --

Click to view Full table

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

department          |lastname     |rate   |hiredate  |lastvalue |
--------------------+-------------+-------+----------+----------+
Document Control    |Chai         |  10.25|2009-01-22|2009-02-09|
Document Control    |Berge        |  10.25|2009-02-09|2009-02-09|
Document Control    |Kharatishvili|16.8269|2008-12-16|2009-03-06|
Document Control    |Norred       |16.8269|2009-03-06|2009-03-06|
Document Control    |Arifin       |17.7885|2009-01-04|2009-01-04|
Information Services|Bueno        |27.4038|2008-12-23|2009-01-11|
Information Services|Berg         |27.4038|2009-02-16|2009-01-11|
Information Services|Meyyappan    |27.4038|2009-02-03|2009-01-11|
Information Services|Bacon        |27.4038|2009-01-11|2009-01-11|
Information Services|Sharma       |32.4519|2008-12-04|2009-02-23|
...

Click me to see the solution

107. From the following table, write a query in SQL to return the BusinessEntityID, quarter, sales year, and sales quota for the current quarter. Additionally, calculate the differences in sales quota from the first and last quarters of the year for each salesperson. Only include records for years after 2005 and for BusinessEntityIDs between 274 and 275. Order the results by BusinessEntityID, sales year, and quarter.

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

businessentityid|quarter|salesyear|quotathisquarter|differencefromfirstquarter|differencefromlastquarter|
----------------+-------+---------+----------------+--------------------------+-------------------------+
             274|    2.0|   2011.0|           28000|                         0|                   -63000|
             274|    3.0|   2011.0|            7000|                    -21000|                   -84000|
             274|    4.0|   2011.0|           91000|                     63000|                        0|
             274|    1.0|   2012.0|          140000|                         0|                    33000|
             274|    2.0|   2012.0|           70000|                    -70000|                   -37000|
             274|    3.0|   2012.0|          154000|                     14000|                    47000|
             274|    4.0|   2012.0|          107000|                    -33000|                        0|
             274|    1.0|   2013.0|           58000|                         0|                   -26000|
             274|    2.0|   2013.0|          263000|                    205000|                   179000|
             274|    3.0|   2013.0|          116000|                     58000|                    32000|
             274|    4.0|   2013.0|           84000|                     26000|                        0|
             274|    1.0|   2014.0|          187000|                         0|                        0|
             275|    2.0|   2011.0|          367000|                         0|                  -135000|
			 
...

Click me to see the solution

108. From the following table, write a query in SQL to return the quota date (Year), quarter, and sales quota for a specific salesperson. Additionally, calculate the population variance of the sales quota over the quarters for the year 2012 for this salesperson. Filter the results for the salesperson with businessentityid 277 and the year 2012. Order the results by quarter.

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

year                   |quarter|salesquota|variance             |
-----------------------+-------+----------+---------------------+
2012-02-29 00:00:00.000|    1.0|    952000|                    0|
2012-05-30 00:00:00.000|    2.0|   1600000|104976000000.00000000|
2012-08-30 00:00:00.000|    3.0|   1352000| 71267555555.55555556|
2012-11-30 00:00:00.000|    4.0|    839000| 93529187500.00000000|

...

Click me to see the solution

109. From the following table, write a query in SQL to return the business entity ID, sales year, current sales quota, and the next year's sales quota for a specific salesperson. Use the LEAD window function to get the next year's sales quota, defaulting to 0 if not available. Filter the results for the salesperson with BusinessEntityID 277 for the years 2011 and 2012.

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

businessentityid|salesyear|currentquota|nextquota|
----------------+---------+------------+---------+
             277|   2011.0|      565000|   872000|
             277|   2011.0|      872000|   846000|
             277|   2011.0|      846000|   952000|
             277|   2012.0|      952000|  1600000|
             277|   2012.0|     1600000|  1352000|
             277|   2012.0|     1352000|   839000|
             277|   2012.0|      839000|        0|

Click me to see the solution

110. From the following query write a query in SQL to compare year-to-date sales between employees for specific terrotery. Return TerritoryName, BusinessEntityID, SalesYTD, and the salesquota coming in next row.

Sample table: Sales.vSalesPerson
businessentityid|title|firstname|middlename|lastname         |suffix|jobtitle                    |phonenumber        |phonenumbertype|emailaddress                |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|territoryname |territorygroup|salesquota|salesytd    |saleslastyear|
----------------+-----+---------+----------+-----------------+------+----------------------------+-------------------+---------------+----------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+--------------+--------------+----------+------------+-------------+
             274|     |Stephen  |Y         |Jiang            |      |North American Sales Manager|238-555-0197       |Cell           |[email protected]|             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |              |              |          | 559697.5639|            0|
             275|     |Michael  |G         |Blythe           |      |Sales Representative        |257-555-0154       |Cell           |[email protected]|             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |Northeast     |North America |    300000|3763178.1787| 1750406.4785|
             276|     |Linda    |C         |Mitchell         |      |Sales Representative        |883-555-0116       |Work           |[email protected]  |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |Southwest     |North America |    250000|4251368.5497| 1439156.0291|
             277|     |Jillian  |          |Carson           |      |Sales Representative        |517-555-0117       |Work           |[email protected]|             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |Central       |North America |    250000|3189418.3662| 1997186.2037|
             278|     |Garrett  |R         |Vargas           |      |Sales Representative        |922-555-0165       |Work           |[email protected]|             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |Canada        |North America |    250000|1453719.4653| 1620276.8966|
             279|     |Tsvi     |Michael   |Reiter           |      |Sales Representative        |664-555-0112       |Work           |[email protected]   |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |Southeast     |North America |    300000| 2315185.611| 1849640.9418|
             280|     |Pamela   |O         |Ansman-Wolfe     |      |Sales Representative        |340-555-0193       |Cell           |[email protected] |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |Northwest     |North America |    250000|1352577.1325|  1927059.178|
             281|     |Shu      |K         |Ito              |      |Sales Representative        |330-555-0120       |Cell           |[email protected]    |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |Southwest     |North America |    250000|2458535.6169| 2073505.9999|
             282|     |José     |Edvaldo   |Saraiva          |      |Sales Representative        |185-555-0169       |Work           |josé[email protected]   |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |Canada        |North America |    250000|2604540.7172| 2038234.6549|
             283|     |David    |R         |Campbell         |      |Sales Representative        |740-555-0182       |Work           |[email protected]  |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |Northwest     |North America |    250000|1573012.9383| 1371635.3158|
             284|Mr.  |Tete     |A         |Mensa-Annan      |      |Sales Representative        |615-555-0153       |Work           |[email protected]   |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |Northwest     |North America |    300000|1576562.1966|            0|
             285|Mr.  |Syed     |E         |Abbas            |      |Pacific Sales Manager       |926-555-0182       |Work           |[email protected]   |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |              |              |          | 172524.4512|            0|
             286|     |Lynn     |N         |Tsoflias         |      |Sales Representative        |1 (11) 500 555-0190|Cell           |[email protected]   |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |Australia     |Pacific       |    250000|1421810.9242| 2278548.9776|
             287|     |Amy      |E         |Alberts          |      |European Sales Manager      |775-555-0164       |Work           |[email protected]    |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |              |              |          |  519905.932|            0|
             288|     |Rachel   |B         |Valdez           |      |Sales Representative        |1 (11) 500 555-0140|Cell           |[email protected] |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |Germany       |Europe        |    250000|1827066.7118| 1307949.7917|
             289|     |Jae      |B         |Pak              |      |Sales Representative        |1 (11) 500 555-0145|Work           |[email protected]    |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |United Kingdom|Europe        |    250000|4116871.2277| 1635823.3967|
             290|     |Ranjit   |R         |Varkey Chudukatil|      |Sales Representative        |1 (11) 500 555-0117|Cell           |[email protected] |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |France        |Europe        |    250000|3121616.3202| 2396539.7601|

Click to view Full table

Sample Output:

territoryname|businessentityid|salesytd    |nextrepsales|
-------------+----------------+------------+------------+
Canada       |             282|2604540.7172|1453719.4653|
Canada       |             278|1453719.4653|           0|
Northwest    |             284|1576562.1966|1573012.9383|
Northwest    |             283|1573012.9383|1352577.1325|
Northwest    |             280|1352577.1325|           0|

Click me to see the solution

111. From the following table, write a query in SQL to return the sales year, sales quarter, current sales quota, the next quarter's sales quota, and the difference between the current and next quarter's sales quotas for a specific salesperson. Filter the results for the salesperson with BusinessEntityID 277 for the years 2012 and 2013.

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

year  |quarter|salesquota|nextquota|diff   |
------+-------+----------+---------+-------+
2012.0|    1.0|    952000|  1600000|-648000|
2012.0|    2.0|   1600000|  1352000| 248000|
2012.0|    3.0|   1352000|   839000| 513000|
2012.0|    4.0|    839000|  1369000|-530000|
2013.0|    1.0|   1369000|  1171000| 198000|
2013.0|    2.0|   1171000|   971000| 200000|
2013.0|    3.0|    971000|   714000| 257000|

Click me to see the solution

112. From the following table write a query in SQL to compute the salary percentile for each employee for departments 'Information Services' and 'Document Control'. Return Department, LastName, Rate, CumeDist, and percentile rank. Sort the result set in ascending order on department and descending order on rate.

N.B.: The cumulative distribution calculates the relative position of a specified value in a group of values.

Sample table: HumanResources.vEmployeeDepartmentHistory
businessentityid|title|firstname  |middlename      |lastname         |suffix|shift  |department                |groupname                           |startdate |enddate   |
----------------+-----+-----------+----------------+-----------------+------+-------+--------------------------+------------------------------------+----------+----------+
               1|     |Ken        |J               |Sánchez          |      |Day    |Executive                 |Executive General and Administration|2009-01-14|          |
               2|     |Terri      |Lee             |Duffy            |      |Day    |Engineering               |Research and Development            |2008-01-31|          |
               3|     |Roberto    |                |Tamburello       |      |Day    |Engineering               |Research and Development            |2007-11-11|          |
               4|     |Rob        |                |Walters          |      |Day    |Engineering               |Research and Development            |2007-12-05|2010-05-30|
               4|     |Rob        |                |Walters          |      |Day    |Tool Design               |Research and Development            |2010-05-31|          |
               5|Ms.  |Gail       |A               |Erickson         |      |Day    |Engineering               |Research and Development            |2008-01-06|          |
               6|Mr.  |Jossef     |H               |Goldberg         |      |Day    |Engineering               |Research and Development            |2008-01-24|          |
               7|     |Dylan      |A               |Miller           |      |Day    |Research and Development  |Research and Development            |2009-02-08|          |
               8|     |Diane      |L               |Margheim         |      |Day    |Research and Development  |Research and Development            |2008-12-29|          |
               9|     |Gigi       |N               |Matthew          |      |Day    |Research and Development  |Research and Development            |2009-01-16|          |
              10|     |Michael    |                |Raheem           |      |Day    |Research and Development  |Research and Development            |2009-05-03|          |
			-- more --

Click to view Full table

Sample Output:

department          |lastname     |rate   |cumedist|pctrank           |
--------------------+-------------+-------+--------+------------------+
Document Control    |Arifin       |17.7885|     1.0|               1.0|
Document Control    |Kharatishvili|16.8269|     0.8|               0.5|
Document Control    |Norred       |16.8269|     0.8|               0.5|
Document Control    |Chai         |  10.25|     0.4|               0.0|
Document Control    |Berge        |  10.25|     0.4|               0.0|
Information Services|Trenary      |50.4808|     1.0|               1.0|
Information Services|Conroy       |39.6635|     0.9|0.8888888888888888|
Information Services|Ajenstat     |38.4615|     0.8|0.6666666666666666|
Information Services|Wilson       |38.4615|     0.8|0.6666666666666666|
Information Services|Sharma       |32.4519|     0.6|0.4444444444444444|
Information Services|Connelly     |32.4519|     0.6|0.4444444444444444|
Information Services|Bueno        |27.4038|     0.4|               0.0|
Information Services|Meyyappan    |27.4038|     0.4|               0.0|
Information Services|Bacon        |27.4038|     0.4|               0.0|
Information Services|Berg         |27.4038|     0.4|               0.0|

Click me to see the solution

113. From the following table write a query in SQL to add two days to each value in the OrderDate column, to derive a new column named PromisedShipDate. Return salesorderid, orderdate, and promisedshipdate column.

Sample table: sales.salesorderheader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|orderdate              |promisedshipdate       |
------------+-----------------------+-----------------------+
       43659|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43660|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43661|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43662|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43663|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43664|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43665|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43666|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43667|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43668|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
       43669|2011-05-31 00:00:00.000|2011-06-02 00:00:00.000|
...	

Click me to see the solution

114. From the following table write a query in SQL to obtain a newdate by adding two days with current date for each salespersons. Filter the result set for those salespersons whose sales value is more than zero.

Sample table: Sales.SalesPerson
businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Person.Address
|addressid|addressline1              |addressline2|city         |stateprovinceid|postalcode|spatiallocation                             |rowguid                             |modifieddate           |
|---------|--------------------------|------------|-------------|---------------|----------|--------------------------------------------|------------------------------------|-----------------------|
|1        |1970 Napa Ct.             |            |Bothell      |79             |98011     |E6100000010CAE8BFC28BCE4474067A89189898A5EC0|9aadcb0d-36cf-483f-84d8-585c2d4ec6e9|2007-12-04 00:00:00.000|
|2        |9833 Mt. Dias Blv.        |            |Bothell      |79             |98011     |E6100000010CD6FA851AE6D74740BC262A0A03905EC0|32a54b9e-e034-4bfb-b573-a71cde60d8c0|2008-11-30 00:00:00.000|
|3        |7484 Roundtree Drive      |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE14740DA930C7893915EC0|4c506923-6d1b-452c-a07c-baa6f5b142a4|2013-03-07 00:00:00.000|
|4        |9539 Glenside Dr          |            |Bothell      |79             |98011     |E6100000010C813A0D5F9FDE474011A5C28A7C955EC0|e5946c78-4bcc-477f-9fa1-cc09de16a880|2009-02-03 00:00:00.000|
|5        |1226 Shoe St.             |            |Bothell      |79             |98011     |E6100000010C61C64D8ABBD94740C460EA3FD8855EC0|fbaff937-4a97-4af0-81fd-b849900e9bb0|2008-12-19 00:00:00.000|
|6        |1399 Firestone Drive      |            |Bothell      |79             |98011     |E6100000010CE0B4E50458DA47402F12A5F80C975EC0|febf8191-9804-44c8-877a-33fde94f0075|2009-02-13 00:00:00.000|
|7        |5672 Hale Dr.             |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE1474011A5C28A7C955EC0|0175a174-6c34-4d41-b3c1-4419cd6a0446|2009-12-11 00:00:00.000|
|8        |6387 Scenic Avenue        |            |Bothell      |79             |98011     |E6100000010C0029A5D93BDF4740E248962FD5975EC0|3715e813-4dca-49e0-8f1c-31857d21f269|2008-12-17 00:00:00.000|
|9        |8713 Yosemite Ct.         |            |Bothell      |79             |98011     |E6100000010C6A80AD742DDC4740851574F7198C5EC0|268af621-76d7-4c78-9441-144fd139821a|2012-05-30 00:00:00.000|
|10       |250 Race Court            |            |Bothell      |79             |98011     |E6100000010C219D64AE1FE4474040862564B7825EC0|0b6b739d-8eb6-4378-8d55-fe196af34c04|2008-12-02 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

firstname|lastname         |New Date                     |
---------+-----------------+-----------------------------+
Michael  |Blythe           |2022-11-02 14:28:09.304 +0530|
Linda    |Mitchell         |2022-11-02 14:28:09.304 +0530|
Jillian  |Carson           |2022-11-02 14:28:09.304 +0530|
Garrett  |Vargas           |2022-11-02 14:28:09.304 +0530|
Tsvi     |Reiter           |2022-11-02 14:28:09.304 +0530|
Pamela   |Ansman-Wolfe     |2022-11-02 14:28:09.304 +0530|
Shu      |Ito              |2022-11-02 14:28:09.304 +0530|
José     |Saraiva          |2022-11-02 14:28:09.304 +0530|
David    |Campbell         |2022-11-02 14:28:09.304 +0530|
Tete     |Mensa-Annan      |2022-11-02 14:28:09.304 +0530|
Lynn     |Tsoflias         |2022-11-02 14:28:09.304 +0530|
Rachel   |Valdez           |2022-11-02 14:28:09.304 +0530|
Jae      |Pak              |2022-11-02 14:28:09.304 +0530|
Ranjit   |Varkey Chudukatil|2022-11-02 14:28:09.304 +0530|

Click me to see the solution

115. From the following table write a query in SQL to find the differences between the maximum and minimum orderdate.

Sample table: Sales.SalesOrderHeader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

?column? |
---------+
1126 days|

Click me to see the solution

116. From the following table write a query in SQL to rank the products in inventory, by the inventory locationID values between 3 and 4, according to their quantities. Divide the result set by LocationID and sort the result set on Quantity in descending order.

Sample table: Production.ProductInventory
productid|locationid|shelf|bin|quantity|rowguid                             |modifieddate           |
---------+----------+-----+---+--------+------------------------------------+-----------------------+
        1|         1|A    |  1|     408|47a24246-6c43-48eb-968f-025738a8a410|2014-08-08 00:00:00.000|
        1|         6|B    |  5|     324|d4544d7d-caf5-46b3-ab22-5718dcc26b5e|2014-08-08 00:00:00.000|
        1|        50|A    |  5|     353|bff7dc60-96a8-43ca-81a7-d6d2ed3000a8|2014-08-08 00:00:00.000|
        2|         1|A    |  2|     427|f407c07a-ca14-4684-a02c-608bd00c2233|2014-08-08 00:00:00.000|
        2|         6|B    |  1|     318|ca1ff2f4-48fb-4960-8d92-3940b633e4c1|2014-08-08 00:00:00.000|
        2|        50|A    |  6|     364|d38cfbee-6347-47b1-b033-0e278cca03e2|2014-08-08 00:00:00.000|
        3|         1|A    |  7|     585|e18a519b-fb5e-4051-874c-58cd58436c95|2008-03-31 00:00:00.000|
        3|         6|B    |  9|     443|3c860c96-15ff-4df4-91d7-b237ff64480f|2008-03-31 00:00:00.000|
        3|        50|A    | 10|     324|1339e5e3-1f8e-4b82-a447-a8666a264f0c|2008-03-31 00:00:00.000|
        4|         1|A    |  6|     512|6beaf0a0-971a-4ce1-96fe-692807d5dc00|2014-08-08 00:00:00.000|
        4|         6|B    | 10|     422|2c82427a-63f1-4877-a1f6-a27b4d201eb6|2014-08-08 00:00:00.000|
        4|        50|A    | 11|     388|fd912e69-efa2-4ab7-82a4-03f5101af11c|2014-08-08 00:00:00.000|
      316|         5|A    | 11|     532|1ee3dbd3-2a7e-47dc-af99-1b585575efb9|2008-03-31 00:00:00.000|
	  -- more --

Click to view Full table

Sample Output:

productid|name          |locationid|quantity|rank|
---------+--------------+----------+--------+----+
      495|Paint - Blue  |         3|      49|   1|
      494|Paint - Silver|         3|      49|   1|
      493|Paint - Red   |         3|      41|   2|
      496|Paint - Yellow|         3|      30|   3|
      492|Paint - Black |         3|      17|   4|
      495|Paint - Blue  |         4|      35|   1|
      496|Paint - Yellow|         4|      25|   2|
      493|Paint - Red   |         4|      24|   3|
      492|Paint - Black |         4|      14|   4|
      494|Paint - Silver|         4|      12|   5| 

Click me to see the solution

117. From the following table write a query in SQL to return the top ten employees ranked by their salary.

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|rate   |rankbysalary|
----------------+-------+------------+
               1|  125.5|           1|
              25|84.1346|           2|
             273|72.1154|           3|
               2|63.4615|           4|
             234|60.0962|           5|
             263|50.4808|           6|
               7|50.4808|           6|
             234|48.5577|           7|
             287| 48.101|           8|
             274| 48.101|           8|

Click me to see the solution

118. From the following table write a query in SQL to divide rows into four groups of employees based on their year-to-date sales. Return first name, last name, group as quartile, year-to-date sales, and postal code.

Sample table: Sales.SalesPerson
businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Person.Address
|addressid|addressline1              |addressline2|city         |stateprovinceid|postalcode|spatiallocation                             |rowguid                             |modifieddate           |
|---------|--------------------------|------------|-------------|---------------|----------|--------------------------------------------|------------------------------------|-----------------------|
|1        |1970 Napa Ct.             |            |Bothell      |79             |98011     |E6100000010CAE8BFC28BCE4474067A89189898A5EC0|9aadcb0d-36cf-483f-84d8-585c2d4ec6e9|2007-12-04 00:00:00.000|
|2        |9833 Mt. Dias Blv.        |            |Bothell      |79             |98011     |E6100000010CD6FA851AE6D74740BC262A0A03905EC0|32a54b9e-e034-4bfb-b573-a71cde60d8c0|2008-11-30 00:00:00.000|
|3        |7484 Roundtree Drive      |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE14740DA930C7893915EC0|4c506923-6d1b-452c-a07c-baa6f5b142a4|2013-03-07 00:00:00.000|
|4        |9539 Glenside Dr          |            |Bothell      |79             |98011     |E6100000010C813A0D5F9FDE474011A5C28A7C955EC0|e5946c78-4bcc-477f-9fa1-cc09de16a880|2009-02-03 00:00:00.000|
|5        |1226 Shoe St.             |            |Bothell      |79             |98011     |E6100000010C61C64D8ABBD94740C460EA3FD8855EC0|fbaff937-4a97-4af0-81fd-b849900e9bb0|2008-12-19 00:00:00.000|
|6        |1399 Firestone Drive      |            |Bothell      |79             |98011     |E6100000010CE0B4E50458DA47402F12A5F80C975EC0|febf8191-9804-44c8-877a-33fde94f0075|2009-02-13 00:00:00.000|
|7        |5672 Hale Dr.             |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE1474011A5C28A7C955EC0|0175a174-6c34-4d41-b3c1-4419cd6a0446|2009-12-11 00:00:00.000|
|8        |6387 Scenic Avenue        |            |Bothell      |79             |98011     |E6100000010C0029A5D93BDF4740E248962FD5975EC0|3715e813-4dca-49e0-8f1c-31857d21f269|2008-12-17 00:00:00.000|
|9        |8713 Yosemite Ct.         |            |Bothell      |79             |98011     |E6100000010C6A80AD742DDC4740851574F7198C5EC0|268af621-76d7-4c78-9441-144fd139821a|2012-05-30 00:00:00.000|
|10       |250 Race Court            |            |Bothell      |79             |98011     |E6100000010C219D64AE1FE4474040862564B7825EC0|0b6b739d-8eb6-4378-8d55-fe196af34c04|2008-12-02 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

firstname|lastname         |quartile|salesytd    |postalcode|
---------+-----------------+--------+------------+----------+
Linda    |Mitchell         |       1|4251368.5497|98027     |
Jae      |Pak              |       1|4116871.2277|98055     |
Michael  |Blythe           |       1|3763178.1787|98027     |
Jillian  |Carson           |       1|3189418.3662|98027     |
Ranjit   |Varkey Chudukatil|       2|3121616.3202|98055     |
José     |Saraiva          |       2|2604540.7172|98055     |
Shu      |Ito              |       2|2458535.6169|98055     |
Tsvi     |Reiter           |       2|2315185.611 |98027     |
Rachel   |Valdez           |       3|1827066.7118|98055     |
Tete     |Mensa-Annan      |       3|1576562.1966|98055     |
David    |Campbell         |       3|1573012.9383|98055     |
Garrett  |Vargas           |       4|1453719.4653|98027     |
Lynn     |Tsoflias         |       4|1421810.9242|98055     |
Pamela   |Ansman-Wolfe     |       4|1352577.1325|98027     |

Click me to see the solution

119. From the following tables write a query in SQL to rank the products in inventory with locationID values between 3 and 4 according to their quantities. The result set is partitioned by LocationID and logically ordered by Quantity. Return productid, name, locationid, quantity, and rank.

Sample table: production.productinventory
productid|locationid|shelf|bin|quantity|rowguid                             |modifieddate           |
---------+----------+-----+---+--------+------------------------------------+-----------------------+
        1|         1|A    |  1|     408|47a24246-6c43-48eb-968f-025738a8a410|2014-08-08 00:00:00.000|
        1|         6|B    |  5|     324|d4544d7d-caf5-46b3-ab22-5718dcc26b5e|2014-08-08 00:00:00.000|
        1|        50|A    |  5|     353|bff7dc60-96a8-43ca-81a7-d6d2ed3000a8|2014-08-08 00:00:00.000|
        2|         1|A    |  2|     427|f407c07a-ca14-4684-a02c-608bd00c2233|2014-08-08 00:00:00.000|
        2|         6|B    |  1|     318|ca1ff2f4-48fb-4960-8d92-3940b633e4c1|2014-08-08 00:00:00.000|
        2|        50|A    |  6|     364|d38cfbee-6347-47b1-b033-0e278cca03e2|2014-08-08 00:00:00.000|
        3|         1|A    |  7|     585|e18a519b-fb5e-4051-874c-58cd58436c95|2008-03-31 00:00:00.000|
        3|         6|B    |  9|     443|3c860c96-15ff-4df4-91d7-b237ff64480f|2008-03-31 00:00:00.000|
        3|        50|A    | 10|     324|1339e5e3-1f8e-4b82-a447-a8666a264f0c|2008-03-31 00:00:00.000|
        4|         1|A    |  6|     512|6beaf0a0-971a-4ce1-96fe-692807d5dc00|2014-08-08 00:00:00.000|
        4|         6|B    | 10|     422|2c82427a-63f1-4877-a1f6-a27b4d201eb6|2014-08-08 00:00:00.000|
        4|        50|A    | 11|     388|fd912e69-efa2-4ab7-82a4-03f5101af11c|2014-08-08 00:00:00.000|
      316|         5|A    | 11|     532|1ee3dbd3-2a7e-47dc-af99-1b585575efb9|2008-03-31 00:00:00.000|
	  -- more --

Click to view Full table

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|name          |locationid|quantity|rank|
---------+--------------+----------+--------+----+
      495|Paint - Blue  |         3|      49|   1|
      494|Paint - Silver|         3|      49|   1|
      493|Paint - Red   |         3|      41|   3|
      496|Paint - Yellow|         3|      30|   4|
      492|Paint - Black |         3|      17|   5|
      495|Paint - Blue  |         4|      35|   1|
      496|Paint - Yellow|         4|      25|   2|
      493|Paint - Red   |         4|      24|   3|
      492|Paint - Black |         4|      14|   4|
      494|Paint - Silver|         4|      12|   5| 

Click me to see the solution

120. From the following table write a query in SQL to find the salary of top ten employees. Return BusinessEntityID, Rate, and rank of employees by salary.

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|rate   |rankbysalary|
----------------+-------+------------+
               1|  125.5|           1|
               2|63.4615|           4|
               3|43.2692|          11|
               4|29.8462|          28|
               5|32.6923|          22|
               6|32.6923|          22|
               7|50.4808|           6|
               8|40.8654|          14|
               9|40.8654|          14|
              10|42.4808|          13| 

Click me to see the solution

121. From the following table write a query in SQL to calculate a row number for the salespeople based on their year-to-date sales ranking. Return row number, first name, last name, and year-to-date sales.

Sample table: Sales.vSalesPerson
businessentityid|title|firstname|middlename|lastname         |suffix|jobtitle                    |phonenumber        |phonenumbertype|emailaddress                |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|territoryname |territorygroup|salesquota|salesytd    |saleslastyear|
----------------+-----+---------+----------+-----------------+------+----------------------------+-------------------+---------------+----------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+--------------+--------------+----------+------------+-------------+
             274|     |Stephen  |Y         |Jiang            |      |North American Sales Manager|238-555-0197       |Cell           |[email protected]|             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |              |              |          | 559697.5639|            0|
             275|     |Michael  |G         |Blythe           |      |Sales Representative        |257-555-0154       |Cell           |[email protected]|             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |Northeast     |North America |    300000|3763178.1787| 1750406.4785|
             276|     |Linda    |C         |Mitchell         |      |Sales Representative        |883-555-0116       |Work           |[email protected]  |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |Southwest     |North America |    250000|4251368.5497| 1439156.0291|
             277|     |Jillian  |          |Carson           |      |Sales Representative        |517-555-0117       |Work           |[email protected]|             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |Central       |North America |    250000|3189418.3662| 1997186.2037|
             278|     |Garrett  |R         |Vargas           |      |Sales Representative        |922-555-0165       |Work           |[email protected]|             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |Canada        |North America |    250000|1453719.4653| 1620276.8966|
             279|     |Tsvi     |Michael   |Reiter           |      |Sales Representative        |664-555-0112       |Work           |[email protected]   |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |Southeast     |North America |    300000| 2315185.611| 1849640.9418|
             280|     |Pamela   |O         |Ansman-Wolfe     |      |Sales Representative        |340-555-0193       |Cell           |[email protected] |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |Northwest     |North America |    250000|1352577.1325|  1927059.178|
             281|     |Shu      |K         |Ito              |      |Sales Representative        |330-555-0120       |Cell           |[email protected]    |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |Southwest     |North America |    250000|2458535.6169| 2073505.9999|
             282|     |José     |Edvaldo   |Saraiva          |      |Sales Representative        |185-555-0169       |Work           |josé[email protected]   |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |Canada        |North America |    250000|2604540.7172| 2038234.6549|
             283|     |David    |R         |Campbell         |      |Sales Representative        |740-555-0182       |Work           |[email protected]  |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |Northwest     |North America |    250000|1573012.9383| 1371635.3158|
             284|Mr.  |Tete     |A         |Mensa-Annan      |      |Sales Representative        |615-555-0153       |Work           |[email protected]   |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |Northwest     |North America |    300000|1576562.1966|            0|
             285|Mr.  |Syed     |E         |Abbas            |      |Pacific Sales Manager       |926-555-0182       |Work           |[email protected]   |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |              |              |          | 172524.4512|            0|
             286|     |Lynn     |N         |Tsoflias         |      |Sales Representative        |1 (11) 500 555-0190|Cell           |[email protected]   |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |Australia     |Pacific       |    250000|1421810.9242| 2278548.9776|
             287|     |Amy      |E         |Alberts          |      |European Sales Manager      |775-555-0164       |Work           |[email protected]    |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |              |              |          |  519905.932|            0|
             288|     |Rachel   |B         |Valdez           |      |Sales Representative        |1 (11) 500 555-0140|Cell           |[email protected] |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |Germany       |Europe        |    250000|1827066.7118| 1307949.7917|
             289|     |Jae      |B         |Pak              |      |Sales Representative        |1 (11) 500 555-0145|Work           |[email protected]    |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |United Kingdom|Europe        |    250000|4116871.2277| 1635823.3967|
             290|     |Ranjit   |R         |Varkey Chudukatil|      |Sales Representative        |1 (11) 500 555-0117|Cell           |[email protected] |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |France        |Europe        |    250000|3121616.3202| 2396539.7601|

Click to view Full table

Sample Output:

row|firstname|lastname         |Sales YTD |
---+---------+-----------------+----------+
  1|Linda    |Mitchell         |4251368.55|
  2|Jae      |Pak              |4116871.23|
  3|Michael  |Blythe           |3763178.18|
  4|Jillian  |Carson           |3189418.37|
  5|Ranjit   |Varkey Chudukatil|3121616.32|
  6|José     |Saraiva          |2604540.72|
  7|Shu      |Ito              |2458535.62|
  8|Tsvi     |Reiter           |2315185.61|
  9|Rachel   |Valdez           |1827066.71|
 10|Tete     |Mensa-Annan      |1576562.20|
 11|David    |Campbell         |1573012.94|
 12|Garrett  |Vargas           |1453719.47|
 13|Lynn     |Tsoflias         |1421810.92|
 14|Pamela   |Ansman-Wolfe     |1352577.13| 

Click me to see the solution

122. From the following table write a query in SQL to calculate row numbers for all rows between 50 to 60 inclusive. Sort the result set on orderdate.

Sample table: Sales.SalesOrderHeader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|orderdate              |rownumber|
------------+-----------------------+---------+
       43708|2011-06-02 00:00:00.000|       50|
       43709|2011-06-02 00:00:00.000|       51|
       43710|2011-06-02 00:00:00.000|       52|
       43711|2011-06-03 00:00:00.000|       53|
       43712|2011-06-03 00:00:00.000|       54|
       43713|2011-06-04 00:00:00.000|       55|
       43714|2011-06-04 00:00:00.000|       56|
       43715|2011-06-04 00:00:00.000|       57|
       43716|2011-06-04 00:00:00.000|       58|
       43717|2011-06-04 00:00:00.000|       59|
       43718|2011-06-05 00:00:00.000|       60|

Click me to see the solution

123. From the following table write a query in SQL to return first name, last name, territoryname, salesytd, and row number. Partition the query result set by the TerritoryName. Orders the rows in each partition by SalesYTD. Sort the result set on territoryname in ascending order.

Sample table: Sales.vSalesPerson
businessentityid|title|firstname|middlename|lastname         |suffix|jobtitle                    |phonenumber        |phonenumbertype|emailaddress                |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|territoryname |territorygroup|salesquota|salesytd    |saleslastyear|
----------------+-----+---------+----------+-----------------+------+----------------------------+-------------------+---------------+----------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+--------------+--------------+----------+------------+-------------+
             274|     |Stephen  |Y         |Jiang            |      |North American Sales Manager|238-555-0197       |Cell           |[email protected]|             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |              |              |          | 559697.5639|            0|
             275|     |Michael  |G         |Blythe           |      |Sales Representative        |257-555-0154       |Cell           |[email protected]|             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |Northeast     |North America |    300000|3763178.1787| 1750406.4785|
             276|     |Linda    |C         |Mitchell         |      |Sales Representative        |883-555-0116       |Work           |[email protected]  |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |Southwest     |North America |    250000|4251368.5497| 1439156.0291|
             277|     |Jillian  |          |Carson           |      |Sales Representative        |517-555-0117       |Work           |[email protected]|             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |Central       |North America |    250000|3189418.3662| 1997186.2037|
             278|     |Garrett  |R         |Vargas           |      |Sales Representative        |922-555-0165       |Work           |[email protected]|             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |Canada        |North America |    250000|1453719.4653| 1620276.8966|
             279|     |Tsvi     |Michael   |Reiter           |      |Sales Representative        |664-555-0112       |Work           |[email protected]   |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |Southeast     |North America |    300000| 2315185.611| 1849640.9418|
             280|     |Pamela   |O         |Ansman-Wolfe     |      |Sales Representative        |340-555-0193       |Cell           |[email protected] |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |Northwest     |North America |    250000|1352577.1325|  1927059.178|
             281|     |Shu      |K         |Ito              |      |Sales Representative        |330-555-0120       |Cell           |[email protected]    |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |Southwest     |North America |    250000|2458535.6169| 2073505.9999|
             282|     |José     |Edvaldo   |Saraiva          |      |Sales Representative        |185-555-0169       |Work           |josé[email protected]   |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |Canada        |North America |    250000|2604540.7172| 2038234.6549|
             283|     |David    |R         |Campbell         |      |Sales Representative        |740-555-0182       |Work           |[email protected]  |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |Northwest     |North America |    250000|1573012.9383| 1371635.3158|
             284|Mr.  |Tete     |A         |Mensa-Annan      |      |Sales Representative        |615-555-0153       |Work           |[email protected]   |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |Northwest     |North America |    300000|1576562.1966|            0|
             285|Mr.  |Syed     |E         |Abbas            |      |Pacific Sales Manager       |926-555-0182       |Work           |[email protected]   |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |              |              |          | 172524.4512|            0|
             286|     |Lynn     |N         |Tsoflias         |      |Sales Representative        |1 (11) 500 555-0190|Cell           |[email protected]   |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |Australia     |Pacific       |    250000|1421810.9242| 2278548.9776|
             287|     |Amy      |E         |Alberts          |      |European Sales Manager      |775-555-0164       |Work           |[email protected]    |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |              |              |          |  519905.932|            0|
             288|     |Rachel   |B         |Valdez           |      |Sales Representative        |1 (11) 500 555-0140|Cell           |[email protected] |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |Germany       |Europe        |    250000|1827066.7118| 1307949.7917|
             289|     |Jae      |B         |Pak              |      |Sales Representative        |1 (11) 500 555-0145|Work           |[email protected]    |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |United Kingdom|Europe        |    250000|4116871.2277| 1635823.3967|
             290|     |Ranjit   |R         |Varkey Chudukatil|      |Sales Representative        |1 (11) 500 555-0117|Cell           |[email protected] |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |France        |Europe        |    250000|3121616.3202| 2396539.7601|

Click to view Full table

Sample Output:

firstname|lastname         |territoryname |salesytd  |row|
---------+-----------------+--------------+----------+---+
Lynn     |Tsoflias         |Australia     |1421810.92|  1|
José     |Saraiva          |Canada        |2604540.72|  1|
Garrett  |Vargas           |Canada        |1453719.47|  2|
Jillian  |Carson           |Central       |3189418.37|  1|
Ranjit   |Varkey Chudukatil|France        |3121616.32|  1|
Rachel   |Valdez           |Germany       |1827066.71|  1|
Michael  |Blythe           |Northeast     |3763178.18|  1|
Tete     |Mensa-Annan      |Northwest     |1576562.20|  1|
David    |Campbell         |Northwest     |1573012.94|  2|
Pamela   |Ansman-Wolfe     |Northwest     |1352577.13|  3|
Tsvi     |Reiter           |Southeast     |2315185.61|  1|
Linda    |Mitchell         |Southwest     |4251368.55|  1|
Shu      |Ito              |Southwest     |2458535.62|  2|
Jae      |Pak              |United Kingdom|4116871.23|  1|

Click me to see the solution

124. From the following table write a query in SQL to order the result set by the column TerritoryName when the column CountryRegionName is equal to 'United States' and by CountryRegionName for all other rows. Return BusinessEntityID, LastName, TerritoryName, CountryRegionName.

Sample table: Sales.vSalesPerson
businessentityid|title|firstname|middlename|lastname         |suffix|jobtitle                    |phonenumber        |phonenumbertype|emailaddress                |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|territoryname |territorygroup|salesquota|salesytd    |saleslastyear|
----------------+-----+---------+----------+-----------------+------+----------------------------+-------------------+---------------+----------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+--------------+--------------+----------+------------+-------------+
             274|     |Stephen  |Y         |Jiang            |      |North American Sales Manager|238-555-0197       |Cell           |[email protected]|             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |              |              |          | 559697.5639|            0|
             275|     |Michael  |G         |Blythe           |      |Sales Representative        |257-555-0154       |Cell           |[email protected]|             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |Northeast     |North America |    300000|3763178.1787| 1750406.4785|
             276|     |Linda    |C         |Mitchell         |      |Sales Representative        |883-555-0116       |Work           |[email protected]  |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |Southwest     |North America |    250000|4251368.5497| 1439156.0291|
             277|     |Jillian  |          |Carson           |      |Sales Representative        |517-555-0117       |Work           |[email protected]|             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |Central       |North America |    250000|3189418.3662| 1997186.2037|
             278|     |Garrett  |R         |Vargas           |      |Sales Representative        |922-555-0165       |Work           |[email protected]|             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |Canada        |North America |    250000|1453719.4653| 1620276.8966|
             279|     |Tsvi     |Michael   |Reiter           |      |Sales Representative        |664-555-0112       |Work           |[email protected]   |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |Southeast     |North America |    300000| 2315185.611| 1849640.9418|
             280|     |Pamela   |O         |Ansman-Wolfe     |      |Sales Representative        |340-555-0193       |Cell           |[email protected] |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |Northwest     |North America |    250000|1352577.1325|  1927059.178|
             281|     |Shu      |K         |Ito              |      |Sales Representative        |330-555-0120       |Cell           |[email protected]    |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |Southwest     |North America |    250000|2458535.6169| 2073505.9999|
             282|     |José     |Edvaldo   |Saraiva          |      |Sales Representative        |185-555-0169       |Work           |josé[email protected]   |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |Canada        |North America |    250000|2604540.7172| 2038234.6549|
             283|     |David    |R         |Campbell         |      |Sales Representative        |740-555-0182       |Work           |[email protected]  |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |Northwest     |North America |    250000|1573012.9383| 1371635.3158|
             284|Mr.  |Tete     |A         |Mensa-Annan      |      |Sales Representative        |615-555-0153       |Work           |[email protected]   |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |Northwest     |North America |    300000|1576562.1966|            0|
             285|Mr.  |Syed     |E         |Abbas            |      |Pacific Sales Manager       |926-555-0182       |Work           |[email protected]   |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |              |              |          | 172524.4512|            0|
             286|     |Lynn     |N         |Tsoflias         |      |Sales Representative        |1 (11) 500 555-0190|Cell           |[email protected]   |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |Australia     |Pacific       |    250000|1421810.9242| 2278548.9776|
             287|     |Amy      |E         |Alberts          |      |European Sales Manager      |775-555-0164       |Work           |[email protected]    |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |              |              |          |  519905.932|            0|
             288|     |Rachel   |B         |Valdez           |      |Sales Representative        |1 (11) 500 555-0140|Cell           |[email protected] |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |Germany       |Europe        |    250000|1827066.7118| 1307949.7917|
             289|     |Jae      |B         |Pak              |      |Sales Representative        |1 (11) 500 555-0145|Work           |[email protected]    |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |United Kingdom|Europe        |    250000|4116871.2277| 1635823.3967|
             290|     |Ranjit   |R         |Varkey Chudukatil|      |Sales Representative        |1 (11) 500 555-0117|Cell           |[email protected] |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |France        |Europe        |    250000|3121616.3202| 2396539.7601|

Click to view Full table

Sample Output:

businessentityid|lastname         |territoryname |countryregionname|
----------------+-----------------+--------------+-----------------+
             286|Tsoflias         |Australia     |Australia        |
             282|Saraiva          |Canada        |Canada           |
             278|Vargas           |Canada        |Canada           |
             277|Carson           |Central       |United States    |
             290|Varkey Chudukatil|France        |France           |
             288|Valdez           |Germany       |Germany          |
             275|Blythe           |Northeast     |United States    |
             280|Ansman-Wolfe     |Northwest     |United States    |
             284|Mensa-Annan      |Northwest     |United States    |
             283|Campbell         |Northwest     |United States    |
             279|Reiter           |Southeast     |United States    |
             276|Mitchell         |Southwest     |United States    |
             281|Ito              |Southwest     |United States    |
             289|Pak              |United Kingdom|United Kingdom   |

Click me to see the solution

125. From the following tables write a query in SQL to return the highest hourly wage for each job title. Restricts the titles to those that are held by men with a maximum pay rate greater than 40 dollars or women with a maximum pay rate greater than 42 dollars.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

jobtitle                        |maximumrate|
--------------------------------+-----------+
Chief Executive Officer         |      125.5|
Vice President of Production    |    84.1346|
Vice President of Sales         |    72.1154|
Vice President of Engineering   |    63.4615|
Chief Financial Officer         |    60.0962|
Research and Development Manager|    50.4808|
Information Services Manager    |    50.4808|
North American Sales Manager    |     48.101|
Pacific Sales Manager           |     48.101|
European Sales Manager          |     48.101|
Engineering Manager             |    43.2692|
Finance Manager                 |    43.2692|

Click me to see the solution

126. From the following table write a query in SQL to sort the BusinessEntityID in descending order for those employees that have the SalariedFlag set to 'true' and in ascending order that have the SalariedFlag set to 'false'. Return BusinessEntityID, and SalariedFlag.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

businessentityid|salariedflag|
----------------+------------+
               4|false       |
              11|false       |
              12|false       |
              13|false       |
              17|false       |
              18|false       |
              19|false       |
              20|false       |
              21|false       |
              22|false       |
              23|false       |
              24|false       |
...			  

Click me to see the solution

127. From the following table write a query in SQL to display the list price as a text comment based on the price range for a product. Return ProductNumber, Name, and listprice. Sort the result set on ProductNumber in ascending order.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productnumber|name                            |listprice|Price Range              |
-------------+--------------------------------+---------+-------------------------+
AR-5381      |Adjustable Race                 |        0|Mfg item - not for resale|
BA-8327      |Bearing Ball                    |        0|Mfg item - not for resale|
BB-7421      |LL Bottom Bracket               |    53.99|Under $250               |
BB-8107      |ML Bottom Bracket               |   101.24|Under $250               |
BB-9108      |HL Bottom Bracket               |   121.49|Under $250               |
BC-M005      |Mountain Bottle Cage            |     9.99|Under $50                |
BC-R205      |Road Bottle Cage                |     8.99|Under $50                |
BE-2349      |BB Ball Bearing                 |        0|Mfg item - not for resale|
BE-2908      |Headset Ball Bearings           |        0|Mfg item - not for resale|
BK-M18B-40   |Mountain-500 Black, 40          |   539.99|Under $1000              |
BK-M18B-42   |Mountain-500 Black, 42          |   539.99|Under $1000              |
BK-M18B-44   |Mountain-500 Black, 44          |   539.99|Under $1000              |
BK-M18B-48   |Mountain-500 Black, 48          |   539.99|Under $1000              |
BK-M18B-52   |Mountain-500 Black, 52          |   539.99|Under $1000              |
...

Click me to see the solution

128. From the following table write a query in SQL to change the display of product line categories to make them more understandable. Return ProductNumber, category, and name of the product. Sort the result set in ascending order on ProductNumber.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productnumber|Category        |name                            |
-------------+----------------+--------------------------------+
AR-5381      |Not for sale    |Adjustable Race                 |
BA-8327      |Not for sale    |Bearing Ball                    |
BB-7421      |Not for sale    |LL Bottom Bracket               |
BB-8107      |Not for sale    |ML Bottom Bracket               |
BB-9108      |Not for sale    |HL Bottom Bracket               |
BC-M005      |Mountain        |Mountain Bottle Cage            |
BC-R205      |Road            |Road Bottle Cage                |
BE-2349      |Not for sale    |BB Ball Bearing                 |
BE-2908      |Not for sale    |Headset Ball Bearings           |
BK-M18B-40   |Mountain        |Mountain-500 Black, 40          |
BK-M18B-42   |Mountain        |Mountain-500 Black, 42          |
BK-M18B-44   |Mountain        |Mountain-500 Black, 44          |

...

Click me to see the solution

129. From the following table write a query in SQL to evaluate whether the values in the MakeFlag and FinishedGoodsFlag columns are the same for products with ProductID less than 10. If the values in MakeFlag and FinishedGoodsFlag are the same, return NULL; otherwise, return the value of MakeFlag. Return the columns ProductID, MakeFlag, FinishedGoodsFlag, and the evaluated result.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|makeflag|finishedgoodsflag|makeflag|
---------+--------+-----------------+--------+
        1|false   |false            |        |
        2|false   |false            |        |
        3|true    |false            |true    |
        4|false   |false            |        |

Click me to see the solution

130. From the following table write a query in SQL to select the data from the first column that has a nonnull value. Retrun Name, Class, Color, ProductNumber, and FirstNotNull.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                            |class|color       |productnumber|firstnotnull|
--------------------------------+-----+------------+-------------+------------+
Adjustable Race                 |     |            |AR-5381      |AR-5381     |
Bearing Ball                    |     |            |BA-8327      |BA-8327     |
BB Ball Bearing                 |     |            |BE-2349      |BE-2349     |
Headset Ball Bearings           |     |            |BE-2908      |BE-2908     |
Blade                           |     |            |BL-2036      |BL-2036     |
LL Crankarm                     |L    |Black       |CA-5965      |L           |
ML Crankarm                     |M    |Black       |CA-6738      |M           |
HL Crankarm                     |     |Black       |CA-7457      |Black       |
Chainring Bolts                 |     |Silver      |CB-2903      |Silver      |
Chainring Nut                   |     |Silver      |CN-6137      |Silver      |
Chainring                       |     |Black       |CR-7833      |Black       |
Crown Race                      |     |            |CR-9981      |CR-9981     |
Chain Stays                     |     |            |CS-2812      |CS-2812     |
Decal 1                         |     |            |DC-8732      |DC-8732     |
...

Click me to see the solution

131. From the following table, write a query in SQL to check the values of MakeFlag and FinishedGoodsFlag columns and return whether they are the same or not. Return NULL if MakeFlag is equal to FinishedGoodsFlag, otherwise return the value of MakeFlag. Return the columns ProductID, MakeFlag, FinishedGoodsFlag, and a column indicating NULL if they are equal. Filter the results for products where ProductID is less than 10.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|makeflag|finishedgoodsflag|Null if Equal|
---------+--------+-----------------+-------------+
        1|false   |false            |             |
        2|false   |false            |             |
        3|true    |false            |true         |
        4|false   |false            |             |

Click me to see the solution

132. From the following tables write a query in SQL to return any distinct values that are returned by both the query.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: production.WorkOrder
workorderid|productid|orderqty|scrappedqty|startdate              |enddate                |duedate                |scrapreasonid|modifieddate           |
-----------+---------+--------+-----------+-----------------------+-----------------------+-----------------------+-------------+-----------------------+
          1|      722|       8|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          2|      725|      15|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          3|      726|       9|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          4|      729|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          5|      730|      14|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          6|      732|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          7|      733|       4|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          8|      738|      19|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          9|      741|       2|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         10|      742|       3|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         11|      743|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         12|      745|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
		 -- more --

Click to view Full table

Sample Output:

productid|
---------+
      753|
      765|
      970|
      781|
      951|
      839|
      732|
      887|
      350|
      959|
      758|
      819|
      826|
	  ...

Click me to see the solution

133. From the following tables write a query in SQL to return any distinct values from first query that aren't also found on the 2nd query.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: production.WorkOrder
workorderid|productid|orderqty|scrappedqty|startdate              |enddate                |duedate                |scrapreasonid|modifieddate           |
-----------+---------+--------+-----------+-----------------------+-----------------------+-----------------------+-------------+-----------------------+
          1|      722|       8|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          2|      725|      15|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          3|      726|       9|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          4|      729|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          5|      730|      14|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          6|      732|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          7|      733|       4|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          8|      738|      19|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          9|      741|       2|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         10|      742|       3|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         11|      743|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         12|      745|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
		 -- more --

Click to view Full table

Sample Output:

productid|
---------+
      846|
      938|
      477|
      394|
      867|
      858|
      874|
      424|
      406|
      849|
      509|
      929|
      417|
      932|
...

Click me to see the solution

134. From the following tables write a query in SQL to fetch any distinct values from the left query that aren't also present in the query to the right.

Sample table: production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: production.WorkOrder
workorderid|productid|orderqty|scrappedqty|startdate              |enddate                |duedate                |scrapreasonid|modifieddate           |
-----------+---------+--------+-----------+-----------------------+-----------------------+-----------------------+-------------+-----------------------+
          1|      722|       8|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          2|      725|      15|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          3|      726|       9|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          4|      729|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          5|      730|      14|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          6|      732|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          7|      733|       4|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          8|      738|      19|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          9|      741|       2|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         10|      742|       3|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         11|      743|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         12|      745|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
		 -- more --

Click to view Full table

Sample Output:

productid|
---------+	

N.B. : No result returns here

Click me to see the solution

135. From the following tables write a query in SQL to fetch distinct businessentityid that are returned by both the specified query. Sort the result set by ascending order on businessentityid.

Sample table: Person.BusinessEntity
businessentityid|rowguid                             |modifieddate           |
----------------+------------------------------------+-----------------------+
               1|0c7d8f81-d7b1-4cf0-9c0a-4cd8b6b50087|2017-12-13 13:20:24.150|
               2|6648747f-7843-4002-b317-65389684c398|2017-12-13 13:20:24.430|
               3|568204da-93d7-42f4-8a7a-4446a144277d|2017-12-13 13:20:24.540|
               4|0eff57b9-4f4f-41a6-8867-658c199a5fc0|2017-12-13 13:20:24.570|
               5|b82f88d1-ff79-4fd9-8c54-9d24c140f647|2017-12-13 13:20:24.633|
               6|1b3d077a-1941-4d6e-8328-f7dc03595565|2017-12-13 13:20:24.680|
               7|c1898370-a36f-43a2-987c-0bf24fe3fb82|2017-12-13 13:20:24.727|
               8|2b50abb8-abab-412b-a4d0-4fd5ebeb5cbe|2017-12-13 13:20:24.773|
               9|5c0ab449-a087-4d8d-834f-3726061b6bfa|2017-12-13 13:20:24.803|
              10|0f3cc1d7-f484-4bde-b088-b11ef03e2f52|2017-12-13 13:20:24.850|
              11|a417a3d1-00eb-4d7f-b793-f93dc2c5391d|2017-12-13 13:20:24.900|
              12|ebd8a50f-322e-4426-a39a-566fd5535b1c|2017-12-13 13:20:24.947|
			  -- more --

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|
----------------+
            1699|
            1700|
            1701|
            1702|
            1703|
            1704|
            1705|
            1706|
            1707|
            1708|
            1709|
            1710|
            1711|
...	

Click me to see the solution

136. From the following table write a query which is the combination of two queries. Return any distinct businessentityid from the 1st query that aren't also found in the 2nd query. Sort the result set in ascending order on businessentityid.

Sample table: Person.BusinessEntity
businessentityid|rowguid                             |modifieddate           |
----------------+------------------------------------+-----------------------+
               1|0c7d8f81-d7b1-4cf0-9c0a-4cd8b6b50087|2017-12-13 13:20:24.150|
               2|6648747f-7843-4002-b317-65389684c398|2017-12-13 13:20:24.430|
               3|568204da-93d7-42f4-8a7a-4446a144277d|2017-12-13 13:20:24.540|
               4|0eff57b9-4f4f-41a6-8867-658c199a5fc0|2017-12-13 13:20:24.570|
               5|b82f88d1-ff79-4fd9-8c54-9d24c140f647|2017-12-13 13:20:24.633|
               6|1b3d077a-1941-4d6e-8328-f7dc03595565|2017-12-13 13:20:24.680|
               7|c1898370-a36f-43a2-987c-0bf24fe3fb82|2017-12-13 13:20:24.727|
               8|2b50abb8-abab-412b-a4d0-4fd5ebeb5cbe|2017-12-13 13:20:24.773|
               9|5c0ab449-a087-4d8d-834f-3726061b6bfa|2017-12-13 13:20:24.803|
              10|0f3cc1d7-f484-4bde-b088-b11ef03e2f52|2017-12-13 13:20:24.850|
              11|a417a3d1-00eb-4d7f-b793-f93dc2c5391d|2017-12-13 13:20:24.900|
              12|ebd8a50f-322e-4426-a39a-566fd5535b1c|2017-12-13 13:20:24.947|
			  -- more --

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|
----------------+
               1|
               2|
               3|
               4|
               5|
               6|
               7|
               8|
               9|
              10|
              11|
...			

Click me to see the solution

137. From the following tables write a query in SQL to combine the ProductModelID and Name columns. A result set includes columns for productid 3 and 4. Sort the results by name ascending.

Sample table: Production.ProductModel
productmodelid|name                       |catalogdescription|instructions|rowguid                             |modifieddate           |
--------------+---------------------------+------------------+------------+------------------------------------+-----------------------+
             1|Classic Vest               |                  |            |29321d47-1e4c-4aac-887c-19634328c25e|2013-04-30 00:00:00.000|
             2|Cycling Cap                |                  |            |474fb654-3c96-4cb9-82df-2152eeffbdb0|2011-05-01 00:00:00.000|
             3|Full-Finger Gloves         |                  |            |a75483fe-3c47-4aa4-93cf-664b51192987|2012-04-30 00:00:00.000|
             4|Half-Finger Gloves         |                  |            |14b56f2a-d4aa-40a4-b9a2-984f165ed702|2012-04-30 00:00:00.000|
             5|HL Mountain Frame          |                  |            |fdd5407b-c2db-49d1-a86b-c13a2e3582a2|2011-05-01 00:00:00.000|
             6|HL Road Frame              |                  |            |4d332ecc-48b3-4e04-b7e7-227f3ac2a7ec|2008-03-31 00:00:00.000|
             7|HL Touring Frame           |                  |[XML]       |d60ed2a5-c100-4c54-89a1-531404c4a20f|2015-04-15 16:34:28.980|
             8|LL Mountain Frame          |                  |            |65bf3f6d-bcf2-4db6-8515-fc5c57423037|2012-10-19 09:56:38.273|
             9|LL Road Frame              |                  |            |ddc67a2f-024a-4446-9b54-3c679baba708|2011-05-01 00:00:00.000|
            10|LL Touring Frame           |                  |[XML]       |66c63844-2a24-473c-96d5-d3b3fd57d834|2015-04-15 16:34:28.980|
            11|Long-Sleeve Logo Jersey    |                  |            |20efe3f1-a2f8-4dde-b74b-18265f61f863|2011-05-01 00:00:00.000|
            12|Men's Bib-Shorts           |                  |            |219e2f87-26a9-483b-b968-04578e943096|2012-04-30 00:00:00.000|
			-- more --

Click to view Full table

Sample table: Production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|name                            |
---------+--------------------------------+
        1|Adjustable Race                 |
      122|All-Purpose Bike Stand          |
      879|All-Purpose Bike Stand          |
      712|AWC Logo Cap                    |
        2|Bearing Ball                    |
      119|Bike Wash                       |
      877|Bike Wash - Dissolver           |
      316|Blade                           |
      115|Cable Lock                      |
      843|Cable Lock                      |
       98|Chain                           |
      952|Chain                           |
      324|Chain Stays                     |
      322|Chainring                       |
...	

Click me to see the solution

138. From the following table write a query in SQL to find a total number of hours away from work can be calculated by adding vacation time and sick leave. Sort results ascending by Total Hours Away.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname  |lastname         |vacationhours|sickleavehours|Total Hours Away|
-----------+-----------------+-------------+--------------+----------------+
Hung-Fu    |Ting             |            0|            20|              20|
Mandar     |Samant           |            0|            20|              20|
Laura      |Norman           |            0|            20|              20|
Min        |Su               |            1|            20|              21|
Terri      |Duffy            |            1|            20|              21|
Jim        |Scardelis        |            1|            20|              21|
Krishna    |Sunkammurali     |            2|            21|              23|
Nuan       |Yu               |            2|            21|              23|
Roberto    |Tamburello       |            2|            21|              23|
Olinda     |Turner           |            3|            21|              24|
Houman     |Pournasseh       |            3|            21|              24|
Michael    |Sullivan         |            3|            21|              24|
...

Click me to see the solution

139. From the following table write a query in SQL to calculate the tax difference between the highest and lowest tax-rate state or province.

Sample table: Sales.SalesTaxRate
salestaxrateid|stateprovinceid|taxtype|taxrate|name                                 |rowguid                             |modifieddate           |
--------------+---------------+-------+-------+-------------------------------------+------------------------------------+-----------------------+
             1|              1|      1|     14|Canadian GST + Alberta Provincial Tax|683de5dd-521a-47d4-a573-06a3cdb1bc5d|2008-04-30 00:00:00.000|
             2|             57|      1|  14.25|Canadian GST + Ontario Provincial Tax|05c4ffdb-4f84-4cdf-abe5-fdf3216ea74e|2008-04-30 00:00:00.000|
             3|             63|      1|  14.25|Canadian GST + Quebec Provincial Tax |d4edb557-56d7-403c-b538-4df5e7302588|2008-04-30 00:00:00.000|
             4|              1|      2|      7|Canadian GST                         |f0d76907-b433-453f-b95e-16fce73b807a|2008-04-30 00:00:00.000|
             5|             57|      2|      7|Canadian GST                         |7e0e97a2-878b-476f-a648-05a3dd4450ed|2008-04-30 00:00:00.000|
             6|             63|      2|      7|Canadian GST                         |1e285d2c-8af7-47aa-b06a-762cf4d93acd|2008-04-30 00:00:00.000|
             7|              7|      3|      7|Canadian GST                         |590ccb14-cb20-49bf-8fee-e0c3abc4c2b1|2008-04-30 00:00:00.000|
             8|             29|      3|      7|Canadian GST                         |a8365f30-78b7-4dbe-8985-f8260560126b|2008-04-30 00:00:00.000|
             9|             31|      3|      7|Canadian GST                         |f4fde24b-7a53-4340-9d10-173e9424864a|2008-04-30 00:00:00.000|
            10|             41|      3|      7|Canadian GST                         |383d465b-e1d1-492a-83f3-ab3e9cbf3282|2008-04-30 00:00:00.000|
            11|             45|      3|      7|Canadian GST                         |8451909f-8a8d-4789-9f87-16a335d28053|2008-04-30 00:00:00.000|
            12|             49|      3|      7|Canadian GST                         |fb7607ee-8f12-41ea-b461-10885c6f1533|2008-04-30 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

Tax Rate Difference|
-------------------+
               14.6|

Click me to see the solution

140. From the following tables write a query in SQL to calculate sales targets per month for salespeople.

Sample table: Sales.SalesPerson
businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

salespersonid|firstname|lastname         |salesquota|Sales Target Per Month|
-------------+---------+-----------------+----------+----------------------+
          274|Stephen  |Jiang            |          |                      |
          275|Michael  |Blythe           |    300000|    25000.000000000000|
          276|Linda    |Mitchell         |    250000|    20833.333333333333|
          277|Jillian  |Carson           |    250000|    20833.333333333333|
          278|Garrett  |Vargas           |    250000|    20833.333333333333|
          279|Tsvi     |Reiter           |    300000|    25000.000000000000|
          280|Pamela   |Ansman-Wolfe     |    250000|    20833.333333333333|
          281|Shu      |Ito              |    250000|    20833.333333333333|
          282|José     |Saraiva          |    250000|    20833.333333333333|
          283|David    |Campbell         |    250000|    20833.333333333333|
          284|Tete     |Mensa-Annan      |    300000|    25000.000000000000|
          285|Syed     |Abbas            |          |                      |
          286|Lynn     |Tsoflias         |    250000|    20833.333333333333|
          287|Amy      |Alberts          |          |                      |
          288|Rachel   |Valdez           |    250000|    20833.333333333333|
          289|Jae      |Pak              |    250000|    20833.333333333333|
          290|Ranjit   |Varkey Chudukatil|    250000|    20833.333333333333|

Click me to see the solution

141. From the following table write a query in SQL to return the ID number, unit price, and the modulus (remainder) of dividing product prices. Convert the modulo to an integer value.

Sample table: Sales.SalesOrderDetail
salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

productid|unitprice|orderqty|modulo|
---------+---------+--------+------+
      776| 2024.994|       1|     0|
      777| 2024.994|       3|     0|
      778| 2024.994|       1|     0|
      771| 2039.994|       1|     0|
      772| 2039.994|       1|     0|
      773| 2039.994|       2|     0|
      774| 2039.994|       1|     0|
      714|  28.8404|       3|     2|
      716|  28.8404|       1|     0|
      709|      5.7|       6|     0|
      712|   5.1865|       2|     1|
      711|  20.1865|       4|     0|
      762| 419.4589|       1|     0|
      758|  874.794|       1|     0|
      745|   809.76|       1|     0|
      743| 714.7043|       1|     0|
      747| 714.7043|       2|     1|
      712|   5.1865|       4|     1|
      715|  28.8404|       4|     1|
...

Click me to see the solution

142. From the following table write a query in SQL to select employees who have the title of Marketing Assistant and more than 41 vacation hours.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

businessentityid|loginid               |jobtitle           |vacationhours|
----------------+----------------------+-------------------+-------------+
              17|adventure-works\kevin0|Marketing Assistant|           42|
              19|adventure-works\mary2 |Marketing Assistant|           43|

Click me to see the solution

143. From the following tables write a query in SQL to find all rows outside a specified range of rate between 27 and 30. Sort the result in ascending order on rate.

Sample table: HumanResources.vEmployee
businessentityid|title|firstname  |middlename      |lastname         |suffix|jobtitle                                |phonenumber        |phonenumbertype|emailaddress                    |emailpromotion|addressline1              |addressline2|city         |stateprovincename|postalcode|countryregionname|additionalcontactinfo|
----------------+-----+-----------+----------------+-----------------+------+----------------------------------------+-------------------+---------------+--------------------------------+--------------+--------------------------+------------+-------------+-----------------+----------+-----------------+---------------------+
               1|     |Ken        |J               |Sánchez          |      |Chief Executive Officer                 |697-555-0142       |Cell           |[email protected]        |             0|4350 Minute Dr.           |            |Newport Hills|Washington       |98006     |United States    |                     |
               2|     |Terri      |Lee             |Duffy            |      |Vice President of Engineering           |819-555-0175       |Work           |[email protected]      |             1|7559 Worth Ct.            |            |Renton       |Washington       |98055     |United States    |                     |
               3|     |Roberto    |                |Tamburello       |      |Engineering Manager                     |212-555-0187       |Cell           |[email protected]    |             0|2137 Birchwood Dr         |            |Redmond      |Washington       |98052     |United States    |                     |
               4|     |Rob        |                |Walters          |      |Senior Tool Designer                    |612-555-0100       |Cell           |[email protected]        |             0|5678 Lakeview Blvd.       |            |Minneapolis  |Minnesota        |55402     |United States    |                     |
               5|Ms.  |Gail       |A               |Erickson         |      |Design Engineer                         |849-555-0139       |Cell           |[email protected]       |             0|9435 Breck Court          |            |Bellevue     |Washington       |98004     |United States    |                     |
               6|Mr.  |Jossef     |H               |Goldberg         |      |Design Engineer                         |122-555-0189       |Work           |[email protected]     |             0|5670 Bel Air Dr.          |            |Renton       |Washington       |98055     |United States    |                     |
               7|     |Dylan      |A               |Miller           |      |Research and Development Manager        |181-555-0156       |Work           |[email protected]      |             2|7048 Laurel               |            |Kenmore      |Washington       |98028     |United States    |                     |
               8|     |Diane      |L               |Margheim         |      |Research and Development Engineer       |815-555-0138       |Cell           |[email protected]      |             0|475 Santa Maria           |            |Everett      |Washington       |98201     |United States    |                     |
               9|     |Gigi       |N               |Matthew          |      |Research and Development Engineer       |185-555-0186       |Cell           |[email protected]       |             0|7808 Brown St.            |            |Bellevue     |Washington       |98004     |United States    |                     |
              10|     |Michael    |                |Raheem           |      |Research and Development Manager        |330-555-2568       |Work           |[email protected]    |             2|1234 Seaside Way          |            |San Francisco|California       |94109     |United States    |                     |
              11|     |Ovidiu     |V               |Cracium          |      |Senior Tool Designer                    |719-555-0181       |Cell           |[email protected]     |             0|5458 Gladstone Drive      |            |Kenmore      |Washington       |98028     |United States    |                     |
              12|     |Thierry    |B               |D'Hers           |      |Tool Designer                           |168-555-0183       |Work           |[email protected]    |             2|1970 Napa Ct.             |            |Bothell      |Washington       |98011     |United States    |                     |
              13|Ms.  |Janice     |M               |Galvin           |      |Tool Designer                           |473-555-0117       |Work           |[email protected]     |             2|3397 Rancho View Drive    |            |Redmond      |Washington       |98052     |United States    |                     |
              14|     |Michael    |I               |Sullivan         |      |Senior Design Engineer                  |465-555-0156       |Cell           |[email protected]    |             2|6510 Hacienda Drive       |            |Renton       |Washington       |98055     |United States    |                     |
              15|     |Sharon     |B               |Salavaria        |      |Design Engineer                         |970-555-0138       |Cell           |[email protected]     |             2|7165 Brock Lane           |            |Renton       |Washington       |98055     |United States    |                     |
              16|     |David      |M               |Bradley          |      |Marketing Manager                       |913-555-0172       |Work           |[email protected]      |             1|3768 Door Way             |            |Redmond      |Washington       |98052     |United States    |                     |
              17|     |Kevin      |F               |Brown            |      |Marketing Assistant                     |150-555-0189       |Cell           |[email protected]      |             2|7883 Missing Canyon Court |            |Everett      |Washington       |98201     |United States    |                     |
              18|     |John       |L               |Wood             |      |Marketing Specialist                    |486-555-0150       |Work           |[email protected]       |             2|9906 Oak Grove Road       |            |Redmond      |Washington       |98052     |United States    |                     |
              19|     |Mary       |A               |Dempsey          |      |Marketing Assistant                     |124-555-0114       |Cell           |[email protected]       |             1|6307 Greenbelt Way        |            |Bellevue     |Washington       |98004     |United States    |                     |
              20|     |Wanida     |M               |Benshoof         |      |Marketing Assistant                     |708-555-0141       |Work           |[email protected]     |             2|6951 Harmony Way          |            |Sammamish    |Washington       |98074     |United States    |                     |
              21|     |Terry      |J               |Eminhizer        |      |Marketing Specialist                    |138-555-0118       |Cell           |[email protected]      |             2|8668 Via Neruda           |            |Bellevue     |Washington       |98004     |United States    |                     |
              22|     |Sariya     |E               |Harnpadoungsataya|      |Marketing Specialist                    |399-555-0176       |Work           |[email protected]     |             0|1185 Dallas Drive         |            |Everett      |Washington       |98201     |United States    |                     |
              23|     |Mary       |E               |Gibson           |      |Marketing Specialist                    |531-555-0183       |Work           |[email protected]       |             0|3928 San Francisco        |            |Everett      |Washington       |98201     |United States    |                     |
              24|Ms.  |Jill       |A               |Williams         |      |Marketing Specialist                    |510-555-0121       |Work           |[email protected]       |             0|3238 Laguna Circle        |            |Everett      |Washington       |98201     |United States    |                     |
              25|     |James      |R               |Hamilton         |      |Vice President of Production            |870-555-0122       |Work           |[email protected]      |             0|9652 Los Angeles          |            |Monroe       |Washington       |98272     |United States    |                     |
              26|     |Peter      |J               |Krebs            |      |Production Control Manager              |913-555-0196       |Work           |[email protected]      |             0|3670 All Ways Drive       |            |Bellevue     |Washington       |98004     |United States    |                     |
              27|     |Jo         |A               |Brown            |      |Production Supervisor - WC60            |632-555-0129       |Cell           |[email protected]         |             0|9693 Mellowood Street     |            |Duvall       |Washington       |98019     |United States    |                     |
              28|     |Guy        |R               |Gilbert          |      |Production Technician - WC60            |320-555-0195       |Work           |[email protected]        |             0|7726 Driftwood Drive      |            |Monroe       |Washington       |98272     |United States    |                     |
              29|     |Mark       |K               |McArthur         |      |Production Technician - WC60            |417-555-0154       |Work           |[email protected]       |             1|9863 Ridge Place          |            |Redmond      |Washington       |98052     |United States    |                     |
              30|     |Britta     |L               |Simon            |      |Production Technician - WC60            |955-555-0169       |Cell           |[email protected]     |             0|2046 Las Palmas           |            |Edmonds      |Washington       |98020     |United States    |                     |
              31|     |Margie     |W               |Shoop            |      |Production Technician - WC60            |818-555-0128       |Cell           |[email protected]     |             2|2080 Sycamore Drive       |            |Edmonds      |Washington       |98020     |United States    |                     |
              32|     |Rebecca    |A               |Laszlo           |      |Production Technician - WC60            |314-555-0113       |Cell           |[email protected]    |             1|3197 Thornhill Place      |            |Bellevue     |Washington       |98004     |United States    |                     |
              33|     |Annik      |O               |Stahl            |      |Production Technician - WC60            |499-555-0125       |Work           |[email protected]      |             0|7842 Ygnacio Valley Road  |            |Seattle      |Washington       |98104     |United States    |                     |
              34|     |Suchitra   |O               |Mohan            |      |Production Technician - WC60            |753-555-0129       |Cell           |[email protected]   |             2|5678 Clear Court          |            |Bellevue     |Washington       |98004     |United States    |                     |
              35|     |Brandon    |G               |Heidepriem       |      |Production Technician - WC60            |429-555-0137       |Cell           |[email protected]    |             1|8000 Crane Court          |            |Redmond      |Washington       |98052     |United States    |                     |
              36|     |Jose       |R               |Lugo             |      |Production Technician - WC60            |587-555-0115       |Cell           |[email protected]       |             2|5125 Cotton Ct.           |            |Seattle      |Washington       |98104     |United States    |                     |
              37|     |Chris      |O               |Okelberry        |      |Production Technician - WC60            |315-555-0144       |Cell           |[email protected]      |             0|8467 Clifford Court       |            |Redmond      |Washington       |98052     |United States    |                     |
              38|     |Kim        |B               |Abercrombie      |      |Production Technician - WC60            |208-555-0114       |Cell           |[email protected]        |             2|9752 Jeanne Circle        |            |Carnation    |Washington       |98014     |United States    |                     |
              39|     |Ed         |R               |Dudenhoefer      |      |Production Technician - WC60            |919-555-0140       |Work           |[email protected]         |             0|4598 Manila Avenue        |            |Seattle      |Washington       |98104     |United States    |                     |
              40|     |JoLynn     |M               |Dobney           |      |Production Supervisor - WC60            |903-555-0145       |Work           |[email protected]     |             1|7126 Ending Ct.           |            |Seattle      |Washington       |98104     |United States    |                     |
              41|     |Bryan      |                |Baker            |      |Production Technician - WC60            |712-555-0113       |Cell           |[email protected]      |             0|2275 Valley Blvd.         |            |Monroe       |Washington       |98272     |United States    |                     |
              42|     |James      |D               |Kramer           |      |Production Technician - WC60            |119-555-0117       |Cell           |[email protected]      |             2|4734 Sycamore Court       |            |Monroe       |Washington       |98272     |United States    |                     |
              43|     |Nancy      |A               |Anderson         |      |Production Technician - WC60            |970-555-0118       |Cell           |[email protected]      |             1|7820 Bird Drive           |            |Sammamish    |Washington       |98074     |United States    |                     |
              44|     |Simon      |D               |Rapier           |      |Production Technician - WC60            |963-555-0134       |Work           |[email protected]      |             0|3421 Bouncing Road        |            |Duvall       |Washington       |98019     |United States    |                     |
              45|     |Thomas     |R               |Michaels         |      |Production Technician - WC60            |278-555-0118       |Cell           |[email protected]     |             1|7338 Green St.            |            |Edmonds      |Washington       |98020     |United States    |                     |
              46|     |Eugene     |O               |Kogan            |      |Production Technician - WC60            |173-555-0179       |Cell           |[email protected]     |             0|991 Vista Verde           |            |Duvall       |Washington       |98019     |United States    |                     |
              47|     |Andrew     |R               |Hill             |      |Production Supervisor - WC10            |908-555-0159       |Cell           |[email protected]     |             1|6629 Polson Circle        |            |Everett      |Washington       |98201     |United States    |                     |
              48|     |Ruth       |Ann             |Ellerbrock       |      |Production Technician - WC10            |145-555-0130       |Cell           |[email protected]       |             0|2176 Apollo Way           |            |Everett      |Washington       |98201     |United States    |                     |
              49|     |Barry      |K               |Johnson          |      |Production Technician - WC10            |206-555-0180       |Work           |[email protected]      |             0|3114 Notre Dame Ave.      |            |Snohomish    |Washington       |98296     |United States    |                     |
              50|     |Sidney     |M               |Higa             |      |Production Technician - WC10            |424-555-0189       |Work           |[email protected]     |             0|9277 Country View Lane    |            |Edmonds      |Washington       |98020     |United States    |                     |
              51|     |Jeffrey    |L               |Ford             |      |Production Technician - WC10            |984-555-0185       |Work           |[email protected]    |             0|5734 Ashford Court        |            |Monroe       |Washington       |98272     |United States    |                     |
              52|     |Doris      |M               |Hartwig          |      |Production Technician - WC10            |328-555-0150       |Cell           |[email protected]      |             0|5553 Cash Avenue          |            |Kenmore      |Washington       |98028     |United States    |                     |
              53|     |Diane      |R               |Glimp            |      |Production Technician - WC10            |202-555-0151       |Cell           |[email protected]      |             2|9006 Woodside Way         |            |Redmond      |Washington       |98052     |United States    |                     |
              54|     |Bonnie     |N               |Kearney          |      |Production Technician - WC10            |264-555-0150       |Work           |[email protected]     |             0|4852 Chaparral Court      |            |Snohomish    |Washington       |98296     |United States    |                     |
              55|     |Taylor     |R               |Maxwell          |      |Production Supervisor - WC50            |508-555-0165       |Work           |[email protected]     |             0|504 O St.                 |            |Edmonds      |Washington       |98020     |United States    |                     |
              56|     |Denise     |H               |Smith            |      |Production Technician - WC50            |869-555-0119       |Cell           |[email protected]     |             0|5669 Ironwood Way         |            |Kenmore      |Washington       |98028     |United States    |                     |
              57|     |Frank      |T               |Miller           |      |Production Technician - WC50            |167-555-0139       |Work           |[email protected]      |             1|591 Merriewood Drive      |            |Snohomish    |Washington       |98296     |United States    |                     |
              58|     |Kendall    |C               |Keil             |      |Production Technician - WC50            |138-555-0128       |Work           |[email protected]    |             2|7439 Laguna Niguel        |            |Seattle      |Washington       |98104     |United States    |                     |
              59|     |Bob        |N               |Hohman           |      |Production Technician - WC50            |611-555-0116       |Work           |[email protected]        |             0|6387 Scenic Avenue        |            |Bothell      |Washington       |98011     |United States    |                     |
              60|     |Pete       |C               |Male             |      |Production Technician - WC50            |768-555-0123       |Cell           |[email protected]       |             2|5375 Clearland Circle     |            |Seattle      |Washington       |98104     |United States    |                     |
              61|     |Diane      |H               |Tibbott          |      |Production Technician - WC50            |361-555-0180       |Work           |[email protected]      |             0|8192 Seagull Court        |            |Kenmore      |Washington       |98028     |United States    |                     |
              62|     |John       |T               |Campbell         |      |Production Supervisor - WC60            |435-555-0113       |Work           |[email protected]       |             1|2639 Anchor Court         |            |Seattle      |Washington       |98104     |United States    |                     |
              63|     |Maciej     |W               |Dusza            |      |Production Technician - WC60            |237-555-0128       |Cell           |[email protected]     |             0|3026 Anchor Drive         |            |Edmonds      |Washington       |98020     |United States    |                     |
              64|     |Michael    |J               |Zwilling         |      |Production Technician - WC60            |582-555-0148       |Cell           |[email protected]    |             1|7511 Cooper Dr.           |            |Edmonds      |Washington       |98020     |United States    |                     |
              65|     |Randy      |T               |Reeves           |      |Production Technician - WC60            |961-555-0122       |Cell           |[email protected]      |             0|3632 Bank Way             |            |Edmonds      |Washington       |98020     |United States    |                     |
              66|     |Karan      |R               |Khanna           |      |Production Technician - WC60            |447-555-0186       |Work           |[email protected]      |             1|1102 Ravenwood            |            |Seattle      |Washington       |98104     |United States    |                     |
              67|     |Jay        |G               |Adams            |      |Production Technician - WC60            |407-555-0165       |Work           |[email protected]        |             0|896 Southdale             |            |Monroe       |Washington       |98272     |United States    |                     |
              68|     |Charles    |B               |Fitzgerald       |      |Production Technician - WC60            |931-555-0118       |Work           |[email protected]    |             2|5263 Etcheverry Dr        |            |Sammamish    |Washington       |98074     |United States    |                     |
              69|     |Steve      |F               |Masters          |      |Production Technician - WC60            |712-555-0170       |Work           |[email protected]      |             1|1398 Yorba Linda          |            |Seattle      |Washington       |98104     |United States    |                     |
              70|     |David      |J               |Ortiz            |      |Production Technician - WC60            |712-555-0119       |Work           |[email protected]      |             0|931 Corte De Luna         |            |Seattle      |Washington       |98104     |United States    |                     |
              71|     |Michael    |Sean            |Ray              |      |Production Supervisor - WC30            |156-555-0199       |Cell           |[email protected]    |             2|6498 Mining Rd.           |            |Seattle      |Washington       |98104     |United States    |                     |
              72|     |Steven     |T               |Selikoff         |      |Production Technician - WC30            |925-555-0114       |Work           |[email protected]     |             2|181 Gaining Drive         |            |Everett      |Washington       |98201     |United States    |                     |
              73|     |Carole     |M               |Poland           |      |Production Technician - WC30            |688-555-0192       |Cell           |[email protected]     |             2|8411 Mt. Orange Place     |            |Edmonds      |Washington       |98020     |United States    |                     |
              74|     |Bjorn      |M               |Rettig           |      |Production Technician - WC30            |199-555-0117       |Work           |[email protected]      |             1|5802 Ampersand Drive      |            |Seattle      |Washington       |98104     |United States    |                     |
              75|     |Michiko    |F               |Osada            |      |Production Technician - WC30            |984-555-0148       |Work           |[email protected]    |             0|1962 Ferndale Lane        |            |Sammamish    |Washington       |98074     |United States    |                     |
              76|     |Carol      |M               |Philips          |      |Production Technician - WC30            |609-555-0153       |Cell           |[email protected]      |             2|6872 Thornwood Dr.        |            |Bothell      |Washington       |98011     |United States    |                     |
              77|     |Merav      |A               |Netz             |      |Production Technician - WC30            |224-555-0187       |Work           |[email protected]      |             0|5666 Hazelnut Lane        |            |Seattle      |Washington       |98104     |United States    |                     |
              78|     |Reuben     |H               |D'sa             |      |Production Supervisor - WC40            |191-555-0112       |Work           |[email protected]     |             2|1064 Slow Creek Road      |            |Seattle      |Washington       |98104     |United States    |                     |
              79|     |Eric       |L               |Brown            |      |Production Technician - WC40            |680-555-0118       |Cell           |[email protected]       |             0|5086 Nottingham Place     |            |Duvall       |Washington       |98019     |United States    |                     |
              80|     |Sandeep    |P               |Kaliyath         |      |Production Technician - WC40            |166-555-0156       |Work           |[email protected]    |             2|4310 Kenston Dr.          |            |Sammamish    |Washington       |98074     |United States    |                     |
              81|     |Mihail     |U               |Frintu           |      |Production Technician - WC40            |733-555-0128       |Work           |[email protected]     |             0|2466 Clearland Circle     |            |Edmonds      |Washington       |98020     |United States    |                     |
              82|     |Jack       |T               |Creasey          |      |Production Technician - WC40            |521-555-0113       |Cell           |[email protected]       |             0|874 Olivera Road          |            |Seattle      |Washington       |98104     |United States    |                     |
              83|     |Patrick    |M               |Cook             |      |Production Technician - WC40            |425-555-0117       |Cell           |[email protected]    |             0|9537 Ridgewood Drive      |            |Seattle      |Washington       |98104     |United States    |                     |
              84|     |Frank      |R               |Martinez         |      |Production Technician - WC40            |203-555-0196       |Work           |[email protected]      |             1|5724 Victory Lane         |            |Snohomish    |Washington       |98296     |United States    |                     |
              85|     |Brian      |Richard         |Goldstein        |      |Production Technician - WC40            |730-555-0117       |Cell           |[email protected]      |             0|8157 W. Book              |            |Bothell      |Washington       |98011     |United States    |                     |
              86|     |Ryan       |L               |Cornelsen        |      |Production Technician - WC40            |208-555-0114       |Work           |[email protected]       |             2|177 11th Ave              |            |Sammamish    |Washington       |98074     |United States    |                     |
              87|     |Cristian   |K               |Petculescu       |      |Production Supervisor - WC10            |434-555-0133       |Cell           |[email protected]   |             1|7166 Brock Lane           |            |Seattle      |Washington       |98104     |United States    |                     |
              88|     |Betsy      |A               |Stadick          |      |Production Technician - WC10            |405-555-0171       |Cell           |[email protected]      |             0|5672 Hale Dr.             |            |Bothell      |Washington       |98011     |United States    |                     |
              89|     |Patrick    |C               |Wedge            |      |Production Technician - WC10            |413-555-0124       |Cell           |[email protected]    |             0|3067 Maya                 |            |Bellevue     |Washington       |98004     |United States    |                     |
              90|     |Danielle   |C               |Tiedt            |      |Production Technician - WC10            |500-555-0172       |Cell           |[email protected]   |             1|5203 Virginia Lane        |            |Kenmore      |Washington       |98028     |United States    |                     |
              91|     |Kimberly   |B               |Zimmerman        |      |Production Technician - WC10            |123-555-0167       |Work           |[email protected]   |             0|8656 Lakespring Place     |            |Seattle      |Washington       |98104     |United States    |                     |
              92|     |Tom        |M               |Vande Velde      |      |Production Technician - WC10            |295-555-0161       |Work           |[email protected]        |             0|5242 Marvelle Ln.         |            |Everett      |Washington       |98201     |United States    |                     |
              93|     |Kok-Ho     |T               |Loh              |      |Production Supervisor - WC50            |999-555-0155       |Work           |[email protected]     |             2|3708 Montana              |            |Bellevue     |Washington       |98004     |United States    |                     |
              94|     |Russell    |                |Hunter           |      |Production Technician - WC50            |786-555-0144       |Work           |[email protected]    |             1|7616 Honey Court          |            |Seattle      |Washington       |98104     |United States    |                     |
              95|     |Jim        |H               |Scardelis        |      |Production Technician - WC50            |679-555-0113       |Work           |[email protected]        |             2|172 Turning Dr.           |            |Edmonds      |Washington       |98020     |United States    |                     |
              96|     |Elizabeth  |I               |Keyser           |      |Production Technician - WC50            |318-555-0137       |Cell           |[email protected]  |             0|350 Pastel Drive          |            |Kent         |Washington       |98031     |United States    |                     |
              97|     |Mandar     |H               |Samant           |      |Production Technician - WC50            |140-555-0132       |Work           |[email protected]     |             0|2598 La Vista Circle      |            |Duvall       |Washington       |98019     |United States    |                     |
              98|     |Sameer     |A               |Tejani           |      |Production Technician - WC50            |990-555-0172       |Cell           |[email protected]     |             0|5379 Treasure Island Way  |# 14        |Duvall       |Washington       |98019     |United States    |                     |
              99|     |Nuan       |                |Yu               |      |Production Technician - WC50            |913-555-0184       |Cell           |[email protected]       |             0|3454 Bel Air Drive        |            |Bellevue     |Washington       |98004     |United States    |                     |
             100|     |Lolan      |B               |Song             |      |Production Technician - WC50            |582-555-0178       |Cell           |[email protected]      |             1|8152 Claudia Dr.          |            |Edmonds      |Washington       |98020     |United States    |                     |
             101|     |Houman     |N               |Pournasseh       |      |Production Technician - WC50            |180-555-0136       |Cell           |[email protected]     |             2|9882 Clay Rde             |            |Redmond      |Washington       |98052     |United States    |                     |
             102|     |Zheng      |W               |Mu               |      |Production Supervisor - WC10            |113-555-0173       |Cell           |[email protected]      |             0|6578 Woodhaven Ln.        |            |Seattle      |Washington       |98104     |United States    |                     |
             103|     |Ebru       |N               |Ersan            |      |Production Technician - WC10            |202-555-0187       |Cell           |[email protected]       |             2|8316 La Salle St.         |            |Sammamish    |Washington       |98074     |United States    |                     |
             104|     |Mary       |R               |Baker            |      |Production Technician - WC10            |283-555-0185       |Work           |[email protected]       |             2|2354 Frame Ln.            |            |Seattle      |Washington       |98104     |United States    |                     |
             105|     |Kevin      |M               |Homer            |      |Production Technician - WC10            |555-555-0113       |Work           |[email protected]      |             0|6058 Hill Street          |# 4         |Bellevue     |Washington       |98004     |United States    |                     |
             106|     |John       |T               |Kane             |      |Production Technician - WC10            |254-555-0114       |Work           |[email protected]       |             1|8209 Green View Court     |            |Duvall       |Washington       |98019     |United States    |                     |
             107|     |Christopher|E               |Hill             |      |Production Technician - WC10            |153-555-0166       |Cell           |[email protected]|             0|1902 Santa Cruz           |            |Bothell      |Washington       |98011     |United States    |                     |
             108|     |Jinghao    |K               |Liu              |      |Production Supervisor - WC50            |794-555-0159       |Cell           |[email protected]    |             0|9666 Northridge Ct.       |            |Carnation    |Washington       |98014     |United States    |                     |
             109|     |Alice      |O               |Ciccu            |      |Production Technician - WC50            |333-555-0173       |Cell           |[email protected]      |             1|3280 Pheasant Circle      |            |Snohomish    |Washington       |98296     |United States    |                     |
             110|     |Jun        |T               |Cao              |      |Production Technician - WC50            |299-555-0113       |Work           |[email protected]        |             0|4909 Poco Lane            |            |Redmond      |Washington       |98052     |United States    |                     |
             111|     |Suroor     |R               |Fatima           |      |Production Technician - WC50            |932-555-0161       |Work           |[email protected]     |             0|3281 Hillview Dr.         |            |Edmonds      |Washington       |98020     |United States    |                     |
             112|     |John       |P               |Evans            |      |Production Technician - WC50            |172-555-0130       |Cell           |[email protected]       |             1|136 Balboa Court          |            |Seattle      |Washington       |98104     |United States    |                     |
             113|     |Linda      |K               |Moschell         |      |Production Technician - WC50            |612-555-0171       |Cell           |[email protected]      |             1|3284 S. Blank Avenue      |            |Bellevue     |Washington       |98004     |United States    |                     |
             114|     |Mindaugas  |J               |Krapauskas       |      |Production Technician - WC50            |637-555-0120       |Work           |[email protected]  |             1|9825 Coralie Drive        |            |Edmonds      |Washington       |98020     |United States    |                     |
             115|     |Angela     |W               |Barbariol        |      |Production Technician - WC50            |150-555-0194       |Cell           |[email protected]     |             2|2687 Ridge Road           |            |Edmonds      |Washington       |98020     |United States    |                     |
             116|     |Michael    |W               |Patten           |      |Production Technician - WC50            |441-555-0195       |Work           |[email protected]    |             0|2038 Encino Drive         |            |Edmonds      |Washington       |98020     |United States    |                     |
             117|     |Chad       |W               |Niswonger        |      |Production Technician - WC50            |559-555-0175       |Work           |[email protected]       |             1|5747 Shirley Drive        |            |Bothell      |Washington       |98011     |United States    |                     |
             118|     |Don        |L               |Hall             |      |Production Technician - WC50            |100-555-0174       |Work           |[email protected]        |             0|1411 Ranch Drive          |            |Carnation    |Washington       |98014     |United States    |                     |
             119|     |Michael    |T               |Entin            |      |Production Technician - WC50            |817-555-0186       |Work           |[email protected]    |             1|2482 Buckingham Dr.       |            |Redmond      |Washington       |98052     |United States    |                     |
             120|     |Kitti      |H               |Lertpiriyasuwat  |      |Production Technician - WC50            |785-555-0132       |Work           |[email protected]      |             0|5376 Catanzaro Way        |            |Seattle      |Washington       |98104     |United States    |                     |
             121|     |Pilar      |G               |Ackerman         |      |Shipping and Receiving Supervisor       |577-555-0185       |Work           |[email protected]      |             0|5407 Cougar Way           |            |Seattle      |Washington       |98104     |United States    |                     |
             122|     |Susan      |W               |Eaton            |      |Stocker                                 |943-555-0196       |Work           |[email protected]      |             2|2736 Scramble Rd          |            |Renton       |Washington       |98055     |United States    |                     |
             123|     |Vamsi      |N               |Kuppa            |      |Shipping and Receiving Clerk            |937-555-0137       |Work           |[email protected]      |             0|9833 Mt. Dias Blv.        |            |Bothell      |Washington       |98011     |United States    |                     |
             124|     |Kim        |T               |Ralls            |      |Stocker                                 |309-555-0129       |Work           |[email protected]        |             2|1226 Shoe St.             |            |Bothell      |Washington       |98011     |United States    |                     |
             125|     |Matthias   |T               |Berndt           |      |Shipping and Receiving Clerk            |139-555-0120       |Cell           |[email protected]   |             0|4312 Cambridge Drive      |            |Renton       |Washington       |98055     |United States    |                     |
             126|     |Jimmy      |T               |Bischoff         |      |Stocker                                 |927-555-0168       |Cell           |[email protected]      |             0|2176 Brown Street         |            |Renton       |Washington       |98055     |United States    |                     |
             127|     |David      |P               |Hamilton         |      |Production Supervisor - WC40            |986-555-0177       |Cell           |[email protected]      |             1|4095 Cooper Dr.           |            |Kenmore      |Washington       |98028     |United States    |                     |
             128|     |Paul       |B               |Komosinski       |      |Production Technician - WC40            |147-555-0160       |Work           |[email protected]       |             2|7270 Pepper Way           |            |Bellevue     |Washington       |98004     |United States    |                     |
             129|     |Gary       |W               |Yukish           |      |Production Technician - WC40            |901-555-0125       |Cell           |[email protected]       |             0|6057 Hill Street          |            |Edmonds      |Washington       |98020     |United States    |                     |
             130|     |Rob        |T               |Caron            |      |Production Technician - WC40            |238-555-0116       |Work           |[email protected]        |             0|5030 Blue Ridge Dr.       |            |Monroe       |Washington       |98272     |United States    |                     |
             131|     |Baris      |F               |Cetinok          |      |Production Technician - WC40            |164-555-0114       |Work           |[email protected]      |             2|426 San Rafael            |            |Seattle      |Washington       |98104     |United States    |                     |
             132|     |Nicole     |B               |Holliday         |      |Production Technician - WC40            |508-555-0129       |Cell           |[email protected]     |             0|3243 Buckingham Dr.       |# 207       |Seattle      |Washington       |98104     |United States    |                     |
             133|     |Michael    |L               |Rothkugel        |      |Production Technician - WC40            |454-555-0119       |Work           |[email protected]    |             2|207 Berry Court           |            |Edmonds      |Washington       |98020     |United States    |                     |
             134|     |Eric       |                |Gubbels          |      |Production Supervisor - WC20            |260-555-0119       |Cell           |[email protected]       |             2|371 Apple Dr.             |            |Edmonds      |Washington       |98020     |United States    |                     |
             135|     |Ivo        |William         |Salmre           |      |Production Technician - WC20            |115-555-0179       |Work           |[email protected]        |             0|3841 Silver Oaks Place    |            |Monroe       |Washington       |98272     |United States    |                     |
             136|     |Sylvester  |A               |Valdez           |      |Production Technician - WC20            |492-555-0174       |Cell           |[email protected]  |             0|7902 Grammercy Lane       |Unit A      |Bellevue     |Washington       |98004     |United States    |                     |
             137|     |Anibal     |T               |Sousa            |      |Production Technician - WC20            |106-555-0120       |Work           |[email protected]     |             0|6891 Ham Drive            |            |Redmond      |Washington       |98052     |United States    |                     |
             138|     |Samantha   |H               |Smith            |      |Production Technician - WC20            |587-555-0114       |Cell           |[email protected]   |             0|1648 Eastgate Lane        |            |Bellevue     |Washington       |98004     |United States    |                     |
             139|Mr.  |Hung-Fu    |T               |Ting             |      |Production Technician - WC20            |497-555-0181       |Cell           |[email protected]    |             0|7086 O St.                |            |Sammamish    |Washington       |98074     |United States    |                     |
             140|     |Prasanna   |E               |Samarawickrama   |      |Production Technician - WC20            |129-555-0199       |Cell           |[email protected]   |             1|9322 Driving Drive        |            |Redmond      |Washington       |98052     |United States    |                     |
             141|     |Min        |G               |Su               |      |Production Technician - WC20            |590-555-0152       |Work           |[email protected]        |             0|7396 Stratton Circle      |            |Bellevue     |Washington       |98004     |United States    |                     |
             142|     |Olinda     |C               |Turner           |      |Production Technician - WC20            |306-555-0186       |Cell           |[email protected]     |             0|7221 Peachwillow Street   |            |Bellevue     |Washington       |98004     |United States    |                     |
             143|     |Krishna    |                |Sunkammurali     |      |Production Technician - WC20            |491-555-0183       |Cell           |[email protected]    |             2|6870 D Bel Air Drive      |            |Edmonds      |Washington       |98020     |United States    |                     |
             144|     |Paul       |R               |Singh            |      |Production Technician - WC20            |727-555-0112       |Cell           |[email protected]       |             2|1343 Prospect St          |            |Bellevue     |Washington       |98004     |United States    |                     |
             145|     |Cynthia    |S               |Randall          |      |Production Supervisor - WC30            |352-555-0138       |Cell           |[email protected]    |             0|463 H Stagecoach Rd.      |            |Kenmore      |Washington       |98028     |United States    |                     |
             146|     |Jian Shuo  |                |Wang             |      |Production Technician - WC30            |952-555-0178       |Cell           |[email protected]   |             0|8310 Ridge Circle         |            |Monroe       |Washington       |98272     |United States    |                     |
             147|     |Sandra     |                |Reátegui Alayo   |      |Production Technician - WC30            |896-555-0168       |Work           |[email protected]     |             0|1619 Stillman Court       |            |Seattle      |Washington       |98104     |United States    |                     |
             148|     |Jason      |M               |Watters          |      |Production Technician - WC30            |571-555-0179       |Work           |[email protected]      |             0|9320 Teakwood Dr.         |            |Bellevue     |Washington       |98004     |United States    |                     |
             149|     |Andy       |M               |Ruth             |      |Production Technician - WC30            |118-555-0110       |Cell           |[email protected]       |             1|4777 Rockne Drive         |            |Bellevue     |Washington       |98004     |United States    |                     |
             150|     |Michael    |T               |Vanderhyde       |      |Production Technician - WC30            |296-555-0121       |Cell           |[email protected]    |             2|2812 Mazatlan             |            |Edmonds      |Washington       |98020     |United States    |                     |
             151|     |Rostislav  |E               |Shabalin         |      |Production Technician - WC30            |751-555-0134       |Cell           |[email protected]  |             2|3711 Rollingwood Dr       |            |Bellevue     |Washington       |98004     |United States    |                     |
             152|     |Yuhong     |L               |Li               |      |Production Supervisor - WC20            |965-555-0155       |Cell           |[email protected]     |             1|502 Alexander Pl.         |            |Seattle      |Washington       |98104     |United States    |                     |
             153|     |Hanying    |P               |Feng             |      |Production Technician - WC20            |319-555-0139       |Work           |[email protected]    |             0|7297 RisingView           |            |Redmond      |Washington       |98052     |United States    |                     |
             154|     |Raymond    |K               |Sam              |      |Production Technician - WC20            |226-555-0197       |Work           |[email protected]    |             0|9784 Mt Etna Drive        |            |Edmonds      |Washington       |98020     |United States    |                     |
             155|     |Fadi       |K               |Fakhouri         |      |Production Technician - WC20            |935-555-0116       |Work           |[email protected]       |             2|1285 Greenbrier Street    |            |Snohomish    |Washington       |98296     |United States    |                     |
             156|     |Lane       |M               |Sacksteder       |      |Production Technician - WC20            |200-555-0117       |Cell           |[email protected]       |             1|3029 Pastime Dr           |# 2         |Seattle      |Washington       |98104     |United States    |                     |
             157|     |Linda      |A               |Randall          |      |Production Technician - WC20            |696-555-0157       |Work           |[email protected]      |             0|77 Birchwood              |            |Seattle      |Washington       |98104     |United States    |                     |
             158|     |Shelley    |N               |Dyck             |      |Production Technician - WC20            |991-555-0184       |Cell           |[email protected]    |             0|3747 W. Landing Avenue    |            |Monroe       |Washington       |98272     |United States    |                     |
             159|     |Terrence   |W               |Earls            |      |Production Technician - WC20            |110-555-0115       |Work           |[email protected]   |             1|6968 Wren Ave.            |            |Bellevue     |Washington       |98004     |United States    |                     |
             160|     |Jeff       |V               |Hay              |      |Production Supervisor - WC45            |350-555-0167       |Cell           |[email protected]       |             1|3385 Crestview Drive      |            |Everett      |Washington       |98201     |United States    |                     |
             161|     |Kirk       |J               |Koenigsbauer     |      |Production Technician - WC45            |669-555-0150       |Work           |[email protected]       |             1|1220 Bradford Way         |            |Seattle      |Washington       |98104     |United States    |                     |
             162|     |Laura      |C               |Steele           |      |Production Technician - WC45            |777-555-0141       |Work           |[email protected]      |             0|1825 Corte Del Prado      |            |Duvall       |Washington       |98019     |United States    |                     |
             163|     |Alex       |M               |Nayberg          |      |Production Technician - WC45            |819-555-0198       |Work           |[email protected]       |             1|1400 Gate Drive           |            |Newport Hills|Washington       |98006     |United States    |                     |
             164|     |Andrew     |M               |Cencini          |      |Production Technician - WC45            |207-555-0192       |Cell           |[email protected]     |             0|4444 Pepper Way           |            |Sammamish    |Washington       |98074     |United States    |                     |
             165|     |Chris      |T               |Preston          |      |Production Technician - WC45            |200-555-0112       |Cell           |[email protected]      |             0|6657 Sand Pointe Lane     |            |Seattle      |Washington       |98104     |United States    |                     |
             166|     |Jack       |S               |Richins          |      |Production Supervisor - WC30            |552-555-0111       |Work           |[email protected]       |             0|1356 Grove Way            |            |Monroe       |Washington       |98272     |United States    |                     |
             167|     |David      |N               |Johnson          |      |Production Technician - WC30            |166-555-0162       |Cell           |[email protected]      |             0|6697 Ridge Park Drive     |            |Kenmore      |Washington       |98028     |United States    |                     |
             168|     |Garrett    |R               |Young            |      |Production Technician - WC30            |609-555-0179       |Work           |[email protected]    |             2|2115 Passing              |            |Snohomish    |Washington       |98296     |United States    |                     |
             169|     |Susan      |A               |Metters          |      |Production Technician - WC30            |639-555-0164       |Cell           |[email protected]      |             1|9104 Mt. Sequoia Ct.      |            |Sammamish    |Washington       |98074     |United States    |                     |
             170|     |George     |Z               |Li               |      |Production Technician - WC30            |518-555-0199       |Cell           |[email protected]     |             0|3074 Arbor Drive          |            |Carnation    |Washington       |98014     |United States    |                     |
             171|     |David      |A               |Yalovsky         |      |Production Technician - WC30            |373-555-0142       |Work           |[email protected]      |             1|5025 Holiday Hills        |            |Seattle      |Washington       |98104     |United States    |                     |
             172|     |Marc       |J               |Ingle            |      |Production Technician - WC30            |234-555-0169       |Cell           |[email protected]       |             2|2473 Orchard Way          |            |Sammamish    |Washington       |98074     |United States    |                     |
             173|     |Eugene     |R               |Zabokritski      |      |Production Technician - WC30            |241-555-0191       |Cell           |[email protected]     |             0|7939 Bayview Court        |            |Sammamish    |Washington       |98074     |United States    |                     |
             174|     |Benjamin   |R               |Martin           |      |Production Technician - WC30            |533-555-0111       |Cell           |[email protected]   |             2|4231 Spar Court           |            |Snohomish    |Washington       |98296     |United States    |                     |
             175|     |Reed       |T               |Koch             |      |Production Technician - WC30            |678-555-0110       |Work           |[email protected]       |             0|1275 West Street          |            |Redmond      |Washington       |98052     |United States    |                     |
             176|     |David      |Oliver          |Lawrence         |      |Production Technician - WC30            |118-555-0177       |Work           |[email protected]      |             0|158 Walnut Ave            |            |Monroe       |Washington       |98272     |United States    |                     |
             177|     |Russell    |M               |King             |      |Production Technician - WC30            |517-555-0122       |Work           |[email protected]    |             0|3919 Pinto Road           |            |Bellevue     |Washington       |98004     |United States    |                     |
             178|     |John       |N               |Frum             |      |Production Technician - WC30            |663-555-0172       |Cell           |[email protected]       |             2|3665 Oak Creek Ct.        |            |Everett      |Washington       |98201     |United States    |                     |
             179|     |Jan        |S               |Miksovsky        |      |Production Technician - WC30            |139-555-0131       |Work           |[email protected]        |             0|8624 Pepper Way           |            |Everett      |Washington       |98201     |United States    |                     |
             180|     |Katie      |L               |McAskill-White   |      |Production Supervisor - WC20            |809-555-0133       |Work           |[email protected]      |             2|4948 West 4th St          |            |Seattle      |Washington       |98104     |United States    |                     |
             181|     |Michael    |T               |Hines            |      |Production Technician - WC20            |218-555-0126       |Work           |[email protected]    |             0|1792 Belmont Rd.          |            |Monroe       |Washington       |98272     |United States    |                     |
             182|     |Nitin      |S               |Mirchandani      |      |Production Technician - WC20            |143-555-0173       |Cell           |[email protected]      |             0|4096 San Remo             |            |Sammamish    |Washington       |98074     |United States    |                     |
             183|     |Barbara    |S               |Decker           |      |Production Technician - WC20            |119-555-0192       |Cell           |[email protected]    |             0|7145 Matchstick Drive     |            |Sammamish    |Washington       |98074     |United States    |                     |
             184|     |John       |Y               |Chen             |      |Production Technician - WC20            |201-555-0163       |Cell           |[email protected]       |             2|3977 Central Avenue       |            |Duvall       |Washington       |98019     |United States    |                     |
             185|     |Stefen     |A               |Hesse            |      |Production Technician - WC20            |165-555-0113       |Cell           |[email protected]     |             1|8463 Vista Avenue         |            |Duvall       |Washington       |98019     |United States    |                     |
             186|     |Shane      |S               |Kim              |      |Production Supervisor - WC45            |810-555-0178       |Cell           |[email protected]      |             2|9745 Bonita Ct.           |            |Bellevue     |Washington       |98004     |United States    |                     |
             187|     |Yvonne     |S               |McKay            |      |Production Technician - WC45            |286-555-0189       |Work           |[email protected]     |             0|1962 Cotton Ct.           |            |Everett      |Washington       |98201     |United States    |                     |
             188|     |Douglas    |B               |Hite             |      |Production Technician - WC45            |808-555-0172       |Cell           |[email protected]    |             1|390 Ridgewood Ct.         |            |Carnation    |Washington       |98014     |United States    |                     |
             189|     |Janeth     |M               |Esteves          |      |Production Technician - WC45            |540-555-0191       |Work           |[email protected]     |             1|4566 La Jolla             |            |Monroe       |Washington       |98272     |United States    |                     |
             190|     |Robert     |J               |Rounthwaite      |      |Production Technician - WC45            |589-555-0147       |Cell           |[email protected]     |             0|6843 San Simeon Dr.       |            |Seattle      |Washington       |98104     |United States    |                     |
             191|     |Lionel     |C               |Penuchot         |      |Production Technician - WC45            |450-555-0152       |Cell           |[email protected]     |             1|7765 Sunsine Drive        |            |Seattle      |Washington       |98104     |United States    |                     |
             192|     |Brenda     |M               |Diaz             |      |Production Supervisor - WC40            |142-555-0139       |Work           |[email protected]     |             1|1349 Steven Way           |            |Seattle      |Washington       |98104     |United States    |                     |
             193|     |Alejandro  |E               |McGuel           |      |Production Technician - WC40            |668-555-0130       |Work           |[email protected]  |             0|7127 Los Gatos Court      |            |Seattle      |Washington       |98104     |United States    |                     |
             194|     |Fred       |T               |Northup          |      |Production Technician - WC40            |818-555-0192       |Cell           |[email protected]       |             0|2601 Cambridge Drive      |            |Snohomish    |Washington       |98296     |United States    |                     |
             195|     |Kevin      |H               |Liu              |      |Production Technician - WC40            |714-555-0138       |Work           |[email protected]      |             2|7594 Alexander Pl.        |            |Seattle      |Washington       |98104     |United States    |                     |
             196|     |Shammi     |G               |Mohamed          |      |Production Technician - WC40            |793-555-0179       |Cell           |[email protected]     |             0|332 Laguna Niguel         |            |Bellevue     |Washington       |98004     |United States    |                     |
             197|     |Rajesh     |M               |Patel            |      |Production Technician - WC40            |373-555-0137       |Cell           |[email protected]     |             1|5423 Champion Rd.         |            |Edmonds      |Washington       |98020     |United States    |                     |
             198|     |Lorraine   |O               |Nay              |      |Production Technician - WC40            |845-555-0184       |Work           |[email protected]   |             1|2059 Clay Rd              |            |Edmonds      |Washington       |98020     |United States    |                     |
             199|     |Paula      |R               |Nartker          |      |Production Technician - WC40            |476-555-0119       |Cell           |[email protected]      |             1|2144 San Rafael           |            |Seattle      |Washington       |98104     |United States    |                     |
             200|     |Frank      |T               |Lee              |      |Production Technician - WC40            |158-555-0191       |Cell           |[email protected]      |             0|8290 Margaret Ct.         |            |Seattle      |Washington       |98104     |United States    |                     |
             201|     |Brian      |T               |Lloyd            |      |Production Technician - WC40            |110-555-0182       |Cell           |[email protected]      |             0|7230 Vine Maple Street    |            |Snohomish    |Washington       |98296     |United States    |                     |
             202|     |Tawana     |G               |Nusbaum          |      |Production Technician - WC40            |368-555-0113       |Work           |[email protected]     |             0|9964 North Ridge Drive    |            |Seattle      |Washington       |98104     |United States    |                     |
             203|     |Ken        |L               |Myer             |      |Production Technician - WC40            |949-555-0174       |Work           |[email protected]        |             1|1362 Somerset Place       |            |Everett      |Washington       |98201     |United States    |                     |
             204|     |Gabe       |B               |Mares            |      |Production Technician - WC40            |310-555-0117       |Work           |[email protected]       |             0|1061 Buskrik Avenue       |            |Edmonds      |Washington       |98020     |United States    |                     |
             205|     |Lori       |A               |Kane             |      |Production Supervisor - WC45            |289-555-0196       |Cell           |[email protected]       |             0|3066 Wallace Dr.          |            |Redmond      |Washington       |98052     |United States    |                     |
             206|     |Stuart     |V               |Munson           |      |Production Technician - WC45            |413-555-0136       |Cell           |[email protected]     |             2|6448 Castle Court         |            |Bellevue     |Washington       |98004     |United States    |                     |
             207|     |Greg       |F               |Alderson         |      |Production Technician - WC45            |332-555-0150       |Work           |[email protected]       |             0|8684 Military East        |            |Bellevue     |Washington       |98004     |United States    |                     |
             208|     |Scott      |R               |Gode             |      |Production Technician - WC45            |391-555-0138       |Cell           |[email protected]      |             0|7403 N. Broadway          |            |Seattle      |Washington       |98104     |United States    |                     |
             209|     |Kathie     |E               |Flood            |      |Production Technician - WC45            |446-555-0118       |Work           |[email protected]     |             0|9241 St George Dr.        |            |Everett      |Washington       |98201     |United States    |                     |
             210|     |Belinda    |M               |Newman           |      |Production Technician - WC45            |319-555-0126       |Cell           |[email protected]    |             2|1399 Firestone Drive      |            |Bothell      |Washington       |98011     |United States    |                     |
             211|     |Hazem      |E               |Abolrous         |      |Quality Assurance Manager               |869-555-0125       |Work           |[email protected]      |             0|5050 Mt. Wilson Way       |            |Kenmore      |Washington       |98028     |United States    |                     |
             212|     |Peng       |J               |Wu               |      |Quality Assurance Supervisor            |164-555-0164       |Work           |[email protected]       |             2|250 Race Court            |            |Bothell      |Washington       |98011     |United States    |                     |
             213|     |Sootha     |T               |Charncherngkha   |      |Quality Assurance Technician            |325-555-0137       |Work           |[email protected]     |             0|4155 Working Drive        |            |Kenmore      |Washington       |98028     |United States    |                     |
             214|     |Andreas    |T               |Berglund         |      |Quality Assurance Technician            |181-555-0124       |Cell           |[email protected]    |             0|1803 Olive Hill           |            |Renton       |Washington       |98055     |United States    |                     |
             215|     |Mark       |L               |Harrington       |      |Quality Assurance Technician            |147-555-0179       |Cell           |[email protected]       |             0|8585 Los Gatos Ct.        |            |Issaquah     |Washington       |98027     |United States    |                     |
             216|     |Sean       |P               |Alexander        |      |Quality Assurance Technician            |420-555-0173       |Cell           |[email protected]       |             2|7985 Center Street        |            |Renton       |Washington       |98055     |United States    |                     |
             217|     |Zainal     |T               |Arifin           |      |Document Control Manager                |204-555-0115       |Cell           |[email protected]     |             1|342 San Simeon            |            |Issaquah     |Washington       |98027     |United States    |                     |
             218|     |Tengiz     |N               |Kharatishvili    |      |Control Specialist                      |910-555-0116       |Work           |[email protected]     |             1|3333 Madhatter Circle     |            |Issaquah     |Washington       |98027     |United States    |                     |
             219|     |Sean       |N               |Chai             |      |Document Control Assistant              |205-555-0132       |Cell           |[email protected]       |             0|9314 Icicle Way           |            |Issaquah     |Washington       |98027     |United States    |                     |
             220|     |Karen      |R               |Berge            |      |Document Control Assistant              |746-555-0164       |Work           |[email protected]      |             0|3127 El Camino Drive      |            |Index        |Washington       |98256     |United States    |                     |
             221|     |Chris      |K               |Norred           |      |Control Specialist                      |575-555-0126       |Cell           |[email protected]      |             0|989 Crown Ct              |            |Issaquah     |Washington       |98027     |United States    |                     |
             222|     |A. Scott   |                |Wright           |      |Master Scheduler                        |992-555-0194       |Cell           |[email protected]     |             0|9297 Kenston Dr.          |            |Newport Hills|Washington       |98006     |United States    |                     |
             223|     |Sairaj     |L               |Uddin            |      |Scheduling Assistant                    |500-555-0159       |Cell           |[email protected]     |             0|8040 Hill Ct              |            |Redmond      |Washington       |98052     |United States    |                     |
             224|     |William    |S               |Vong             |      |Scheduling Assistant                    |148-555-0145       |Cell           |[email protected]    |             2|6774 Bonanza              |            |Bellevue     |Washington       |98004     |United States    |                     |
             225|     |Alan       |J               |Brewer           |      |Scheduling Assistant                    |438-555-0172       |Work           |[email protected]       |             0|25 95th Ave NE            |            |Kenmore      |Washington       |98028     |United States    |                     |
             226|     |Brian      |P               |LaMee            |      |Scheduling Assistant                    |313-555-0196       |Cell           |[email protected]      |             0|2294 West 39th St.        |            |Everett      |Washington       |98201     |United States    |                     |
             227|     |Gary       |E.              |Altman           |III   |Facilities Manager                      |110-555-0112       |Cell           |[email protected]       |             0|2598 Breck Court          |            |Renton       |Washington       |98055     |United States    |                     |
             228|     |Christian  |E               |Kleinerman       |      |Maintenance Supervisor                  |846-555-0157       |Cell           |[email protected]  |             0|8036 Summit View Dr.      |            |Gold Bar     |Washington       |98251     |United States    |                     |
             229|     |Lori       |K               |Penor            |      |Janitor                                 |295-555-0161       |Cell           |[email protected]       |             0|3514 Sunshine             |            |Index        |Washington       |98256     |United States    |                     |
             230|     |Stuart     |J               |Macrae           |      |Janitor                                 |539-555-0149       |Work           |[email protected]     |             0|2266 Greenwood Circle     |            |Renton       |Washington       |98055     |United States    |                     |
             231|     |Jo         |L               |Berry            |      |Janitor                                 |228-555-0159       |Cell           |[email protected]         |             0|1748 Bird Drive           |            |Index        |Washington       |98256     |United States    |                     |
             232|     |Pat        |H               |Coleman          |      |Janitor                                 |720-555-0158       |Work           |[email protected]        |             0|2425 Notre Dame Ave       |            |Gold Bar     |Washington       |98251     |United States    |                     |
             233|     |Magnus     |E               |Hedlund          |      |Facilities Administrative Assistant     |583-555-0182       |Work           |[email protected]     |             0|9533 Working Drive        |            |Renton       |Washington       |98055     |United States    |                     |
             234|     |Laura      |F               |Norman           |      |Chief Financial Officer                 |615-555-0110       |Cell           |[email protected]      |             1|6937 E. 42nd Street       |            |Renton       |Washington       |98055     |United States    |                     |
             235|     |Paula      |M               |Barreto de Mattos|      |Human Resources Manager                 |523-555-0175       |Cell           |[email protected]      |             2|4311 Clay Rd              |            |Bellevue     |Washington       |98004     |United States    |                     |
             236|     |Grant      |N               |Culbertson       |      |Human Resources Administrative Assistant|955-555-0131       |Work           |[email protected]      |             2|213 Stonewood Drive       |            |Gold Bar     |Washington       |98251     |United States    |                     |
             237|     |Hao        |O               |Chen             |      |Human Resources Administrative Assistant|806-555-0136       |Work           |[email protected]        |             0|7691 Benedict Ct.         |# 141       |Issaquah     |Washington       |98027     |United States    |                     |
             238|     |Vidur      |X               |Luthra           |      |Recruiter                               |153-555-0186       |Work           |[email protected]      |             0|3030 Blackburn Ct.        |            |Newport Hills|Washington       |98006     |United States    |                     |
             239|     |Mindy      |C               |Martin           |      |Benefits Specialist                     |522-555-0147       |Work           |[email protected]      |             0|9687 Shakespeare Drive    |            |Newport Hills|Washington       |98006     |United States    |                     |
             240|     |Willis     |T               |Johnson          |      |Recruiter                               |778-555-0141       |Work           |[email protected]     |             0|5452 Corte Gilberto       |            |Everett      |Washington       |98201     |United States    |                     |
             241|     |David      |J               |Liu              |      |Accounts Manager                        |646-555-0185       |Work           |[email protected]      |             0|9605 Pheasant Circle      |            |Gold Bar     |Washington       |98251     |United States    |                     |
             242|     |Deborah    |E               |Poe              |      |Accounts Receivable Specialist          |602-555-0194       |Cell           |[email protected]    |             0|7640 First Ave.           |            |Everett      |Washington       |98201     |United States    |                     |
             243|     |Candy      |L               |Spoon            |      |Accounts Receivable Specialist          |920-555-0177       |Cell           |[email protected]      |             0|310 Winter Lane           |            |Index        |Washington       |98256     |United States    |                     |
             244|     |Bryan      |A               |Walton           |      |Accounts Receivable Specialist          |935-555-0199       |Work           |[email protected]      |             0|1397 Paradise Ct.         |            |Newport Hills|Washington       |98006     |United States    |                     |
             245|     |Barbara    |C               |Moreland         |      |Accountant                              |822-555-0145       |Cell           |[email protected]    |             0|137 Mazatlan              |            |Seattle      |Washington       |98104     |United States    |                     |
             246|     |Dragan     |K               |Tomic            |      |Accounts Payable Specialist             |117-555-0185       |Work           |[email protected]     |             1|3884 Beauty Street        |# 14        |Gold Bar     |Washington       |98251     |United States    |                     |
             247|     |Janet      |L               |Sheperdigian     |      |Accounts Payable Specialist             |393-555-0186       |Work           |[email protected]      |             0|6871 Thornwood Dr.        |            |Sammamish    |Washington       |98074     |United States    |                     |
             248|     |Mike       |K               |Seamans          |      |Accountant                              |927-555-0150       |Work           |[email protected]       |             2|1245 Clay Road            |            |Index        |Washington       |98256     |United States    |                     |
             249|     |Wendy      |Beth            |Kahn             |      |Finance Manager                         |248-555-0134       |Work           |[email protected]      |             2|4525 Benedict Ct.         |            |Sammamish    |Washington       |98074     |United States    |                     |
             250|     |Sheela     |H               |Word             |      |Purchasing Manager                      |210-555-0193       |Work           |[email protected]     |             0|535 Greendell Pl          |            |Sammamish    |Washington       |98074     |United States    |                     |
             251|     |Mikael     |Q               |Sandberg         |      |Buyer                                   |309-555-0170       |Work           |[email protected]     |             2|9539 Glenside Dr          |            |Bothell      |Washington       |98011     |United States    |                     |
             252|     |Arvind     |B               |Rao              |      |Buyer                                   |848-555-0163       |Cell           |[email protected]     |             0|9495 Limewood Place       |            |Renton       |Washington       |98055     |United States    |                     |
             253|     |Linda      |P               |Meisner          |      |Buyer                                   |916-555-0165       |Cell           |[email protected]      |             0|6118 Grasswood Circle     |            |Bellevue     |Washington       |98004     |United States    |                     |
             254|     |Fukiko     |J               |Ogisu            |      |Buyer                                   |520-555-0177       |Work           |[email protected]     |             0|8751 Norse Drive          |            |Bellevue     |Washington       |98004     |United States    |                     |
             255|     |Gordon     |L               |Hee              |      |Buyer                                   |230-555-0144       |Cell           |[email protected]     |             0|108 Lakeside Court        |            |Bellevue     |Washington       |98004     |United States    |                     |
             256|     |Frank      |S               |Pellow           |      |Buyer                                   |163-555-0147       |Cell           |[email protected]      |             0|5980 Icicle Circle        |Unit H      |Renton       |Washington       |98055     |United States    |                     |
             257|     |Eric       |S               |Kurjan           |      |Buyer                                   |265-555-0195       |Work           |[email protected]       |             2|1378 String Dr            |            |Renton       |Washington       |98055     |United States    |                     |
             258|     |Erin       |M               |Hagens           |      |Buyer                                   |842-555-0158       |Work           |[email protected]       |             0|2947 Vine Lane            |            |Bellevue     |Washington       |98004     |United States    |                     |
             259|     |Ben        |T               |Miller           |      |Buyer                                   |151-555-0113       |Work           |[email protected]        |             0|101 Candy Rd.             |            |Redmond      |Washington       |98052     |United States    |                     |
             260|     |Annette    |L               |Hill             |      |Purchasing Assistant                    |125-555-0196       |Cell           |[email protected]    |             1|6369 Ellis Street         |            |Redmond      |Washington       |98052     |United States    |                     |
             261|     |Reinout    |N               |Hillmann         |      |Purchasing Assistant                    |370-555-0163       |Work           |[email protected]    |             2|620 Woodside Ct.          |            |Bellevue     |Washington       |98004     |United States    |                     |
             262|     |David      |M               |Barber           |      |Assistant to the Chief Financial Officer|477-555-0132       |Work           |[email protected]      |             0|8967 Hamilton Ave.        |            |Newport Hills|Washington       |98006     |United States    |                     |
             263|     |Jean       |E               |Trenary          |      |Information Services Manager            |685-555-0120       |Work           |[email protected]       |             2|2383 Pepper Drive         |            |Redmond      |Washington       |98052     |United States    |                     |
             264|     |Stephanie  |A               |Conroy           |      |Network Manager                         |594-555-0110       |Work           |[email protected]  |             2|7435 Ricardo              |            |Issaquah     |Washington       |98027     |United States    |                     |
             265|     |Ashvini    |R               |Sharma           |      |Network Administrator                   |656-555-0119       |Work           |[email protected]    |             1|6580 Poor Ridge Court     |            |Issaquah     |Washington       |98027     |United States    |                     |
             266|     |Peter      |I               |Connelly         |      |Network Administrator                   |310-555-0133       |Work           |[email protected]      |             0|9530 Vine Lane            |            |Issaquah     |Washington       |98027     |United States    |                     |
             267|     |Karen      |A               |Berg             |      |Application Specialist                  |654-555-0177       |Work           |[email protected]      |             0|5256 Chickpea Ct.         |            |Issaquah     |Washington       |98027     |United States    |                     |
             268|     |Ramesh     |V               |Meyyappan        |      |Application Specialist                  |182-555-0134       |Work           |[email protected]     |             1|3848 East 39th Street     |            |Issaquah     |Washington       |98027     |United States    |                     |
             269|     |Dan        |K               |Bacon            |Jr.   |Application Specialist                  |166-555-0159       |Work           |[email protected]        |             0|1921 Ranch Road           |            |Issaquah     |Washington       |98027     |United States    |                     |
             270|     |François   |P               |Ajenstat         |      |Database Administrator                  |785-555-0110       |Cell           |franç[email protected]   |             0|1144 Paradise Ct.         |            |Issaquah     |Washington       |98027     |United States    |                     |
             271|     |Dan        |B               |Wilson           |      |Database Administrator                  |653-555-0144       |Work           |[email protected]        |             0|5863 Sierra               |            |Bellevue     |Washington       |98004     |United States    |                     |
             272|     |Janaina    |Barreiro Gambaro|Bueno            |      |Application Specialist                  |623-555-0155       |Work           |[email protected]    |             0|5979 El Pueblo            |            |Issaquah     |Washington       |98027     |United States    |                     |
             273|Mr.  |Brian      |S               |Welcker          |      |Vice President of Sales                 |716-555-0127       |Cell           |[email protected]      |             0|7772 Golden Meadow        |            |Issaquah     |Washington       |98027     |United States    |                     |
             274|     |Stephen    |Y               |Jiang            |      |North American Sales Manager            |238-555-0197       |Cell           |[email protected]    |             0|2427 Notre Dame Ave.      |            |Redmond      |Washington       |98052     |United States    |                     |
             275|     |Michael    |G               |Blythe           |      |Sales Representative                    |257-555-0154       |Cell           |[email protected]    |             1|8154 Via Mexico           |            |Detroit      |Michigan         |48226     |United States    |                     |
             276|     |Linda      |C               |Mitchell         |      |Sales Representative                    |883-555-0116       |Work           |[email protected]      |             0|2487 Riverside Drive      |            |Nevada       |Utah             |84407     |United States    |                     |
             277|     |Jillian    |                |Carson           |      |Sales Representative                    |517-555-0117       |Work           |[email protected]    |             1|80 Sunview Terrace        |            |Duluth       |Minnesota        |55802     |United States    |                     |
             278|     |Garrett    |R               |Vargas           |      |Sales Representative                    |922-555-0165       |Work           |[email protected]    |             0|10203 Acorn Avenue        |            |Calgary      |Alberta          |T2P 2G8   |Canada           |                     |
             279|     |Tsvi       |Michael         |Reiter           |      |Sales Representative                    |664-555-0112       |Work           |[email protected]       |             1|8291 Crossbow Way         |            |Memphis      |Tennessee        |38103     |United States    |                     |
             280|     |Pamela     |O               |Ansman-Wolfe     |      |Sales Representative                    |340-555-0193       |Cell           |[email protected]     |             1|636 Vine Hill Way         |            |Portland     |Oregon           |97205     |United States    |                     |
             281|     |Shu        |K               |Ito              |      |Sales Representative                    |330-555-0120       |Cell           |[email protected]        |             2|5725 Glaze Drive          |            |San Francisco|California       |94109     |United States    |                     |
             282|     |José       |Edvaldo         |Saraiva          |      |Sales Representative                    |185-555-0169       |Work           |josé[email protected]       |             0|9100 Sheppard Avenue North|            |Ottawa       |Ontario          |K4B 1T7   |Canada           |                     |
             283|     |David      |R               |Campbell         |      |Sales Representative                    |740-555-0182       |Work           |[email protected]      |             0|2284 Azalea Avenue        |            |Bellevue     |Washington       |98004     |United States    |                     |
             284|Mr.  |Tete       |A               |Mensa-Annan      |      |Sales Representative                    |615-555-0153       |Work           |[email protected]       |             1|3997 Via De Luna          |            |Cambridge    |Massachusetts    |02139     |United States    |                     |
             285|Mr.  |Syed       |E               |Abbas            |      |Pacific Sales Manager                   |926-555-0182       |Work           |[email protected]       |             0|7484 Roundtree Drive      |            |Bothell      |Washington       |98011     |United States    |                     |
             286|     |Lynn       |N               |Tsoflias         |      |Sales Representative                    |1 (11) 500 555-0190|Cell           |[email protected]       |             2|34 Waterloo Road          |            |Melbourne    |Victoria         |3000      |Australia        |                     |
             287|     |Amy        |E               |Alberts          |      |European Sales Manager                  |775-555-0164       |Work           |[email protected]        |             1|5009 Orange Street        |            |Renton       |Washington       |98055     |United States    |                     |
             288|     |Rachel     |B               |Valdez           |      |Sales Representative                    |1 (11) 500 555-0140|Cell           |[email protected]     |             0|Pascalstr 951             |            |Berlin       |Hamburg          |14111     |Germany          |                     |
             289|     |Jae        |B               |Pak              |      |Sales Representative                    |1 (11) 500 555-0145|Work           |[email protected]        |             0|Downshire Way             |            |Cambridge    |England          |BA5 3HX   |United Kingdom   |                     |
             290|     |Ranjit     |R               |Varkey Chudukatil|      |Sales Representative                    |1 (11) 500 555-0117|Cell           |[email protected]     |             0|94, rue Descartes         |            |Bordeaux     |Gironde          |33000     |France           |                     |

Click to view Full table

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname  |lastname         |rate   |
-----------+-----------------+-------+
Marc       |Ingle            |    6.5|
George     |Li               |    6.5|
David      |Johnson          |    6.5|
John       |Frum             |    6.5|
Russell    |King             |    6.5|
David      |Lawrence         |    6.5|
Reed       |Koch             |    6.5|
Benjamin   |Martin           |   6.75|
John       |Frum             |      7|
George     |Li               |   7.25|
Marc       |Ingle            |   7.25|
...

Click me to see the solution

144. From the follwing table write a query in SQL to retrieve rows whose datetime values are between '20111212' and '20120105'.

Sample table: HumanResources.EmployeePayHistory
businessentityid|ratechangedate         |rate   |payfrequency|modifieddate           |
----------------+-----------------------+-------+------------+-----------------------+
               1|2009-01-14 00:00:00.000|  125.5|           2|2014-06-30 00:00:00.000|
               2|2008-01-31 00:00:00.000|63.4615|           2|2014-06-30 00:00:00.000|
               3|2007-11-11 00:00:00.000|43.2692|           2|2014-06-30 00:00:00.000|
               4|2007-12-05 00:00:00.000|   8.62|           2|2007-11-21 00:00:00.000|
               4|2010-05-31 00:00:00.000|  23.72|           2|2010-05-16 00:00:00.000|
               4|2011-12-15 00:00:00.000|29.8462|           2|2011-12-01 00:00:00.000|
               5|2008-01-06 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               6|2008-01-24 00:00:00.000|32.6923|           2|2014-06-30 00:00:00.000|
               7|2009-02-08 00:00:00.000|50.4808|           2|2014-06-30 00:00:00.000|
               8|2008-12-29 00:00:00.000|40.8654|           2|2014-06-30 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|ratechangedate         |
----------------+-----------------------+
               4|2011-12-15 00:00:00.000|
             224|2012-01-01 00:00:00.000|

Click me to see the solution

145. From the following table write a query in SQL to return TRUE even if NULL is specified in the subquery. Return DepartmentID, Name and sort the result set in ascending order.

Sample table: HumanResources.Department
departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

departmentid|name                      |
------------+--------------------------+
          12|Document Control          |
           1|Engineering               |
          16|Executive                 |
          14|Facilities and Maintenance|
          10|Finance                   |
           9|Human Resources           |
          11|Information Services      |
           4|Marketing                 |
           7|Production                |
           8|Production Control        |
           5|Purchasing                |
          13|Quality Assurance         |
           6|Research and Development  |
           3|Sales                     |
          15|Shipping and Receiving    |
           2|Tool Design               |

Click me to see the solution

146. From the following tables write a query in SQL to get employees with Johnson last names. Return first name and last name.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname|lastname|
---------+--------+
Barry    |Johnson |
David    |Johnson |
Willis   |Johnson |	

Click me to see the solution

147. From the following tables write a query in SQL to find stores whose name is the same name as a vendor.

Sample table: Sales.Store
businessentityid|name                                     |salespersonid|demographics|rowguid                             |modifieddate           |
----------------+-----------------------------------------+-------------+------------+------------------------------------+-----------------------+
             292|Next-Door Bike Store                     |          279|[XML]       |a22517e3-848d-4ebe-b9d9-7437f3432304|2014-09-12 11:15:07.497|
             294|Professional Sales and Service           |          276|[XML]       |b50ca50b-c601-4a13-b07e-2c63862d71b4|2014-09-12 11:15:07.497|
             296|Riders Company                           |          277|[XML]       |337c3688-1339-4e1a-a08a-b54b23566e49|2014-09-12 11:15:07.497|
             298|The Bike Mechanics                       |          275|[XML]       |7894f278-f0c8-4d16-bd75-213fdbf13023|2014-09-12 11:15:07.497|
             300|Nationwide Supply                        |          286|[XML]       |c3fc9705-a8c4-4f3a-9550-eb2fa4b7b64d|2014-09-12 11:15:07.497|
             302|Area Bike Accessories                    |          281|[XML]       |368be6dd-30e5-49bb-9a86-71fd49c58f4e|2014-09-12 11:15:07.497|
             304|Bicycle Accessories and Kits             |          283|[XML]       |35f40636-5105-49d5-869e-27e231189150|2014-09-12 11:15:07.497|
             306|Clamps & Brackets Co.                    |          275|[XML]       |64d06bfc-d060-405c-8c60-c067fe7c67df|2014-09-12 11:15:07.497|
             308|Valley Bicycle Specialists               |          277|[XML]       |59386b0c-652e-4668-b44b-4e1711793330|2014-09-12 11:15:07.497|
             310|New Bikes Company                        |          279|[XML]       |47e4b6bd-5cd1-45a3-a231-79d930381c56|2014-09-12 11:15:07.497|
             312|Vinyl and Plastic Goods Corporation      |          282|[XML]       |dc610525-e373-49b1-b786-ea040ec25c06|2014-09-12 11:15:07.497|
             314|Top of the Line Bikes                    |          288|[XML]       |e290e93f-a980-4ba3-86c3-9858f15c8a6d|2014-09-12 11:15:07.497|
-- more --

Click to view Full table

Sample table: Purchasing.Vendor
businessentityid|accountnumber|name                             |creditrating|preferredvendorstatus|activeflag|purchasingwebserviceurl    |modifieddate           |
----------------+-------------+---------------------------------+------------+---------------------+----------+---------------------------+-----------------------+
            1492|AUSTRALI0001 |Australia Bike Retailer          |           1|true                 |true      |                           |2011-12-23 00:00:00.000|
            1494|ALLENSON0001 |Allenson Cycles                  |           2|true                 |true      |                           |2011-04-25 00:00:00.000|
            1496|ADVANCED0001 |Advanced Bicycles                |           1|true                 |true      |                           |2011-04-25 00:00:00.000|
            1498|TRIKES0001   |Trikes, Inc.                     |           2|true                 |true      |                           |2012-02-03 00:00:00.000|
            1500|MORGANB0001  |Morgan Bike Accessories          |           1|true                 |true      |                           |2012-02-02 00:00:00.000|
            1502|CYCLING0001  |Cycling Master                   |           1|true                 |true      |                           |2011-12-24 00:00:00.000|
            1504|CHICAGO0002  |Chicago Rent-All                 |           2|true                 |true      |                           |2011-12-24 00:00:00.000|
            1506|GREENWOO0001 |Greenwood Athletic Company       |           1|true                 |true      |                           |2012-01-25 00:00:00.000|
            1508|COMPETE0001  |Compete Enterprises, Inc         |           1|true                 |true      |                           |2011-12-24 00:00:00.000|
            1510|INTERNAT0001 |International                    |           1|true                 |true      |                           |2012-01-25 00:00:00.000|
            1512|LIGHTSP0001  |Light Speed                      |           1|true                 |true      |                           |2011-12-23 00:00:00.000|
            1514|TRAINING0001 |Training Systems                 |           1|true                 |true      |                           |2012-02-03 00:00:00.000|
			-- more --

Click to view Full table

Sample Output:

name|
----+

Click me to see the solution

148. From the following tables write a query in SQL to find employees of departments that start with P. Return first name, last name, job title.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.Department
departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample table: HumanResources.EmployeeDepartmentHistory
businessentityid|departmentid|shiftid|startdate |enddate   |modifieddate           |
----------------+------------+-------+----------+----------+-----------------------+
               1|          16|      1|2009-01-14|          |2009-01-13 00:00:00.000|
               2|           1|      1|2008-01-31|          |2008-01-30 00:00:00.000|
               3|           1|      1|2007-11-11|          |2007-11-10 00:00:00.000|
               4|           1|      1|2007-12-05|2010-05-30|2010-05-28 00:00:00.000|
               4|           2|      1|2010-05-31|          |2010-05-30 00:00:00.000|
               5|           1|      1|2008-01-06|          |2008-01-05 00:00:00.000|
               6|           1|      1|2008-01-24|          |2008-01-23 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname  |lastname       |jobtitle                    |
-----------+---------------+----------------------------+
David      |Bradley        |Marketing Manager           |
James      |Hamilton       |Vice President of Production|
Peter      |Krebs          |Production Control Manager  |
Jo         |Brown          |Production Supervisor - WC60|
Guy        |Gilbert        |Production Technician - WC60|
Mark       |McArthur       |Production Technician - WC60|
Britta     |Simon          |Production Technician - WC60|
Margie     |Shoop          |Production Technician - WC60|
Rebecca    |Laszlo         |Production Technician - WC60|
Annik      |Stahl          |Production Technician - WC60|
Suchitra   |Mohan          |Production Technician - WC60|
Brandon    |Heidepriem     |Production Technician - WC60|
....

Click me to see the solution

149. From the following tables write a query in SQL to find all employees that do not belong to departments whose names begin with P.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.Department
departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample table: HumanResources.EmployeeDepartmentHistory
businessentityid|departmentid|shiftid|startdate |enddate   |modifieddate           |
----------------+------------+-------+----------+----------+-----------------------+
               1|          16|      1|2009-01-14|          |2009-01-13 00:00:00.000|
               2|           1|      1|2008-01-31|          |2008-01-30 00:00:00.000|
               3|           1|      1|2007-11-11|          |2007-11-10 00:00:00.000|
               4|           1|      1|2007-12-05|2010-05-30|2010-05-28 00:00:00.000|
               4|           2|      1|2010-05-31|          |2010-05-30 00:00:00.000|
               5|           1|      1|2008-01-06|          |2008-01-05 00:00:00.000|
               6|           1|      1|2008-01-24|          |2008-01-23 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname|lastname         |jobtitle                                |
---------+-----------------+----------------------------------------+
Syed     |Abbas            |Pacific Sales Manager                   |
Hazem    |Abolrous         |Quality Assurance Manager               |
Pilar    |Ackerman         |Shipping and Receiving Supervisor       |
François |Ajenstat         |Database Administrator                  |
Amy      |Alberts          |European Sales Manager                  |
Sean     |Alexander        |Quality Assurance Technician            |
Gary     |Altman           |Facilities Manager                      |
Pamela   |Ansman-Wolfe     |Sales Representative                    |
Zainal   |Arifin           |Document Control Manager                |
Dan      |Bacon            |Application Specialist                  |
David    |Barber           |Assistant to the Chief Financial Officer|
Paula    |Barreto de Mattos|Human Resources Manager                 |
...

Click me to see the solution

150. From the following table write a query in SQL to select employees who work as design engineers, tool designers, or marketing assistants.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

firstname|lastname |jobtitle           |
---------+---------+-------------------+
Gail     |Erickson |Design Engineer    |
Jossef   |Goldberg |Design Engineer    |
Thierry  |D'Hers   |Tool Designer      |
Janice   |Galvin   |Tool Designer      |
Sharon   |Salavaria|Design Engineer    |
Kevin    |Brown    |Marketing Assistant|
Mary     |Dempsey  |Marketing Assistant|
Wanida   |Benshoof |Marketing Assistant| 

Click me to see the solution

151. From the following tables write a query in SQL to identify all SalesPerson IDs for employees with sales quotas over $250,000. Return first name, last name of the sales persons.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Sales.SalesPerson
businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample Output:

firstname|lastname   |
---------+-----------+
Michael  |Blythe     |
Tsvi     |Reiter     |
Tete     |Mensa-Annan|

Click me to see the solution

152. From the following tables write a query in SQL to find the salespersons who do not have a quota greater than $250,000. Return first name and last name.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Sales.SalesPerson
businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample Output:

firstname|lastname         |
---------+-----------------+
Stephen  |Jiang            |
Linda    |Mitchell         |
Jillian  |Carson           |
Garrett  |Vargas           |
Pamela   |Ansman-Wolfe     |
Shu      |Ito              |
José     |Saraiva          |
David    |Campbell         |
Syed     |Abbas            |
Lynn     |Tsoflias         |
Amy      |Alberts          |
Rachel   |Valdez           |
Jae      |Pak              |
Ranjit   |Varkey Chudukatil| 

Click me to see the solution

153. From the following tables write a query in SQL to identify salesorderheadersalesreason and SalesReason tables with the same salesreasonid.

Sample table: Sales.salesorderheadersalesreason
salesorderid|salesreasonid|modifieddate           |
------------+-------------+-----------------------+
       43697|            5|2011-05-31 00:00:00.000|
       43697|            9|2011-05-31 00:00:00.000|
       43702|            5|2011-06-01 00:00:00.000|
       43702|            9|2011-06-01 00:00:00.000|
       43703|            5|2011-06-01 00:00:00.000|
       43703|            9|2011-06-01 00:00:00.000|
       43706|            5|2011-06-02 00:00:00.000|
       43706|            9|2011-06-02 00:00:00.000|
       43707|            5|2011-06-02 00:00:00.000|
       43707|            9|2011-06-02 00:00:00.000|
       43709|            5|2011-06-02 00:00:00.000|
       43709|            9|2011-06-02 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: sales.SalesReason
salesreasonid|name                     |reasontype|modifieddate           |
-------------+-------------------------+----------+-----------------------+
            1|Price                    |Other     |2008-04-30 00:00:00.000|
            2|On Promotion             |Promotion |2008-04-30 00:00:00.000|
            3|Magazine Advertisement   |Marketing |2008-04-30 00:00:00.000|
            4|Television  Advertisement|Marketing |2008-04-30 00:00:00.000|
            5|Manufacturer             |Other     |2008-04-30 00:00:00.000|
            6|Review                   |Other     |2008-04-30 00:00:00.000|
            7|Demo Event               |Marketing |2008-04-30 00:00:00.000|
            8|Sponsorship              |Marketing |2008-04-30 00:00:00.000|
            9|Quality                  |Other     |2008-04-30 00:00:00.000|
           10|Other                    |Other     |2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

salesorderid|salesreasonid|modifieddate           |
------------+-------------+-----------------------+
       43697|            5|2011-05-31 00:00:00.000|
       43697|            9|2011-05-31 00:00:00.000|
       43702|            5|2011-06-01 00:00:00.000|
       43702|            9|2011-06-01 00:00:00.000|
       43703|            5|2011-06-01 00:00:00.000|
       43703|            9|2011-06-01 00:00:00.000|
       43706|            5|2011-06-02 00:00:00.000|
       43706|            9|2011-06-02 00:00:00.000|
       43707|            5|2011-06-02 00:00:00.000|
       43707|            9|2011-06-02 00:00:00.000|
       43709|            5|2011-06-02 00:00:00.000|
       43709|            9|2011-06-02 00:00:00.000|
       43710|            5|2011-06-02 00:00:00.000|
       43710|            9|2011-06-02 00:00:00.000|
	   
...	 

Click me to see the solution

154. From the following table write a query in SQL to find all telephone numbers that have area code 415. Returns the first name, last name, and phonenumber. Sort the result set in ascending order by lastname.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Person.PersonPhone
businessentityid|phonenumber        |phonenumbertypeid|modifieddate           |
----------------+-------------------+-----------------+-----------------------+
               1|697-555-0142       |                1|2009-01-07 00:00:00.000|
               2|819-555-0175       |                3|2008-01-24 00:00:00.000|
               3|212-555-0187       |                1|2007-11-04 00:00:00.000|
               4|612-555-0100       |                1|2007-11-28 00:00:00.000|
               5|849-555-0139       |                1|2007-12-30 00:00:00.000|
               6|122-555-0189       |                3|2013-12-16 00:00:00.000|
               7|181-555-0156       |                3|2009-02-01 00:00:00.000|
               8|815-555-0138       |                1|2008-12-22 00:00:00.000|
               9|185-555-0186       |                1|2009-01-09 00:00:00.000|
              10|330-555-2568       |                3|2009-04-26 00:00:00.000|
              11|719-555-0181       |                1|2010-11-28 00:00:00.000|
              12|168-555-0183       |                3|2007-12-04 00:00:00.000|
			  -- more --

Click to view Full table

Sample Output:

firstname|lastname |phonenumber |
---------+---------+------------+
Ruben    |Alonso   |415-555-0124|
Shelby   |Cook     |415-555-0121|
Karen    |Hu       |415-555-0114|
David    |Long     |415-555-0123|
John     |Long     |415-555-0147|
Gilbert  |Ma       |415-555-0138|
Meredith |Moreno   |415-555-0131|
Alexandra|Nelson   |415-555-0174|
Taylor   |Patterson|415-555-0170|
Gabrielle|Russell  |415-555-0197|
Dalton   |Simmons  |415-555-0115|

Click me to see the solution

155. From the following tables write a query in SQL to identify all people with the first name 'Gail' with area codes other than 415. Return first name, last name, telephone number. Sort the result set in ascending order on lastname.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: Person.PersonPhone
businessentityid|phonenumber        |phonenumbertypeid|modifieddate           |
----------------+-------------------+-----------------+-----------------------+
               1|697-555-0142       |                1|2009-01-07 00:00:00.000|
               2|819-555-0175       |                3|2008-01-24 00:00:00.000|
               3|212-555-0187       |                1|2007-11-04 00:00:00.000|
               4|612-555-0100       |                1|2007-11-28 00:00:00.000|
               5|849-555-0139       |                1|2007-12-30 00:00:00.000|
               6|122-555-0189       |                3|2013-12-16 00:00:00.000|
               7|181-555-0156       |                3|2009-02-01 00:00:00.000|
               8|815-555-0138       |                1|2008-12-22 00:00:00.000|
               9|185-555-0186       |                1|2009-01-09 00:00:00.000|
              10|330-555-2568       |                3|2009-04-26 00:00:00.000|
              11|719-555-0181       |                1|2010-11-28 00:00:00.000|
              12|168-555-0183       |                3|2007-12-04 00:00:00.000|
			  -- more --

Click to view Full table

Sample Output:

firstname|lastname |phonenumber        |
---------+---------+-------------------+
Gail     |Alexander|1 (11) 500 555-0120|
Gail     |Butler   |1 (11) 500 555-0191|
Gail     |Erickson |849-555-0139       |
Gail     |Erickson |834-555-0132       |
Gail     |Griffin  |450-555-0171       |
Gail     |Moore    |155-555-0169       |
Gail     |Russell  |334-555-0170       |
Gail     |Westover |305-555-0100       |

Click me to see the solution

156. From the following tables, write a query in SQL to find all silver-colored bicycles with a standard cost not greater than $400. Return the columns ProductID, Name, Color, and StandardCost. Filter the results to include only those products where the ProductNumber starts with 'BK-'.

Sample table: Production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|name                   |color |standardcost|
---------+-----------------------+------+------------+
      984|Mountain-500 Silver, 40|Silver|    308.2179|
      985|Mountain-500 Silver, 42|Silver|    308.2179|
      986|Mountain-500 Silver, 44|Silver|    308.2179|
      987|Mountain-500 Silver, 48|Silver|    308.2179|
      988|Mountain-500 Silver, 52|Silver|    308.2179|

Click me to see the solution

157. From the following table write a query in SQL to retrieve the names of Quality Assurance personnel working the evening or night shifts. Return first name, last name, shift.

Sample table: HumanResources.EmployeeDepartmentHistory
businessentityid|title|firstname  |middlename      |lastname         |suffix|shift  |department                |groupname                           |startdate |enddate   |
----------------+-----+-----------+----------------+-----------------+------+-------+--------------------------+------------------------------------+----------+----------+
               1|     |Ken        |J               |Sánchez          |      |Day    |Executive                 |Executive General and Administration|2009-01-14|          |
               2|     |Terri      |Lee             |Duffy            |      |Day    |Engineering               |Research and Development            |2008-01-31|          |
               3|     |Roberto    |                |Tamburello       |      |Day    |Engineering               |Research and Development            |2007-11-11|          |
               4|     |Rob        |                |Walters          |      |Day    |Engineering               |Research and Development            |2007-12-05|2010-05-30|
               4|     |Rob        |                |Walters          |      |Day    |Tool Design               |Research and Development            |2010-05-31|          |
               5|Ms.  |Gail       |A               |Erickson         |      |Day    |Engineering               |Research and Development            |2008-01-06|          |
               6|Mr.  |Jossef     |H               |Goldberg         |      |Day    |Engineering               |Research and Development            |2008-01-24|          |
               7|     |Dylan      |A               |Miller           |      |Day    |Research and Development  |Research and Development            |2009-02-08|          |
               8|     |Diane      |L               |Margheim         |      |Day    |Research and Development  |Research and Development            |2008-12-29|          |
               9|     |Gigi       |N               |Matthew          |      |Day    |Research and Development  |Research and Development            |2009-01-16|          |
              10|     |Michael    |                |Raheem           |      |Day    |Research and Development  |Research and Development            |2009-05-03|          |
			-- more --

Click to view Full table

Sample Output:

firstname|lastname      |shift  |
---------+--------------+-------+
Sootha   |Charncherngkha|Night  |
Andreas  |Berglund      |Evening| 

Click me to see the solution

158. From the following table write a query in SQL to list all people with three-letter first names ending in 'an'. Sort the result set in ascending order on first name. Return first name and last name.

Sample table: Person.Person
businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

firstname|lastname  |
---------+----------+
Dan      |Bacon     |
Dan      |Wilson    |
Dan      |Wilson    |
Dan      |Bacon     |
Dan      |Baker     |
Dan      |Moyer     |
Dan      |Wilson    |
Ian      |Stewart   |
Ian      |Yuhasz    |
Ian      |Brooks    |
Ian      |Kelly     |
...

Click me to see the solution

159. From the following table write a query in SQL to convert the order date in the 'America/Denver' time zone. Return salesorderid, order date, and orderdate_timezoneade.

Sample table: Sales.SalesOrderHeader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|orderdate              |orderdate_timezoneade        |
------------+-----------------------+-----------------------------+
       43659|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43660|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43661|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43662|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43663|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43664|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43665|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43666|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43667|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
       43668|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|
...	   

Click me to see the solution

160. From the following table write a query in SQL to convert order date in the 'America/Denver' time zone and also convert from 'America/Denver' time zone to 'America/Chicago' time zone.

Sample table: Sales.SalesOrderHeader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|orderdate              |orderdate_timezoneamden      |orderdate_timezoneamchi|
------------+-----------------------+-----------------------------+-----------------------+
       43659|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43660|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43661|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43662|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43663|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43664|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43665|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43666|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43667|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
       43668|2011-05-31 00:00:00.000|2011-05-31 11:30:00.000 +0530|2011-05-31 01:00:00.000|
...		   

Click me to see the solution

161. From the following table wirte a query in SQL to search for rows with the 'green_' character in the LargePhotoFileName column. Return all columns.

Sample table: Production.ProductPhoto
productphotoid|thumbnailphoto                                                                                                                                                                                                                                                 |thumbnailphotofilename             |largephoto                                                                                                                                                                                                                                                     |largephotofilename                 |modifieddate           |
--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+-----------------------+
             1|47494638396150003100F70000000000800000008000808000000080800080008080808080C0C0C0FF000000FF00FFFF000000FFFF00FF00FFFFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|no_image_available_small.gif       |474946383961F0009500F70000000000800000008000808000000080800080008080808080C0C0C0FF000000FF00FFFF000000FFFF00FF00FFFFFFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|no_image_available_large.gif       |2008-04-30 00:00:00.000|
            69|47494638396150003100F70000E3E3FCA6ACB3F5F6FE303D47F8FAFDEDEEFE989DA2F6F8FD6C86B5999B9DD3D3D5E2E5EACCD0D79AA2A8BDBEC2868B93ACB2B8BCBCBE5A6674526A913A4046F9FAFADBDCE9AAABAD656C76BFC0C7E9E9FDDCE1EA27272BEFEFFCDCDEE2C5CCE3CACBCCDADADC94A8C5B1B3B5FEFEFF5B76A86|racer02_black_f_small.gif          |474946383961F0009500F70000D3D3FEE2E3FE86878ADBDCFED7D8E7929BA8545659C9CAD8B7C4CD97999B030405767A8436424F8AAACCF9FAFA96A3AF719BCD7677793A3C40535963EBF3F8656569FAFBFDEBEBECC7C7E4BABCC5F7F9FCDBDCDE738CAEA8ADB327608BCCCCFDE2E3E4778591D2D3D5262629B5D0E25A636ED|racer02_black_f_large.gif          |2008-04-30 00:00:00.000|
            70|47494638396150003100F70000E3E3FCEBECF3F5F6FE999B9DEDEDFEDCE3EB374249B2BCCFABADB2F9FAFDD3D3D4373C44BBBCBEE2E5EA868B93F9FAFAACB0B6C9CBCCAAABADDCDDEADADADC5068907E848A26272AE9E9FD676D7598A2A9CDCFD7B1B3B5DBDDE1C5CCE3C2C3C5FEFEFEBEC0C194ACC7A2A3A65B75A60506066|racer02_black_small.gif            |474946383961F0009500F7000086878AECEDFED7D8E7D3D3FEE3E3FE909AA8DCDDFE545559C7C8D997999BB8C4CD96A2AF757679749ECE767A8289ABCAF9FAFA3A3C4038424C656569535962FAFBFDEDF0FBEBEBEDC8C8E6708FAEBABCC4DBDCDEF7F9FC77858F262629E2E3E4A9ADB25A636FCCCCFDD2D3D52E588ECACCCEB|racer02_black_large.gif            |2012-10-19 09:56:38.273|
            72|47494638396150003100F70000F1F2FEE3E3FCA3ACB6EBEBF3F5F6FEEDEEFE66676BF9FAFEE2E5EAB7BAC65656593B47539A9B9D989DA2D3D3D4787D835C6672D9E2E9DBDDE2868B93EFF0FDBBBCBEF9FAFAAAABAD3B3C42C8CBE6DBDCE9B6C8D5E9E9FDACBBC8D9DADD676C74CED0D37A858CFEFEFEC4D8E7748699206289E|racer02_blue_f_small.gif           |474946383961F0009500F700008EAFC785868991A5B2B5C7D1F2F3F4ECEDFE97989AD7D8E7D3D3FEE2E3FEDCDDFEC7C9D9757B8354555976777A76858FEBF2FAF9FAFA6991B2656669FAFBFD555A61EAEBED39414A3A3C40C7C7E6ACD3E8F7F9FCB9BCC5DBDCDEA8ADB2CCCCFDD2D3D5E2E3E477A9D150728E989CA2DDE1E3C|racer02_blue_f_large.gif           |2012-10-19 09:56:38.273|
			-- more --

Click to view Full table

Sample Output:

productphotoid|thumbnailphoto                                                                                                                                                                                                                                                 |thumbnailphotofilename             |largephoto                                                                                                                                                                                                                                                     |largephotofilename                 |modifieddate           |
--------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+-----------------------+
            76|47494638396150003100F700007689B3B1D5A475777BECEBF234353A85A376FAFCFE45474BF1F2FEE2E2FC6B919D4D5A6CF8FAFEF4F6FE65676BDAE7ECEDEDFE787C805B994CBEBDC3BACFB65A6674AAABB0F6F8FC56565A478C349A9DA1E3E4EBDCDDE1CDD1D9244356D1D1D3586F8EDBDDEA78CA6ABBBCBE68AB58F9FAFA3|racer02_green_f_small.gif          |474946383961F0009500F70000CACBF8D6E4EFA3D19EECEDFEF3F4F4D3D3FEE2E3FEDCDDFED7D7E7979AA6B4C7CEA5A7AAC7C8DA85868983B67633C90754555A2C930797999A719CCD96A5B0F9FAFA777A8287ABCEFAFBFDEEF0F876767977858A3B3C41656669575A604DAE2FC7C6ECEAEBED47CA233A4149BBBCC3F7F9FCA|racer02_green_f_large.gif          |2012-10-19 09:56:38.273|
            77|47494638396150003100F70000B8D3C4E2E3F397A5A945596B6B86B767AB56F5F8FC89BC7134353A45464AFAFCFEEBEBF3E1E2E3F1F2FEE3E3FB75767A797C816CC751F5F6FE65676BF8FAFD499434BEBDC26D9399EDEDFEA6AAB2ECF9E856565AE3E5E884D3713E47509A9DA15A9A4AADB2B6DEE3EADCDDE3CFD1D8D2D2D3D|racer02_green_small.gif            |474946383961F0009500F70000444549309407CACAF8D6E4EE34C90849CE24D8D8E8ECEDFEF2F3F3D3D3FEE2E3FEDCDDFE9699A7A4A6AAB9C4CD858689C6C8DA54555A719DCD96A5B098999A767A8350A731F9FAFAFAFBFD76767A88ABCDEEF1F4D4EDCF69A9563B3C41646569575A60EAEBED75868D6ADB49C6C6EC3C4148B|racer02_green_large.gif            |2012-10-19 09:56:38.273|
            91|47494638396150003100F7000000000000000800080800081008081008100808101008101810101810181810182118182118212118212921212921292921293129293131294229313129313931313939314A3139392152082B472E393942394242424A42425231426B395A6B4239394A39424A42424A424A4A4A4A4A524A4A4|julianax_r_02_f_green_small.gif    |474946383961F0009500F70000000205000810040C10101808081414101018101818101021101821181021181818181821182110211010291010261B1B182118102121182121212121292121182129212129182921182929212929292929212931292931213110213129214A18313121312129293131312D35294B0E293E202|julianax_r_02_f_green_large.gif    |2012-10-19 09:56:38.273|
            95|47494638396150003100F70000000000000008000808000810080810001000081010081018101018101818101821181821182121182129212129212929212931292931312939292942293131293139313139313939215A002D4E1C394A393139423939423942424A63424A6B4231294A39394A39424A42424A424A4A4A4A4A4|julianax_r_02_green_small.gif      |474946383961F0009500F70000000202000808000010000810020D0D081010000818081808081418101010101018101810101818180818181808211018181818211818101821181821082108212110182118212118102121212918213110294218264C10315218295A0C2E5D121821211821291829212118212121212121292|julianax_r_02_green_large.gif      |2012-10-19 09:56:38.273|
           105|47494638396150003100F700000200050D0512151012181818220E14211C252621262929293100002D292D3129313131313929313931313131393931392139103142210852001C5A08316B103939394231394239394242393939424239424242424A39424A42424A424A4A4A4A52424252424A524A4A5A4A4A6F10106D2E2E6|roadster_green_f_small.gif         |474946383961F0009500F7000000000000080008000000000800080808000C08080808081010020810081008100808101014100818081421080C2D040A1010101014141810101810181818181818212113162E1512182118182121252114271D2225272B2F252D1F490A20670144101144272B3131353F372B3931393939393|roadster_green_f_large.gif         |2012-10-19 09:56:38.273|
           106|47494638396150003100F70000020005080810100018120D1029040818151B211821231E262B1618292929312929292931312931313131313139392D31213910314221085200205A08316B103931393939394231394239393939424239424242424A39424A42424A424A4A4A4A632020573F41731C1C7B3C3C524A4A524A525|roadster_green_small.gif           |474946383961F0009500F7000000000000080008000000000800080808000C08080808081010020810081008100808101010100818081422080A3104081012121810101810181818182112161A1C1C211C1C2B191824241D2925292B272D3129311D51041C6300186B00296502451C2033312E35373045352D3F373D3C423C4|roadster_green_large.gif           |2012-10-19 09:56:38.273|
           123|47494638396150003100F7000010081018101821102921103118181821181821182121182921212129212929213131213929292929293131293129293939294A31313139313131313939313929314239393139393942393939394242394242394A4242464A42424A4E35577029314A634A31524A424A4A4A4A4E464E524A4E4|superlight_metalicgreen_f_small.gif|474946383961F0009500F70000150E111B1221221E262921292525312B273331292931293139392131312931313131393136293633333639393142393118314A312D4631424A3929423931394231393931423B3B3F4239424242394242424A3D4242394A42424A4A394A4A424A39473E29425C52424A5242524A4A4E524A4A3|superlight_metalicgreen_f_large.gif|2012-10-19 09:56:38.273|
           124|47494638396150003100F700001008101810181818182118182118212121212921292929292514312D2535292939312931332B3939313131313939313929314239393139393942393939394242394242394A4242424A6B2142424A4A424A4A4A4A4F474C524A52524A5A4A5A4A5D7B2652525263845252525A5A525A5A5A5A6|superlight_metalicgreen_small.gif  |474946383961F0009500F70000150E131C1821221D25292129291E3326292E3129293129312D2D3531312939293139293931313139313131313939462918314A21425A3929422E3C4A3931393939393F363C393F4C4239424A3942423F414444414A394A4A424A52424A524252414C3C394B504E4A4A4A524A525A39524A525|superlight_metalicgreen_large.gif  |2012-10-19 09:56:38.273|   

Click me to see the solution

162. From the following tables write a query in SQL to obtain mailing addresses for companies in cities that begin with PA, outside the United States (US). Return AddressLine1, AddressLine2, City, PostalCode, CountryRegionCode.

Sample table: Person.Address
|addressid|addressline1              |addressline2|city         |stateprovinceid|postalcode|spatiallocation                             |rowguid                             |modifieddate           |
|---------|--------------------------|------------|-------------|---------------|----------|--------------------------------------------|------------------------------------|-----------------------|
|1        |1970 Napa Ct.             |            |Bothell      |79             |98011     |E6100000010CAE8BFC28BCE4474067A89189898A5EC0|9aadcb0d-36cf-483f-84d8-585c2d4ec6e9|2007-12-04 00:00:00.000|
|2        |9833 Mt. Dias Blv.        |            |Bothell      |79             |98011     |E6100000010CD6FA851AE6D74740BC262A0A03905EC0|32a54b9e-e034-4bfb-b573-a71cde60d8c0|2008-11-30 00:00:00.000|
|3        |7484 Roundtree Drive      |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE14740DA930C7893915EC0|4c506923-6d1b-452c-a07c-baa6f5b142a4|2013-03-07 00:00:00.000|
|4        |9539 Glenside Dr          |            |Bothell      |79             |98011     |E6100000010C813A0D5F9FDE474011A5C28A7C955EC0|e5946c78-4bcc-477f-9fa1-cc09de16a880|2009-02-03 00:00:00.000|
|5        |1226 Shoe St.             |            |Bothell      |79             |98011     |E6100000010C61C64D8ABBD94740C460EA3FD8855EC0|fbaff937-4a97-4af0-81fd-b849900e9bb0|2008-12-19 00:00:00.000|
|6        |1399 Firestone Drive      |            |Bothell      |79             |98011     |E6100000010CE0B4E50458DA47402F12A5F80C975EC0|febf8191-9804-44c8-877a-33fde94f0075|2009-02-13 00:00:00.000|
|7        |5672 Hale Dr.             |            |Bothell      |79             |98011     |E6100000010C18E304C4ADE1474011A5C28A7C955EC0|0175a174-6c34-4d41-b3c1-4419cd6a0446|2009-12-11 00:00:00.000|
|8        |6387 Scenic Avenue        |            |Bothell      |79             |98011     |E6100000010C0029A5D93BDF4740E248962FD5975EC0|3715e813-4dca-49e0-8f1c-31857d21f269|2008-12-17 00:00:00.000|
|9        |8713 Yosemite Ct.         |            |Bothell      |79             |98011     |E6100000010C6A80AD742DDC4740851574F7198C5EC0|268af621-76d7-4c78-9441-144fd139821a|2012-05-30 00:00:00.000|
|10       |250 Race Court            |            |Bothell      |79             |98011     |E6100000010C219D64AE1FE4474040862564B7825EC0|0b6b739d-8eb6-4378-8d55-fe196af34c04|2008-12-02 00:00:00.000|
-- more --

Click to view Full table

Sample table: Person.StateProvince

Click to view Full table

Sample Output:

addressline1                     |addressline2         |city            |postalcode|countryregioncode|
---------------------------------+---------------------+----------------+----------+-----------------+
21105, rue de Varenne            |                     |Paris           |75013     |FR               |
22, rue du Départ                |                     |Pantin          |93500     |FR               |
36, avenue de la Gare            |                     |Paris           |75019     |FR               |
39, route de Marseille           |                     |Paris           |75016     |FR               |
98, rue Montcalm                 |                     |Paris           |75019     |FR               |
39, avenue des Laurentides       |                     |Paris La Defense|92081     |FR               |
3101, avenue de Malakoff         |                     |Paris           |75003     |FR               |
9005, rue des Bouchers           |                     |Paris           |75005     |FR               |
7551, avenue Foch                |                     |Paris           |75010     |FR               |
22, rue Lafayette                |                     |Pantin          |93500     |FR               |
699bis, rue des Peupliers        |                     |Paris           |75008     |FR               |
...

Click me to see the solution

163.From the following table, write a query in SQL to join the Product table with a set of specific product names using a JOIN clause. Return the columns ProductID, Name, and Color. The query should filter the Product table to include only those products with the names 'Blade', 'Crown Race', and 'AWC Logo Cap'.

Sample table: Production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productid|name        |color|
---------+------------+-----+
      316|Blade       |     |
      323|Crown Race  |     |
      712|AWC Logo Cap|Multi|

Click me to see the solution

164. From the following table write a query in SQL to find the SalesPersonID, salesyear, totalsales, salesquotayear, salesquota, and amt_above_or_below_quota columns. Sort the result set in ascending order on SalesPersonID, and SalesYear columns.

Sample table: Sales.SalesOrderHeader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: Sales.SalesPersonQuotaHistory
businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

salespersonid|salesyear|totalsales|salesquotayear|salesquota|amt_above_or_below_quota|
-------------+---------+----------+--------------+----------+------------------------+
          274|   2011.0|32567.9155|        2011.0|32567.9155|-93432.084              |
          274|   2012.0|516197.368|        2012.0|516197.368|45197.3680              |
          274|   2013.0|485880.642|        2013.0|485880.642|-35119.358              |
          274|   2014.0|201288.519|        2014.0|201288.519|14288.5196              |
          275|   2011.0|986298.090|        2011.0|986298.090|-438701.90              |
          275|   2012.0|3806298.30|        2012.0|3806298.30|-225701.69              |
          275|   2013.0|4490942.20|        2013.0|4490942.20|-345057.79              |
          275|   2014.0|1191828.47|        2014.0|1191828.47|322828.474              |
          276|   2011.0|1294819.74|        2011.0|1294819.74|-788180.25              |
          276|   2012.0|4328860.05|        2012.0|4328860.05|465860.053              |
          276|   2013.0|4637217.83|        2013.0|4637217.83|-78782.167              |
          276|   2014.0|1434121.43|        2014.0|1434121.43|310121.430              |
          277|   2011.0|1477158.28|        2011.0|1477158.28|-805841.71              |
          277|   2012.0|4865650.84|        2012.0|4865650.84|122650.842              |
...

Click me to see the solution

165. From the following tables write a query in SQL to return the cross product of BusinessEntityID and Department columns.

The following example returns the cross product of the two tables Employee and Department in the AdventureWorks2019 database. A list of all possible combinations of BusinessEntityID rows and all Department name rows are returned.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.Department
departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

businessentityid|department                |
----------------+--------------------------+
               1|Document Control          |
               1|Engineering               |
               1|Executive                 |
               1|Facilities and Maintenance|
               1|Finance                   |
               1|Human Resources           |
               1|Information Services      |
               1|Marketing                 |
               1|Production                |
               1|Production Control        |
               1|Purchasing                |
               1|Quality Assurance         |
               1|Research and Development  |
               1|Sales                     |
               1|Shipping and Receiving    |
...	

Click me to see the solution

166. From the following tables write a query in SQL to return the SalesOrderNumber, ProductKey, and EnglishProductName columns.

Sample table: Sales.SalesOrderDetail
salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: Production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

salesorderid|productid|name                            |
------------+---------+--------------------------------+
       43659|      776|Mountain-100 Black, 42          |
       43659|      777|Mountain-100 Black, 44          |
       43659|      778|Mountain-100 Black, 48          |
       43659|      771|Mountain-100 Silver, 38         |
       43659|      772|Mountain-100 Silver, 42         |
       43659|      773|Mountain-100 Silver, 44         |
       43659|      774|Mountain-100 Silver, 48         |
       43659|      714|Long-Sleeve Logo Jersey, M      |
       43659|      716|Long-Sleeve Logo Jersey, XL     |
       43659|      709|Mountain Bike Socks, M          |
       43659|      712|AWC Logo Cap                    |
       43659|      711|Sport-100 Helmet, Blue          |
       43660|      762|Road-650 Red, 44                |
       43660|      758|Road-450 Red, 52                |
       43661|      745|HL Mountain Frame - Black, 48   |
...	 

Click me to see the solution

167. From the following tables write a query in SQL to return all orders with IDs greater than 60000.

Sample table: Sales.SalesOrderDetail
salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: Production.Product
productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

salesorderid|productid|name                            |
------------+---------+--------------------------------+
       60001|      929|ML Mountain Tire                |
       60001|      921|Mountain Tire Tube              |
       60001|      711|Sport-100 Helmet, Blue          |
       60002|      929|ML Mountain Tire                |
       60003|      712|AWC Logo Cap                    |
       60003|      869|Women's Mountain Shorts, L      |
       60004|      870|Water Bottle - 30 oz.           |
       60005|      870|Water Bottle - 30 oz.           |
       60005|      712|AWC Logo Cap                    |
       60006|      921|Mountain Tire Tube              |
       60006|      873|Patch Kit/8 Patches             |
       60007|      878|Fender Set - Mountain           |
       60007|      713|Long-Sleeve Logo Jersey, S      |
       60008|      878|Fender Set - Mountain           |
...	   

Click me to see the solution

168. From the following tables write a query in SQL to retrieve the SalesOrderid. A NULL is returned if no orders exist for a particular Territoryid. Return territoryid, countryregioncode, and salesorderid. Results are sorted by SalesOrderid, so that NULLs appear at the top.

Sample table: sales.salesterritory
territoryid|name          |countryregioncode|group        |salesytd     |saleslastyear|costytd|costlastyear|rowguid                             |modifieddate           |
-----------+--------------+-----------------+-------------+-------------+-------------+-------+------------+------------------------------------+-----------------------+
          1|Northwest     |US               |North America| 7887186.7882| 3298694.4938|      0|           0|43689a10-e30b-497f-b0de-11de20267ff7|2008-04-30 00:00:00.000|
          2|Northeast     |US               |North America| 2402176.8476| 3607148.9371|      0|           0|00fb7309-96cc-49e2-8363-0a1ba72486f2|2008-04-30 00:00:00.000|
          3|Central       |US               |North America|  3072175.118| 3205014.0767|      0|           0|df6e7fd8-1a8d-468c-b103-ed8addb452c1|2008-04-30 00:00:00.000|
          4|Southwest     |US               |North America|10510853.8739| 5366575.7098|      0|           0|dc3e9ea0-7950-4431-9428-99dbcbc33865|2008-04-30 00:00:00.000|
          5|Southeast     |US               |North America| 2538667.2515| 3925071.4318|      0|           0|6dc4165a-5e4c-42d2-809d-4344e0ac75e7|2008-04-30 00:00:00.000|
          6|Canada        |CA               |North America| 6771829.1376|   5693988.86|      0|           0|06b4af8a-1639-476e-9266-110461d66b00|2008-04-30 00:00:00.000|
          7|France        |FR               |Europe       | 4772398.3078| 2396539.7601|      0|           0|bf806804-9b4c-4b07-9d19-706f2e689552|2008-04-30 00:00:00.000|
          8|Germany       |DE               |Europe       | 3805202.3478| 1307949.7917|      0|           0|6d2450db-8159-414f-a917-e73ee91c38a9|2008-04-30 00:00:00.000|
          9|Australia     |AU               |Pacific      | 5977814.9154| 2278548.9776|      0|           0|602e612e-dfe9-41d9-b894-27e489747885|2008-04-30 00:00:00.000|
         10|United Kingdom|GB               |Europe       | 5012905.3656| 1635823.3967|      0|           0|05fc7e1f-2dea-414e-9ecd-09d150516fb5|2008-04-30 00:00:00.000|

Click to view Full table

Sample table: sales.salesorderheader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

territoryid|countryregioncode|salesorderid|
-----------+-----------------+------------+
          5|US               |       43659|
          5|US               |       43660|
          6|CA               |       43661|
          6|CA               |       43662|
          4|US               |       43663|
          1|US               |       43664|
          1|US               |       43665|
          4|US               |       43666|
          3|US               |       43667|
          6|CA               |       43668|
          1|US               |       43669|
          3|US               |       43670|
...	

Click me to see the solution

169. From the following table write a query in SQL to return all rows from both joined tables but returns NULL for values that do not match from the other table. Return territoryid, countryregioncode, and salesorderid. Results are sorted by SalesOrderid.

Sample table: sales.salesterritory
territoryid|name          |countryregioncode|group        |salesytd     |saleslastyear|costytd|costlastyear|rowguid                             |modifieddate           |
-----------+--------------+-----------------+-------------+-------------+-------------+-------+------------+------------------------------------+-----------------------+
          1|Northwest     |US               |North America| 7887186.7882| 3298694.4938|      0|           0|43689a10-e30b-497f-b0de-11de20267ff7|2008-04-30 00:00:00.000|
          2|Northeast     |US               |North America| 2402176.8476| 3607148.9371|      0|           0|00fb7309-96cc-49e2-8363-0a1ba72486f2|2008-04-30 00:00:00.000|
          3|Central       |US               |North America|  3072175.118| 3205014.0767|      0|           0|df6e7fd8-1a8d-468c-b103-ed8addb452c1|2008-04-30 00:00:00.000|
          4|Southwest     |US               |North America|10510853.8739| 5366575.7098|      0|           0|dc3e9ea0-7950-4431-9428-99dbcbc33865|2008-04-30 00:00:00.000|
          5|Southeast     |US               |North America| 2538667.2515| 3925071.4318|      0|           0|6dc4165a-5e4c-42d2-809d-4344e0ac75e7|2008-04-30 00:00:00.000|
          6|Canada        |CA               |North America| 6771829.1376|   5693988.86|      0|           0|06b4af8a-1639-476e-9266-110461d66b00|2008-04-30 00:00:00.000|
          7|France        |FR               |Europe       | 4772398.3078| 2396539.7601|      0|           0|bf806804-9b4c-4b07-9d19-706f2e689552|2008-04-30 00:00:00.000|
          8|Germany       |DE               |Europe       | 3805202.3478| 1307949.7917|      0|           0|6d2450db-8159-414f-a917-e73ee91c38a9|2008-04-30 00:00:00.000|
          9|Australia     |AU               |Pacific      | 5977814.9154| 2278548.9776|      0|           0|602e612e-dfe9-41d9-b894-27e489747885|2008-04-30 00:00:00.000|
         10|United Kingdom|GB               |Europe       | 5012905.3656| 1635823.3967|      0|           0|05fc7e1f-2dea-414e-9ecd-09d150516fb5|2008-04-30 00:00:00.000|

Click to view Full table

Sample table: sales.salesorderheader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

territoryid|countryregioncode|salesorderid|
-----------+-----------------+------------+
          5|US               |       43659|
          5|US               |       43660|
          6|CA               |       43661|
          6|CA               |       43662|
          4|US               |       43663|
          1|US               |       43664|
          1|US               |       43665|
          4|US               |       43666|
          3|US               |       43667|
          6|CA               |       43668|
          1|US               |       43669|
          3|US               |       43670|
          1|US               |       43671|
		  
...

Click me to see the solution

170. From the following tables write a query in SQL to return a cross-product. Order the result set by SalesOrderid.

Sample table: sales.salesterritory
territoryid|name          |countryregioncode|group        |salesytd     |saleslastyear|costytd|costlastyear|rowguid                             |modifieddate           |
-----------+--------------+-----------------+-------------+-------------+-------------+-------+------------+------------------------------------+-----------------------+
          1|Northwest     |US               |North America| 7887186.7882| 3298694.4938|      0|           0|43689a10-e30b-497f-b0de-11de20267ff7|2008-04-30 00:00:00.000|
          2|Northeast     |US               |North America| 2402176.8476| 3607148.9371|      0|           0|00fb7309-96cc-49e2-8363-0a1ba72486f2|2008-04-30 00:00:00.000|
          3|Central       |US               |North America|  3072175.118| 3205014.0767|      0|           0|df6e7fd8-1a8d-468c-b103-ed8addb452c1|2008-04-30 00:00:00.000|
          4|Southwest     |US               |North America|10510853.8739| 5366575.7098|      0|           0|dc3e9ea0-7950-4431-9428-99dbcbc33865|2008-04-30 00:00:00.000|
          5|Southeast     |US               |North America| 2538667.2515| 3925071.4318|      0|           0|6dc4165a-5e4c-42d2-809d-4344e0ac75e7|2008-04-30 00:00:00.000|
          6|Canada        |CA               |North America| 6771829.1376|   5693988.86|      0|           0|06b4af8a-1639-476e-9266-110461d66b00|2008-04-30 00:00:00.000|
          7|France        |FR               |Europe       | 4772398.3078| 2396539.7601|      0|           0|bf806804-9b4c-4b07-9d19-706f2e689552|2008-04-30 00:00:00.000|
          8|Germany       |DE               |Europe       | 3805202.3478| 1307949.7917|      0|           0|6d2450db-8159-414f-a917-e73ee91c38a9|2008-04-30 00:00:00.000|
          9|Australia     |AU               |Pacific      | 5977814.9154| 2278548.9776|      0|           0|602e612e-dfe9-41d9-b894-27e489747885|2008-04-30 00:00:00.000|
         10|United Kingdom|GB               |Europe       | 5012905.3656| 1635823.3967|      0|           0|05fc7e1f-2dea-414e-9ecd-09d150516fb5|2008-04-30 00:00:00.000|

Click to view Full table

Sample table: sales.salesorderheader
salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

territoryid|salesorderid|
-----------+------------+
          1|       43659|
          2|       43659|
          3|       43659|
          4|       43659|
          5|       43659|
          6|       43659|
          7|       43659|
          8|       43659|
          9|       43659|
         10|       43659|
          1|       43660|
          2|       43660|
...		

Click me to see the solution

171. From the following table, write a query in SQL to return all employees with a BirthDate after September 1, 1988, and a JobTitle of 'Production Technician - WC40'. Return the columns BusinessEntityID, JobTitle, and BirthDate, and sort the result set in ascending order by BirthDate.

Sample table: HumanResources.Employee
businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

businessentityid|jobtitle                    |birthdate |
----------------+----------------------------+----------+
             198|Production Technician - WC40|1988-11-26|
             193|Production Technician - WC40|1988-12-05|
             194|Production Technician - WC40|1989-06-25|
             202|Production Technician - WC40|1989-11-10|
             131|Production Technician - WC40|1990-10-07|
             133|Production Technician - WC40|1991-01-04|

Click me to see the solution

172. From the following table write a query in SQL to return the rows with different firstname values from Adam. Return businessentityid, persontype, firstname, middlename,and lastname. Sort the result set in ascending order on firstname.

Sample table: Person.Person

businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|persontype|firstname               |middlename      |lastname              |
----------------+----------+------------------------+----------------+----------------------+
            2321|GC        |A.                      |Scott           |Wright                |
            1305|SC        |A.                      |Francesca       |Leonetti              |
             222|EM        |A. Scott                |                |Wright                |
            5495|IN        |Aaron                   |J               |Hughes                |
            5504|IN        |Aaron                   |                |Bryant                |
            5494|IN        |Aaron                   |W               |Patterson             |
           16664|IN        |Aaron                   |                |Hill                  |
            5508|IN        |Aaron                   |                |Alexander             |
            5509|IN        |Aaron                   |                |Russell               |
             727|SC        |Aaron                   |                |Con                   |
            5512|IN        |Aaron                   |                |Griffin               |
            5514|IN        |Aaron                   |C               |Diaz                  |
            5515|IN        |Aaron                   |A               |Hayes                 |
            5516|IN        |Aaron                   |A               |Zhang                 |
...	

Click me to see the solution

173. From the following table write a query in SQL to find the rows where firstname doesn't differ from Adam's firstname. Return businessentityid, persontype, firstname, middlename,and lastname. Sort the result set in ascending order on firstname.

Sample table: Person.Person

businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|persontype|firstname|middlename|lastname  |
----------------+----------+---------+----------+----------+
             413|SC        |Adam     |          |Barr      |
            1679|VC        |Adam     |J.        |Reynolds  |
            5231|IN        |Adam     |          |Ross      |
            5234|IN        |Adam     |          |Henderson |
            5236|IN        |Adam     |M         |Jenkins   |
            5238|IN        |Adam     |          |Perry     |
            5239|IN        |Adam     |          |Powell    |
            5240|IN        |Adam     |          |Long      |
            5242|IN        |Adam     |M         |Patterson |
            5243|IN        |Adam     |          |Hughes    |
            5244|IN        |Adam     |L         |Flores    |
            5245|IN        |Adam     |G         |Washington|
            5246|IN        |Adam     |          |Butler    |
            5248|IN        |Adam     |          |Simmons   |
...	

Click me to see the solution

174. From the following table write a query in SQL to find the rows where middlename differs from NULL. Return businessentityid, persontype, firstname, middlename,and lastname. Sort the result set in ascending order on firstname.

Sample table: Person.Person


businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|persontype|firstname      |middlename      |lastname         |
----------------+----------+---------------+----------------+-----------------+
            2321|GC        |A.             |Scott           |Wright           |
            1305|SC        |A.             |Francesca       |Leonetti         |
           15883|IN        |Aaron          |L               |Perez            |
           16923|IN        |Aaron          |M               |Young            |
           16167|IN        |Aaron          |C               |Campbell         |
            5522|IN        |Aaron          |C               |Yang             |
            5523|IN        |Aaron          |M               |Kumar            |
           16591|IN        |Aaron          |C               |Scott            |
            5529|IN        |Aaron          |J               |Sharma           |
            5495|IN        |Aaron          |J               |Hughes           |
            5497|IN        |Aaron          |L               |Washington       |
            5483|IN        |Aaron          |N               |Ross             |
           16420|IN        |Aaron          |J               |Carter           |
...	

Click me to see the solution

175. From the following table write a query in SQL to identify the rows with a middlename that is not NULL. Return businessentityid, persontype, firstname, middlename,and lastname. Sort the result set in ascending order on firstname.

Sample table: Person.Person

businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample Output:

businessentityid|persontype|firstname               |middlename|lastname              |
----------------+----------+------------------------+----------+----------------------+
             222|EM        |A. Scott                |          |Wright                |
           15964|IN        |Aaron                   |          |Roberts               |
           15693|IN        |Aaron                   |          |Edwards               |
            2272|GC        |Aaron                   |          |Con                   |
           17060|IN        |Aaron                   |          |Hernandez             |
             727|SC        |Aaron                   |          |Con                   |
           16664|IN        |Aaron                   |          |Hill                  |
            2306|GC        |Aaron                   |          |Nicholls              |
            5487|IN        |Aaron                   |          |Henderson             |
            5488|IN        |Aaron                   |          |Coleman               |
            5489|IN        |Aaron                   |          |Jenkins               |
            5491|IN        |Aaron                   |          |Perry                 |
            5492|IN        |Aaron                   |          |Powell                |
...	

Click me to see the solution

176. From the following table write a query in SQL to fetch all products with a weight of less than 10 pounds or unknown color. Return the name, weight, and color for the product. Sort the result set in ascending order on name.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                            |weight|color |
--------------------------------+------+------+
Adjustable Race                 |      |      |
All-Purpose Bike Stand          |      |      |
BB Ball Bearing                 |      |      |
Bearing Ball                    |      |      |
Bike Wash - Dissolver           |      |      |
Blade                           |      |      |
Cable Lock                      |      |      |
Chain Stays                     |      |      |
Cone-Shaped Race                |      |      |
Crown Race                      |      |      |
Cup-Shaped Race                 |      |      |
Decal 1                         |      |      |
Decal 2                         |      |      |
...

Click me to see the solution

177. From the following table write a query in SQL to list the salesperson whose salesytd begins with 1. Convert SalesYTD and current date in text format.

Sample table: Sales.SalesPerson

businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample Output:

businessentityid|salesytd    |moneydisplaystyle1|currentdate                  |datedisplaystyle3               |
----------------+------------+------------------+-----------------------------+--------------------------------+
             278|1453719.4653|1453719.4653      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             280|1352577.1325|1352577.1325      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             283|1573012.9383|1573012.9383      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             284|1576562.1966|1576562.1966      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             285| 172524.4512|172524.4512       |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             286|1421810.9242|1421810.9242      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|
             288|1827066.7118|1827066.7118      |2022-12-01 14:35:09.855 +0530|2022-12-01 14:35:09.855204+05:30|

Click me to see the solution

178. From the following table write a query in SQL to return the count of employees by Name and Title, Name, and company total. Filter the results by department ID 12 or 14. For each row, identify its aggregation level in the Title column.

Sample table: HumanResources.Employee

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.EmployeeDepartmentHistory

businessentityid|departmentid|shiftid|startdate |enddate   |modifieddate           |
----------------+------------+-------+----------+----------+-----------------------+
               1|          16|      1|2009-01-14|          |2009-01-13 00:00:00.000|
               2|           1|      1|2008-01-31|          |2008-01-30 00:00:00.000|
               3|           1|      1|2007-11-11|          |2007-11-10 00:00:00.000|
               4|           1|      1|2007-12-05|2010-05-30|2010-05-28 00:00:00.000|
               4|           2|      1|2010-05-31|          |2010-05-30 00:00:00.000|
               5|           1|      1|2008-01-06|          |2008-01-05 00:00:00.000|
               6|           1|      1|2008-01-24|          |2008-01-23 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Department

departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

name                      |Job Title                          |Employee Count|
--------------------------+-----------------------------------+--------------+
                          |Company Total:                     |            12|
Document Control          |Control Specialist                 |             2|
Facilities and Maintenance|Janitor                            |             4|
Facilities and Maintenance|Facilities Manager                 |             1|
Document Control          |Document Control Assistant         |             2|
Document Control          |Document Control Manager           |             1|
Facilities and Maintenance|Maintenance Supervisor             |             1|
Facilities and Maintenance|Facilities Administrative Assistant|             1|
Facilities and Maintenance|Total :Facilities and Maintenance  |             7|
Document Control          |Total :Document Control            |             5|

Click me to see the solution

179. From the following tables write a query in SQL to return only rows with a count of employees by department. Filter the results by department ID 12 or 14. Return name, jobtitle, grouping level and employee count.

Sample table: HumanResources.Employee

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.EmployeeDepartmentHistory

businessentityid|departmentid|shiftid|startdate |enddate   |modifieddate           |
----------------+------------+-------+----------+----------+-----------------------+
               1|          16|      1|2009-01-14|          |2009-01-13 00:00:00.000|
               2|           1|      1|2008-01-31|          |2008-01-30 00:00:00.000|
               3|           1|      1|2007-11-11|          |2007-11-10 00:00:00.000|
               4|           1|      1|2007-12-05|2010-05-30|2010-05-28 00:00:00.000|
               4|           2|      1|2010-05-31|          |2010-05-30 00:00:00.000|
               5|           1|      1|2008-01-06|          |2008-01-05 00:00:00.000|
               6|           1|      1|2008-01-24|          |2008-01-23 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Department

departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

name                      |jobtitle|Grouping Level|Employee Count|
--------------------------+--------+--------------+--------------+
Facilities and Maintenance|        |             1|             7|
Document Control          |        |             1|             5|

Click me to see the solution

180. From the following tables write a query in SQL to return only the rows that have a count of employees by title. Filter the results by department ID 12 or 14. Return name, jobtitle, grouping level and employee count.

Sample table: HumanResources.Employee

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: HumanResources.EmployeeDepartmentHistory

businessentityid|departmentid|shiftid|startdate |enddate   |modifieddate           |
----------------+------------+-------+----------+----------+-----------------------+
               1|          16|      1|2009-01-14|          |2009-01-13 00:00:00.000|
               2|           1|      1|2008-01-31|          |2008-01-30 00:00:00.000|
               3|           1|      1|2007-11-11|          |2007-11-10 00:00:00.000|
               4|           1|      1|2007-12-05|2010-05-30|2010-05-28 00:00:00.000|
               4|           2|      1|2010-05-31|          |2010-05-30 00:00:00.000|
               5|           1|      1|2008-01-06|          |2008-01-05 00:00:00.000|
               6|           1|      1|2008-01-24|          |2008-01-23 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Department

departmentid|name                      |groupname                           |modifieddate           |
------------+--------------------------+------------------------------------+-----------------------+
           1|Engineering               |Research and Development            |2008-04-30 00:00:00.000|
           2|Tool Design               |Research and Development            |2008-04-30 00:00:00.000|
           3|Sales                     |Sales and Marketing                 |2008-04-30 00:00:00.000|
           4|Marketing                 |Sales and Marketing                 |2008-04-30 00:00:00.000|
           5|Purchasing                |Inventory Management                |2008-04-30 00:00:00.000|
           6|Research and Development  |Research and Development            |2008-04-30 00:00:00.000|
           7|Production                |Manufacturing                       |2008-04-30 00:00:00.000|
           8|Production Control        |Manufacturing                       |2008-04-30 00:00:00.000|
           9|Human Resources           |Executive General and Administration|2008-04-30 00:00:00.000|
          10|Finance                   |Executive General and Administration|2008-04-30 00:00:00.000|
          11|Information Services      |Executive General and Administration|2008-04-30 00:00:00.000|
          12|Document Control          |Quality Assurance                   |2008-04-30 00:00:00.000|
          13|Quality Assurance         |Quality Assurance                   |2008-04-30 00:00:00.000|
          14|Facilities and Maintenance|Executive General and Administration|2008-04-30 00:00:00.000|
          15|Shipping and Receiving    |Inventory Management                |2008-04-30 00:00:00.000|
          16|Executive                 |Executive General and Administration|2008-04-30 00:00:00.000|

Click to view Full table

Sample Output:

name                      |jobtitle                           |Grouping Level|Employee Count|
--------------------------+-----------------------------------+--------------+--------------+
Document Control          |Control Specialist                 |             0|             2|
Facilities and Maintenance|Janitor                            |             0|             4|
Facilities and Maintenance|Facilities Manager                 |             0|             1|
Document Control          |Document Control Assistant         |             0|             2|
Document Control          |Document Control Manager           |             0|             1|
Facilities and Maintenance|Maintenance Supervisor             |             0|             1|
Facilities and Maintenance|Facilities Administrative Assistant|             0|             1|

Click me to see the solution

181. From the following table write a query in SQL to return the difference in sales quotas for a specific employee over previous calendar quarters. Sort the results by salesperson with businessentity id 277 and quotadate year 2012 or 2013.

Sample table: sales.salespersonquotahistory

businessentityid|quotadate              |salesquota|rowguid                             |modifieddate           |
----------------+-----------------------+----------+------------------------------------+-----------------------+
             274|2011-05-31 00:00:00.000|     28000|99109bbf-8693-4587-bc23-6036ec89e1be|2011-04-16 00:00:00.000|
             274|2011-08-31 00:00:00.000|      7000|dfd01444-8900-461c-8d6f-04598dae01d4|2011-07-17 00:00:00.000|
             274|2011-12-01 00:00:00.000|     91000|0a69f453-9689-4ccf-a08c-c644670f5668|2011-10-17 00:00:00.000|
             274|2012-02-29 00:00:00.000|    140000|da8d1458-5fb9-4c3e-9ead-8f5ce1393047|2012-01-15 00:00:00.000|
             274|2012-05-30 00:00:00.000|     70000|760cef84-b980-417b-a667-7358c38857f0|2012-04-15 00:00:00.000|
             274|2012-08-30 00:00:00.000|    154000|fb29e024-f26a-49aa-a7cc-c99ae7ba4853|2012-07-16 00:00:00.000|
             274|2012-11-30 00:00:00.000|    107000|13947d2c-a254-47c9-8817-cbd186ffa526|2012-10-16 00:00:00.000|
             274|2013-02-28 00:00:00.000|     58000|bc1a222f-47a0-48d1-9c56-ac873269dc98|2013-01-14 00:00:00.000|
             274|2013-05-30 00:00:00.000|    263000|8b4e3cbf-f0ef-49c5-9a8c-87679055057e|2013-04-15 00:00:00.000|
             274|2013-08-30 00:00:00.000|    116000|e9de95e3-b119-4441-bd1d-b27fc4516022|2013-07-16 00:00:00.000|
             274|2013-11-30 00:00:00.000|     84000|7cea47b5-8391-4414-a866-ff6ec6628cd3|2013-10-16 00:00:00.000|
             274|2014-03-01 00:00:00.000|    187000|0cfb6474-20aa-46d3-a5c0-29dba2eda025|2014-01-15 00:00:00.000|
-- more --

Click to view Full table

Sample Output:

year                   |quarter|salesquota|prevquota|diff   |
-----------------------+-------+----------+---------+-------+
2012-02-29 00:00:00.000|    1.0|    952000|         |       |
2012-05-30 00:00:00.000|    2.0|   1600000|   952000| 648000|
2012-08-30 00:00:00.000|    3.0|   1352000|  1600000|-248000|
2012-11-30 00:00:00.000|    4.0|    839000|  1352000|-513000|
2013-02-28 00:00:00.000|    1.0|   1369000|   839000| 530000|
2013-05-30 00:00:00.000|    2.0|   1171000|  1369000|-198000|
2013-08-30 00:00:00.000|    3.0|    971000|  1171000|-200000|
2013-11-30 00:00:00.000|    4.0|    714000|   971000|-257000|

Click me to see the solution

182. From the following table write a query in SQL to return a truncated date with 4 months added to the orderdate.

Sample table: sales.salesorderheader

salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

year                   |quarter|salesquota|prevquota|diff   |
-----------------------+-------+----------+---------+-------+
2012-02-29 00:00:00.000|    1.0|    952000|         |       |
2012-05-30 00:00:00.000|    2.0|   1600000|   952000| 648000|
2012-08-30 00:00:00.000|    3.0|   1352000|  1600000|-248000|
2012-11-30 00:00:00.000|    4.0|    839000|  1352000|-513000|
2013-02-28 00:00:00.000|    1.0|   1369000|   839000| 530000|
2013-05-30 00:00:00.000|    2.0|   1171000|  1369000|-198000|
2013-08-30 00:00:00.000|    3.0|    971000|  1171000|-200000|
2013-11-30 00:00:00.000|    4.0|    714000|   971000|-257000|

Click me to see the solution

183. From the following table write a query in SQL to return the orders that have sales on or after December 2011. Return salesorderid, MonthOrderOccurred, salespersonid, customerid, subtotal, Running Total, and actual order date.

Sample table: sales.salesorderheader

salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|monthorderoccurred     |salespersonid|customerid|subtotal   |runningtotal|actualorderdate        |
------------+-----------------------+-------------+----------+-----------+------------+-----------------------+
       45579|2012-01-01 00:00:00.000|          279|     29484|   4079.988|    4079.988|2012-01-29 00:00:00.000|
       46389|2012-04-01 00:00:00.000|          279|     29484|  1104.9968|   5184.9848|2012-04-30 00:00:00.000|
       47454|2012-07-01 00:00:00.000|          279|     29484| 27429.5294|  32614.5142|2012-07-31 00:00:00.000|
       48395|2012-10-01 00:00:00.000|          279|     29484| 32562.6538|  65177.1680|2012-10-30 00:00:00.000|
       49495|2013-01-01 00:00:00.000|          279|     29484| 24232.7654|  89409.9334|2013-01-28 00:00:00.000|
       50756|2013-04-01 00:00:00.000|          279|     29484| 37643.0609| 127052.9943|2013-04-30 00:00:00.000|
       53459|2013-07-01 00:00:00.000|          276|     29485|  29133.471|   29133.471|2013-07-31 00:00:00.000|
       58907|2013-10-01 00:00:00.000|          276|     29485| 28413.4274|  57546.8984|2013-10-30 00:00:00.000|
       65157|2014-01-01 00:00:00.000|          276|     29485|  22021.782|  79568.6804|2014-01-29 00:00:00.000|
       71782|2014-05-01 00:00:00.000|          276|     29485|  33319.986| 112888.6664|2014-05-01 00:00:00.000|
       45550|2012-01-01 00:00:00.000|          277|     29486| 54979.9007|  54979.9007|2012-01-29 00:00:00.000|
...	

Click me to see the solution

184. From the following table write a query in SQL to repeat the 0 character four times before productnumber. Return name, productnumber and newly created productnumber.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                            |productnumber|fullproductnumber|
--------------------------------+-------------+-----------------+
Adjustable Race                 |AR-5381      |0000AR-5381      |
All-Purpose Bike Stand          |ST-1401      |0000ST-1401      |
AWC Logo Cap                    |CA-1098      |0000CA-1098      |
BB Ball Bearing                 |BE-2349      |0000BE-2349      |
Bearing Ball                    |BA-8327      |0000BA-8327      |
Bike Wash - Dissolver           |CL-9009      |0000CL-9009      |
Blade                           |BL-2036      |0000BL-2036      |
Cable Lock                      |LO-C100      |0000LO-C100      |
Chain                           |CH-0234      |0000CH-0234      |
Chain Stays                     |CS-2812      |0000CS-2812      |
Chainring                       |CR-7833      |0000CR-7833      |
...

Click me to see the solution

185. From the following table write a query in SQL to find all special offers. When the maximum quantity for a special offer is NULL, return MaxQty as zero.

Sample table: Sales.SpecialOffer

specialofferid|description                       |discountpct|type                |category   |startdate              |enddate                |minqty|maxqty|rowguid                             |modifieddate           |
--------------+----------------------------------+-----------+--------------------+-----------+-----------------------+-----------------------+------+------+------------------------------------+-----------------------+
             1|No Discount                       |          0|No Discount         |No Discount|2011-05-01 00:00:00.000|2014-11-30 00:00:00.000|     0|      |0290c4f5-191f-4337-ab6b-0a2dde03cbf9|2011-04-01 00:00:00.000|
             2|Volume Discount 11 to 14          |       0.02|Volume Discount     |Reseller   |2011-05-31 00:00:00.000|2014-05-30 00:00:00.000|    11|    14|d7542ee7-15db-4541-985c-5cc27aef26d6|2011-05-01 00:00:00.000|
             3|Volume Discount 15 to 24          |       0.05|Volume Discount     |Reseller   |2011-05-31 00:00:00.000|2014-05-30 00:00:00.000|    15|    24|4bdbcc01-8cf7-40a9-b643-40ec5b717491|2011-05-01 00:00:00.000|
             4|Volume Discount 25 to 40          |        0.1|Volume Discount     |Reseller   |2011-05-31 00:00:00.000|2014-05-30 00:00:00.000|    25|    40|504b5e85-8f3f-4ebc-9e1d-c1bc5dea9aa8|2011-05-01 00:00:00.000|
             5|Volume Discount 41 to 60          |       0.15|Volume Discount     |Reseller   |2011-05-31 00:00:00.000|2014-05-30 00:00:00.000|    41|    60|677e1d9d-944f-4e81-90e8-47eb0a82d48c|2011-05-01 00:00:00.000|
             6|Volume Discount over 60           |        0.2|Volume Discount     |Reseller   |2011-05-31 00:00:00.000|2014-05-30 00:00:00.000|    61|      |8157f569-4e8d-46b6-9347-5d0f726a9439|2011-05-01 00:00:00.000|
             7|Mountain-100 Clearance Sale       |       0.35|Discontinued Product|Reseller   |2012-04-13 00:00:00.000|2012-05-29 00:00:00.000|     0|      |7df15bf5-6c05-47e7-80a4-22bd1ce59a72|2012-03-14 00:00:00.000|
			 -- more --

Click to view Full table

Sample Output:

description                       |discountpct|minqty|Max Quantity|
----------------------------------+-----------+------+------------+
No Discount                       |          0|     0|        0.00|
Volume Discount 11 to 14          |       0.02|    11|          14|
Volume Discount 15 to 24          |       0.05|    15|          24|
Volume Discount 25 to 40          |        0.1|    25|          40|
Volume Discount 41 to 60          |       0.15|    41|          60|
Volume Discount over 60           |        0.2|    61|        0.00|
Mountain-100 Clearance Sale       |       0.35|     0|        0.00|
Sport Helmet Discount-2002        |        0.1|     0|        0.00|
Road-650 Overstock                |        0.3|     0|        0.00|
Mountain Tire Sale                |        0.5|     0|        0.00|
Sport Helmet Discount-2003        |       0.15|     0|        0.00|
LL Road Frame Sale                |       0.35|     0|        0.00|
Touring-3000 Promotion            |       0.15|     0|        0.00|
Touring-1000 Promotion            |        0.2|     0|        0.00|
Half-Price Pedal Sale             |        0.5|     0|        0.00|
Mountain-500 Silver Clearance Sale|        0.4|     0|        0.00|

Click me to see the solution

186. From the following table write a query in SQL to find all products that have NULL in the weight column. Return name and weight.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                           |weight|
-------------------------------+------+
Adjustable Race                |      |
Bearing Ball                   |      |
BB Ball Bearing                |      |
Headset Ball Bearings          |      |
Blade                          |      |
LL Crankarm                    |      |
ML Crankarm                    |      |
HL Crankarm                    |      |
Chainring Bolts                |      |
Chainring Nut                  |      |
Chainring                      |      |
Crown Race                     |      |
Chain Stays                    |      |
Decal 1                        |      |
Decal 2                        |      |
...

Click me to see the solution

187. From the following table write a query in SQL to find the data from the first column that has a non-null value. Return name, color, productnumber, and firstnotnull column.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                            |color       |productnumber|firstnotnull|
--------------------------------+------------+-------------+------------+
Adjustable Race                 |            |AR-5381      |AR-5381     |
Bearing Ball                    |            |BA-8327      |BA-8327     |
BB Ball Bearing                 |            |BE-2349      |BE-2349     |
Headset Ball Bearings           |            |BE-2908      |BE-2908     |
Blade                           |            |BL-2036      |BL-2036     |
LL Crankarm                     |Black       |CA-5965      |Black       |
ML Crankarm                     |Black       |CA-6738      |Black       |
HL Crankarm                     |Black       |CA-7457      |Black       |
Chainring Bolts                 |Silver      |CB-2903      |Silver      |
Chainring Nut                   |Silver      |CN-6137      |Silver      |
Chainring                       |Black       |CR-7833      |Black       |
...

Click me to see the solution

188. From the following tables write a query in SQL to return rows only when both the productid and startdate values in the two tables matches.

Sample table: Production.workorder

workorderid|productid|orderqty|scrappedqty|startdate              |enddate                |duedate                |scrapreasonid|modifieddate           |
-----------+---------+--------+-----------+-----------------------+-----------------------+-----------------------+-------------+-----------------------+
          1|      722|       8|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          2|      725|      15|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          3|      726|       9|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          4|      729|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          5|      730|      14|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          6|      732|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          7|      733|       4|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          8|      738|      19|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          9|      741|       2|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         10|      742|       3|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         11|      743|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         12|      745|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
		 -- more --

Click to view Full table

Sample table: Production.workorderrouting

workorderid|productid|operationsequence|locationid|scheduledstartdate     |scheduledenddate       |actualstartdate        |actualenddate          |actualresourcehrs|plannedcost|actualcost|modifieddate           |
-----------+---------+-----------------+----------+-----------------------+-----------------------+-----------------------+-----------------------+-----------------+-----------+----------+-----------------------+
         13|      747|                1|        10|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.1000|      92.25|     92.25|2011-06-19 00:00:00.000|
         13|      747|                2|        20|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           3.5000|       87.5|      87.5|2011-06-19 00:00:00.000|
         13|      747|                3|        30|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           1.0000|       14.5|      14.5|2011-06-19 00:00:00.000|
         13|      747|                4|        40|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           2.0000|       31.5|      31.5|2011-06-19 00:00:00.000|
         13|      747|                6|        50|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           3.0000|      36.75|     36.75|2011-06-19 00:00:00.000|
         13|      747|                7|        60|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.0000|         49|        49|2011-06-19 00:00:00.000|
         14|      748|                1|        10|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.1000|      92.25|     92.25|2011-06-19 00:00:00.000|
		 -- more --

Click to view Full table

Sample Output:

name                            |color       |productnumber|firstnotnull|
--------------------------------+------------+-------------+------------+
Adjustable Race                 |            |AR-5381      |AR-5381     |
Bearing Ball                    |            |BA-8327      |BA-8327     |
BB Ball Bearing                 |            |BE-2349      |BE-2349     |
Headset Ball Bearings           |            |BE-2908      |BE-2908     |
Blade                           |            |BL-2036      |BL-2036     |
LL Crankarm                     |Black       |CA-5965      |Black       |
ML Crankarm                     |Black       |CA-6738      |Black       |
HL Crankarm                     |Black       |CA-7457      |Black       |
Chainring Bolts                 |Silver      |CB-2903      |Silver      |
Chainring Nut                   |Silver      |CN-6137      |Silver      |
Chainring                       |Black       |CR-7833      |Black       |
...

Click me to see the solution

189. From the following tables write a query in SQL to return rows except both the productid and startdate values in the two tables matches.

Sample table: Production.workorder

workorderid|productid|orderqty|scrappedqty|startdate              |enddate                |duedate                |scrapreasonid|modifieddate           |
-----------+---------+--------+-----------+-----------------------+-----------------------+-----------------------+-------------+-----------------------+
          1|      722|       8|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          2|      725|      15|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          3|      726|       9|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          4|      729|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          5|      730|      14|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          6|      732|      16|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          7|      733|       4|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          8|      738|      19|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
          9|      741|       2|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         10|      742|       3|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         11|      743|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
         12|      745|       1|          0|2011-06-03 00:00:00.000|2011-06-13 00:00:00.000|2011-06-14 00:00:00.000|             |2011-06-13 00:00:00.000|
		 -- more --

Click to view Full table

Sample table: Production.workorderrouting

workorderid|productid|operationsequence|locationid|scheduledstartdate     |scheduledenddate       |actualstartdate        |actualenddate          |actualresourcehrs|plannedcost|actualcost|modifieddate           |
-----------+---------+-----------------+----------+-----------------------+-----------------------+-----------------------+-----------------------+-----------------+-----------+----------+-----------------------+
         13|      747|                1|        10|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.1000|      92.25|     92.25|2011-06-19 00:00:00.000|
         13|      747|                2|        20|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           3.5000|       87.5|      87.5|2011-06-19 00:00:00.000|
         13|      747|                3|        30|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           1.0000|       14.5|      14.5|2011-06-19 00:00:00.000|
         13|      747|                4|        40|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           2.0000|       31.5|      31.5|2011-06-19 00:00:00.000|
         13|      747|                6|        50|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           3.0000|      36.75|     36.75|2011-06-19 00:00:00.000|
         13|      747|                7|        60|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.0000|         49|        49|2011-06-19 00:00:00.000|
         14|      748|                1|        10|2011-06-03 00:00:00.000|2011-06-14 00:00:00.000|2011-06-03 00:00:00.000|2011-06-19 00:00:00.000|           4.1000|      92.25|     92.25|2011-06-19 00:00:00.000|
		 -- more --

Click to view Full table

Sample Output:

productid|startdate              |
---------+-----------------------+
        3|2011-06-03 00:00:00.000|
      316|2011-06-03 00:00:00.000|
      324|2011-06-03 00:00:00.000|
      327|2011-06-03 00:00:00.000|
      328|2011-06-03 00:00:00.000|
      329|2011-06-03 00:00:00.000|
      331|2011-06-03 00:00:00.000|
      350|2011-06-03 00:00:00.000|
      398|2011-06-03 00:00:00.000|
      399|2011-06-03 00:00:00.000|
      400|2011-06-03 00:00:00.000|
      401|2011-06-03 00:00:00.000|
      529|2011-06-03 00:00:00.000|
...	  

Click me to see the solution

190. From the following table write a query in SQL to find all creditcardapprovalcodes starting with 1 and the third digit is 6. Sort the result set in ascending order on orderdate.

Sample table: sales.salesorderheader

salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

salesorderid|orderdate              |creditcardapprovalcode|
------------+-----------------------+----------------------+
       43675|2011-05-31 00:00:00.000|126121Vi61402         |
       43679|2011-05-31 00:00:00.000|126365Vi28482         |
       43680|2011-05-31 00:00:00.000|126370Vi34642         |
       43681|2011-05-31 00:00:00.000|16608Vi27707          |
       43875|2011-07-01 00:00:00.000|116188Vi1051          |
       43880|2011-07-01 00:00:00.000|126355Vi95120         |
       43887|2011-07-01 00:00:00.000|106673Vi48861         |
       43889|2011-07-01 00:00:00.000|126756Vi87636         |
       43893|2011-07-01 00:00:00.000|116815Vi96000         |
       43916|2011-07-01 00:00:00.000|18665Vi32553          |
...	 

Click me to see the solution

191. From the following table write a query in SQL to concatenate character and date data types for the order ID 50001.

Sample table: sales.SalesOrderHeader

salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

concat                          |
--------------------------------+
The order is due on 2013-03-22 0|

Click me to see the solution

192. From the following table write a query in SQL to form one long string to display the last name and the first initial of the vice presidents. Sort the result set in ascending order on lastname.

Sample table: HumanResources.Employee

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample Output:

name        |jobtitle                     |
------------+-----------------------------+
Duffy, T.   |Vice President of Engineering|
Hamilton, J.|Vice President of Production |
Welcker, B. |Vice President of Sales      |

Click me to see the solution

193. From the following table write a query in SQL to return only the rows for Product that have a product line of R and that have days to manufacture that is less than 4. Sort the result set in ascending order on name.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

name                        |productnumber|price  |
----------------------------+-------------+-------+
Headlights - Dual-Beam      |LT-H902      |  34.99|
Headlights - Weatherproof   |LT-H903      |  44.99|
HL Road Frame - Black, 44   |FR-R92B-44   | 1431.5|
HL Road Frame - Black, 48   |FR-R92B-48   | 1431.5|
HL Road Frame - Black, 52   |FR-R92B-52   | 1431.5|
HL Road Frame - Black, 58   |FR-R92B-58   | 1431.5|
HL Road Frame - Black, 62   |FR-R92B-62   | 1431.5|
HL Road Frame - Red, 44     |FR-R92R-44   | 1431.5|
HL Road Frame - Red, 48     |FR-R92R-48   | 1431.5|
HL Road Frame - Red, 52     |FR-R92R-52   | 1431.5|
HL Road Frame - Red, 56     |FR-R92R-56   | 1431.5|
HL Road Frame - Red, 58     |FR-R92R-58   | 1431.5|
HL Road Frame - Red, 62     |FR-R92R-62   | 1431.5|
HL Road Front Wheel         |FW-R820      | 330.06|
HL Road Handlebars          |HB-R956      | 120.27|
...

Click me to see the solution

194. From the following tables write a query in SQL to return total sales and the discounts for each product. Sort the result set in descending order on productname.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: Sales.SalesOrderDetail

salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

productname                    |nondiscountsales|discounts  |
-------------------------------+----------------+-----------+
Women's Tights, S              |         224.970|      0.000|
Women's Tights, S              |         134.982|      0.000|
Women's Tights, S              |         134.982|      0.000|
Women's Tights, S              |         359.952|      0.000|
Women's Tights, S              |         179.976|      0.000|
Women's Tights, S              |         224.970|      0.000|
Women's Tights, S              |         269.964|      0.000|
Women's Tights, S              |         179.976|      0.000|
Women's Tights, S              |         269.964|      0.000|
Women's Tights, S              |          44.994|      0.000|
Women's Tights, S              |        608.9188|  12.178376|
Women's Tights, S              |         179.976|      0.000|
Women's Tights, S              |         359.952|      0.000|
...

Click me to see the solution

195. From the following tables write a query in SQL to calculate the revenue for each product in each sales order. Sort the result set in ascending order on productname.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: Sales.SalesOrderDetail

salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample Output:

?column?       |?column?    |?column?|productname                     |
---------------+------------+--------+--------------------------------+
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
Total income is|       159.0| for    |All-Purpose Bike Stand          |
...

Click me to see the solution

196. From the following tables write a query in SQL to retrieve one instance of each product name whose product model is a long sleeve logo jersey, and the ProductModelID numbers match between the tables.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample table: Production.ProductModel

productmodelid|name                       |catalogdescription|instructions|rowguid                             |modifieddate           |
--------------+---------------------------+------------------+------------+------------------------------------+-----------------------+
             1|Classic Vest               |                  |            |29321d47-1e4c-4aac-887c-19634328c25e|2013-04-30 00:00:00.000|
             2|Cycling Cap                |                  |            |474fb654-3c96-4cb9-82df-2152eeffbdb0|2011-05-01 00:00:00.000|
             3|Full-Finger Gloves         |                  |            |a75483fe-3c47-4aa4-93cf-664b51192987|2012-04-30 00:00:00.000|
             4|Half-Finger Gloves         |                  |            |14b56f2a-d4aa-40a4-b9a2-984f165ed702|2012-04-30 00:00:00.000|
             5|HL Mountain Frame          |                  |            |fdd5407b-c2db-49d1-a86b-c13a2e3582a2|2011-05-01 00:00:00.000|
             6|HL Road Frame              |                  |            |4d332ecc-48b3-4e04-b7e7-227f3ac2a7ec|2008-03-31 00:00:00.000|
             7|HL Touring Frame           |                  |[XML]       |d60ed2a5-c100-4c54-89a1-531404c4a20f|2015-04-15 16:34:28.980|
             8|LL Mountain Frame          |                  |            |65bf3f6d-bcf2-4db6-8515-fc5c57423037|2012-10-19 09:56:38.273|
             9|LL Road Frame              |                  |            |ddc67a2f-024a-4446-9b54-3c679baba708|2011-05-01 00:00:00.000|
            10|LL Touring Frame           |                  |[XML]       |66c63844-2a24-473c-96d5-d3b3fd57d834|2015-04-15 16:34:28.980|
            11|Long-Sleeve Logo Jersey    |                  |            |20efe3f1-a2f8-4dde-b74b-18265f61f863|2011-05-01 00:00:00.000|
            12|Men's Bib-Shorts           |                  |            |219e2f87-26a9-483b-b968-04578e943096|2012-04-30 00:00:00.000|
            13|Men's Sports Shorts        |                  |            |45fe0d77-6645-473c-a116-1232baea8d43|2012-04-30 00:00:00.000|
            14|ML Mountain Frame          |                  |            |0d48c51d-7603-4010-9265-0491805bb010|2012-04-30 00:00:00.000|
            15|ML Mountain Frame-W        |                  |            |aa77697c-6d1c-48f1-845c-3cb089498715|2012-04-30 00:00:00.000|
            16|ML Road Frame              |                  |            |3494e8ff-7daf-4860-abf6-97842048e272|2011-05-01 00:00:00.000|
            17|ML Road Frame-W            |                  |            |ca18ecfd-2023-4fa7-a556-0321153bca34|2012-04-30 00:00:00.000|
            18|Mountain Bike Socks        |                  |            |36b1a76a-dff3-4a55-86f9-65eb1cb18d7b|2011-05-01 00:00:00.000|
            19|Mountain-100               |[XML]             |            |fca0665b-b956-489a-a5ec-6f0b4aa14d02|2011-05-01 00:00:00.000|
            20|Mountain-200               |                  |            |3b78edff-2aa9-4ac1-8c3d-94090b5f53a9|2012-04-30 00:00:00.000|
            21|Mountain-300               |                  |            |ecddd0d7-2db2-464d-b2da-89bffc6276aa|2012-04-30 00:00:00.000|
            22|Mountain-400-W             |                  |            |6d2fcce4-ffce-4662-a3f8-5d18f0eedcd8|2013-04-30 00:00:00.000|
            23|Mountain-500               |[XML]             |            |866dbad3-5999-4329-beac-d826d959d9a1|2012-10-19 09:56:38.273|
            24|Racing Socks               |                  |            |bd8ba6f8-7e16-4fa3-b3b3-2036dd4a2ae0|2013-04-30 00:00:00.000|
            25|Road-150                   |[XML]             |            |94ffb702-0cbc-4e3f-b840-c51f0d11c8f6|2011-05-01 00:00:00.000|
            26|Road-250                   |                  |            |3770c5e3-8dc9-43c7-b735-7aff21645d96|2012-04-30 00:00:00.000|
            27|Road-350-W                 |                  |            |dfe49035-7720-4ff4-b28b-16250ee46259|2013-04-30 00:00:00.000|
            28|Road-450                   |[XML]             |            |8456bb94-b4dd-4a47-a76b-d0e54ab4285d|2011-05-01 00:00:00.000|
            29|Road-550-W                 |                  |            |f85f84f2-9ce0-4ecc-9c29-e78021ffc877|2012-04-30 00:00:00.000|
            30|Road-650                   |                  |            |42e1c597-6dd9-4071-b1a5-1dc5cdcbdbca|2011-05-01 00:00:00.000|
            31|Road-750                   |                  |            |2bf795f4-2666-4691-af14-d490c7334a8a|2012-10-19 09:56:38.273|
            32|Short-Sleeve Classic Jersey|                  |            |6beccf2d-eacd-496b-995b-d692567565cd|2013-04-30 00:00:00.000|
            33|Sport-100                  |                  |            |47f7c450-d16a-4cea-be6e-2d6c8c8f81ee|2011-05-01 00:00:00.000|
            34|Touring-1000               |[XML]             |            |52e7f2c1-dbff-4518-927d-c7d46f9ed32e|2012-10-19 09:56:38.273|
            35|Touring-2000               |[XML]             |            |aa10d9e6-e33f-4da8-ace1-992fcd6bb171|2012-10-19 09:56:38.273|
            36|Touring-3000               |                  |            |f5a6ec78-4451-45db-955f-db197de8b059|2012-10-19 09:56:38.273|
            37|Women's Mountain Shorts    |                  |            |a08dd61a-6155-4051-9a11-223232ea51cd|2013-04-30 00:00:00.000|
            38|Women's Tights             |                  |            |a96ff80d-d52a-432f-9701-731bef16efcc|2012-04-30 00:00:00.000|
            39|Mountain-400               |                  |            |37d261a7-00cf-4880-ac1a-533b6b4365b0|2011-05-01 00:00:00.000|
            40|Road-550                   |                  |            |30450264-4ab8-45e0-8bb5-4d407ea2950a|2012-04-30 00:00:00.000|
            41|Road-350                   |                  |            |d71bd21c-239e-4c2b-98a3-101962d6b2d3|2012-10-19 09:56:38.273|
            42|LL Mountain Front Wheel    |                  |            |aa977b32-acd8-4c53-a560-88a02ac1954d|2012-10-19 09:56:38.273|
            43|Touring Rear Wheel         |                  |[XML]       |e878fcaa-61cc-4014-988a-51f52643f7aa|2015-04-15 16:34:28.997|
            44|Touring Front Wheel        |                  |[XML]       |6da78798-3793-4b8e-829e-dba9d140b1d4|2015-04-15 16:34:28.997|
            45|ML Mountain Front Wheel    |                  |            |c3ff3f93-60a8-4957-b076-b7d0984ee70f|2012-04-30 00:00:00.000|
            46|HL Mountain Front Wheel    |                  |            |cca597fb-195f-4ec5-bf5c-15b98d176f4c|2012-04-30 00:00:00.000|
            47|LL Touring Handlebars      |                  |[XML]       |84138622-1ea6-489f-9c98-6e3924cfbac0|2015-04-15 16:34:29.010|
            48|HL Touring Handlebars      |                  |[XML]       |9da82e49-80ad-4918-9a54-31f4b0c8eabb|2015-04-15 16:34:29.027|
            49|LL Road Front Wheel        |                  |            |90f759c1-2073-4d9f-854b-c6b6f3bf9162|2012-04-30 00:00:00.000|
            50|ML Road Front Wheel        |                  |            |980c8cd0-4903-41f2-9ffc-773c7fe4c254|2012-04-30 00:00:00.000|
            51|HL Road Front Wheel        |                  |            |02a562e2-4dfa-4778-bbac-bbddcecf99b0|2012-04-30 00:00:00.000|
            52|LL Mountain Handlebars     |                  |            |699c2ac5-5406-46d2-863d-dcfb23fc7943|2012-04-30 00:00:00.000|
            53|Touring Pedal              |                  |[XML]       |b98a3207-56fc-405c-a040-3c7a90cc7890|2015-04-15 16:34:29.027|
            54|ML Mountain Handlebars     |                  |            |c9fcc804-2cd7-4b8a-b186-9c409cc19df9|2012-04-30 00:00:00.000|
            55|HL Mountain Handlebars     |                  |            |782c991b-a660-4561-a3f4-9bbd74259747|2012-04-30 00:00:00.000|
            56|LL Road Handlebars         |                  |            |a7e65199-84a8-437e-ad55-360c1df1d788|2012-04-30 00:00:00.000|
            57|ML Road Handlebars         |                  |            |02200aa0-c369-4d77-a67c-75973efda81b|2012-04-30 00:00:00.000|
            58|HL Road Handlebars         |                  |            |2489ddc5-1c89-4dec-af22-b0112ccec467|2012-04-30 00:00:00.000|
            59|LL Headset                 |                  |            |39afbba9-0f6c-44ee-b5e1-32fa93f897e6|2012-04-30 00:00:00.000|
            60|ML Headset                 |                  |            |6ba9f3b6-e08b-4ac2-a725-b41114c2a283|2012-04-30 00:00:00.000|
            61|HL Headset                 |                  |            |e196d02e-9bf6-4c67-b772-ed9f86ccf44c|2012-04-30 00:00:00.000|
            62|LL Mountain Pedal          |                  |            |8123f7e2-a5f4-4047-b69d-e74313dfebce|2013-04-30 00:00:00.000|
            63|ML Mountain Pedal          |                  |            |be9cdc56-f4ab-40f1-b338-2e08e0627abd|2013-04-30 00:00:00.000|
            64|HL Mountain Pedal          |                  |            |8da73708-8dae-44ae-ac6c-6e37022c1ffe|2013-04-30 00:00:00.000|
            65|ML Touring Seat/Saddle     |                  |            |63a2199f-f5b5-49bd-bcfc-bec1d1d16d8b|2013-04-30 00:00:00.000|
            66|LL Touring Seat/Saddle     |                  |[XML]       |4a17c43a-1a55-41bb-bc97-612f47cedeb3|2015-04-15 16:34:29.043|
            67|HL Touring Seat/Saddle     |                  |[XML]       |059a2000-7549-4b49-8e0c-2de6b2771ef4|2015-04-15 16:34:29.043|
            68|LL Road Pedal              |                  |            |218b016c-7454-4193-b518-21955c783d72|2013-04-30 00:00:00.000|
            69|ML Road Pedal              |                  |            |3cdf61d6-6209-436f-b235-82e8f159208b|2013-04-30 00:00:00.000|
            70|HL Road Pedal              |                  |            |35677b42-72ca-4d9e-a966-dd874b83ef45|2013-04-30 00:00:00.000|
            71|LL Mountain Seat/Saddle 1  |                  |            |a166af4c-87bb-41aa-8496-d76b26008fb3|2013-04-30 00:00:00.000|
            72|ML Mountain Seat/Saddle 1  |                  |            |baa9405b-68ca-4c18-bc9c-1c4acf49bafc|2013-04-30 00:00:00.000|
            73|HL Mountain Seat/Saddle 1  |                  |            |bbe4918f-198d-43c7-9f4b-79bc2aa08f2b|2013-04-30 00:00:00.000|
            74|LL Road Seat/Saddle 2      |                  |            |24e3e7d4-4053-4035-9d69-f451642f0c1e|2013-04-30 00:00:00.000|
            75|ML Road Seat/Saddle 1      |                  |            |394ed69c-2cc4-4a85-9080-8534112b66fe|2013-04-30 00:00:00.000|
            76|HL Road Seat/Saddle 1      |                  |            |b83ab7ae-ba3f-40df-8296-361915a3a60c|2013-04-30 00:00:00.000|
            77|ML Road Rear Wheel         |                  |            |15702f98-bd92-4fe8-86bc-52f5fd049d3d|2012-04-30 00:00:00.000|
            78|HL Road Rear Wheel         |                  |            |438cbcfa-05ff-4a29-ad95-ecf41dcb83d5|2012-04-30 00:00:00.000|
            79|LL Mountain Seat/Saddle 2  |                  |            |8bbeb399-5a87-4e40-9f52-462fb54f2183|2013-04-30 00:00:00.000|
            80|ML Mountain Seat/Saddle 2  |                  |            |5cefbb6e-3b7e-414f-ac1b-8f6df741fb21|2013-04-30 00:00:00.000|
            81|HL Mountain Seat/Saddle 2  |                  |            |98726f80-e9b9-4141-9cf5-bd2ef07dce25|2013-04-30 00:00:00.000|
            82|LL Road Seat/Saddle 1      |                  |            |00ce9171-8944-4d49-ba37-485c1d122f5c|2013-04-30 00:00:00.000|
            83|ML Road Seat/Saddle 2      |                  |            |feeb8440-446e-4df8-9482-d529c4fc5e8f|2013-04-30 00:00:00.000|
            84|HL Road Seat/Saddle 2      |                  |            |0d3a6ad7-6891-4de9-b14f-e1a841eb220c|2013-04-30 00:00:00.000|
            85|LL Mountain Tire           |                  |            |e3cdc5dd-27c3-4891-9d5e-0d46d1b8457f|2013-04-30 00:00:00.000|
            86|ML Mountain Tire           |                  |            |0434f63a-a361-4d0b-a9fc-8ac2a866ce85|2013-04-30 00:00:00.000|
            87|HL Mountain Tire           |                  |            |ce1b1064-6679-4212-8f56-2b2617ec56a5|2013-04-30 00:00:00.000|
            88|LL Road Tire               |                  |            |e7b00dff-8136-4947-b503-994584cc89e7|2013-04-30 00:00:00.000|
            89|ML Road Tire               |                  |            |d566eb0f-6945-43d8-bc40-bb3d2f4ef7ed|2013-04-30 00:00:00.000|
            90|HL Road Tire               |                  |            |a4b205df-955a-494e-8428-1898aea76f24|2013-04-30 00:00:00.000|
            91|Touring Tire               |                  |            |3bcc63d6-9340-4b93-b5f2-73fa90758bf5|2013-04-30 00:00:00.000|
            92|Mountain Tire Tube         |                  |            |8cfbe7f2-eec3-4ba6-8187-c8a3614f1f0b|2013-04-30 00:00:00.000|
            93|Road Tire Tube             |                  |            |2771d2d2-2e35-4c12-966e-ce9070df6d53|2013-04-30 00:00:00.000|
            94|Touring Tire Tube          |                  |            |deeea9bc-3c8c-4e73-b6b0-64c81a5d99e3|2013-04-30 00:00:00.000|
            95|LL Bottom Bracket          |                  |            |217e7475-d3f4-46fa-836a-d9e53103e71b|2013-04-30 00:00:00.000|
            96|ML Bottom Bracket          |                  |            |09caa74e-f47b-4fca-b206-9d3e46df9751|2013-04-30 00:00:00.000|
            97|HL Bottom Bracket          |                  |            |816360e1-3dee-4568-bf2f-9828243d887b|2013-04-30 00:00:00.000|
            98|Chain                      |                  |            |aca920b2-d0f9-49f3-b879-573202b08c2f|2013-04-30 00:00:00.000|
            99|LL Crankset                |                  |            |5b59f032-9b73-4d90-b252-eafd6a871ff1|2013-04-30 00:00:00.000|
           100|ML Crankset                |                  |            |68c6cb29-d94a-40c5-aaad-90aa6e7c5ea1|2013-04-30 00:00:00.000|
           101|HL Crankset                |                  |            |809668a3-d492-41fb-a196-cfe092a12aa2|2013-04-30 00:00:00.000|
           102|Front Brakes               |                  |            |1099a23a-c9ed-41b1-8cc1-e2c1c54a10c8|2013-04-30 00:00:00.000|
           103|Front Derailleur           |                  |            |10e0c8fd-ca13-437b-8e22-51853ae160a7|2013-04-30 00:00:00.000|
           104|LL Fork                    |                  |            |0481d7e1-4970-4efa-a560-020f6579918d|2012-04-30 00:00:00.000|
           105|ML Fork                    |                  |            |5f115aa4-0553-4478-84b3-5dcf3abe0d08|2012-04-30 00:00:00.000|
           106|HL Fork                    |                  |            |7706a8fd-9513-40bc-95e8-301b55b67db2|2012-04-30 00:00:00.000|
           107|Hydration Pack             |                  |            |cfeef30f-f059-4447-92a8-47001e69f3db|2013-04-30 00:00:00.000|
           108|Taillight                  |                  |            |dba643d4-4cf2-4507-b947-e817d8c5792b|2012-04-30 00:00:00.000|
           109|Headlights - Dual-Beam     |                  |            |7b17ebf1-cb73-4934-9689-1dc26cf22d9c|2012-04-30 00:00:00.000|
           110|Headlights - Weatherproof  |                  |            |1fadb88f-af88-4e94-bb1e-6158c48e6b40|2012-04-30 00:00:00.000|
           111|Water Bottle               |                  |            |3688268a-260c-48bf-bf71-fff350d4d3d5|2013-04-30 00:00:00.000|
           112|Mountain Bottle Cage       |                  |            |2194e65b-9c13-46e1-a655-3ebff8a96719|2013-04-30 00:00:00.000|
           113|Road Bottle Cage           |                  |            |9416c2dd-55d8-469d-8edf-ef447c511897|2013-04-30 00:00:00.000|
           114|Patch kit                  |                  |            |7c738101-c01e-45a2-a0e0-b28aeba1dc40|2013-04-30 00:00:00.000|
           115|Cable Lock                 |                  |            |e7e17f11-a7fd-4c3c-b701-68f0ae26143e|2012-04-30 00:00:00.000|
           116|Minipump                   |                  |            |90cef1a7-d817-403e-814c-40e305eeefef|2012-04-30 00:00:00.000|
           117|Mountain Pump              |                  |            |b35598f6-b413-4138-8081-5dc7d4c64b64|2012-04-30 00:00:00.000|
           118|Hitch Rack - 4-Bike        |                  |            |f570e0d1-e978-4ff2-b5b1-08f01ab60219|2013-04-30 00:00:00.000|
           119|Bike Wash                  |                  |            |90b1b93d-ebc8-44a2-ac08-cdd1d20ca39c|2013-04-30 00:00:00.000|
           120|Touring-Panniers           |                  |            |f06999a1-3aa7-4e85-b8cb-049eb2c391fa|2012-04-30 00:00:00.000|
           121|Fender Set - Mountain      |                  |            |c88d1136-a8bb-46bb-94aa-8c1854f813cc|2013-04-30 00:00:00.000|
           122|All-Purpose Bike Stand     |                  |            |6eab8607-d927-40e1-af30-d8a2a953050c|2013-04-30 00:00:00.000|
           123|LL Mountain Rear Wheel     |                  |            |29521f66-2926-471f-867b-668b0b9ec2b0|2012-04-30 00:00:00.000|
           124|ML Mountain Rear Wheel     |                  |            |d968d774-778e-4399-a3c5-375176418229|2012-04-30 00:00:00.000|
           125|HL Mountain Rear Wheel     |                  |            |95450545-adf7-48f3-899e-964de8920dc6|2012-04-30 00:00:00.000|
           126|LL Road Rear Wheel         |                  |            |95946bd4-c6d9-4344-8066-317d8957ea21|2012-04-30 00:00:00.000|
           127|Rear Derailleur            |                  |            |f9327e5d-f8b6-40c5-bfa9-63f886bdfc24|2013-04-30 00:00:00.000|
           128|Rear Brakes                |                  |            |71d47afd-da3a-43f1-83ad-69c71f96ef33|2013-04-30 00:00:00.000|

Click to view Full table

Sample Output:

name                       |
---------------------------+
Long-Sleeve Logo Jersey, L |
Long-Sleeve Logo Jersey, M |
Long-Sleeve Logo Jersey, S |
Long-Sleeve Logo Jersey, XL|

Click me to see the solution

197. From the following tables write a query in SQL to retrieve the first and last name of each employee whose bonus in the SalesPerson table is 5000.

Sample table: Person.Person

businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: HumanResources.Employee

businessentityid|nationalidnumber|loginid                     |jobtitle                                |birthdate |maritalstatus|gender|hiredate  |salariedflag|vacationhours|sickleavehours|currentflag|rowguid                             |modifieddate           |organizationnode|
----------------+----------------+----------------------------+----------------------------------------+----------+-------------+------+----------+------------+-------------+--------------+-----------+------------------------------------+-----------------------+----------------+
               1|295847284       |adventure-works\ken0        |Chief Executive Officer                 |1969-01-29|S            |M     |2009-01-14|true        |           99|            69|true       |f01251e5-96a3-448d-981e-0f99d789110d|2014-06-30 00:00:00.000|/               |
               2|245797967       |adventure-works\terri0      |Vice President of Engineering           |1971-08-01|S            |F     |2008-01-31|true        |            1|            20|true       |45e8f437-670d-4409-93cb-f9424a40d6ee|2014-06-30 00:00:00.000|/1/             |
               3|509647174       |adventure-works\roberto0    |Engineering Manager                     |1974-11-12|M            |M     |2007-11-11|true        |            2|            21|true       |9bbbfb2c-efbb-4217-9ab7-f97689328841|2014-06-30 00:00:00.000|/1/1/           |
               4|112457891       |adventure-works\rob0        |Senior Tool Designer                    |1974-12-23|S            |M     |2007-12-05|false       |           48|            80|true       |59747955-87b8-443f-8ed4-f8ad3afdf3a9|2014-06-30 00:00:00.000|/1/1/1/         |
               5|695256908       |adventure-works\gail0       |Design Engineer                         |1952-09-27|M            |F     |2008-01-06|true        |            5|            22|true       |ec84ae09-f9b8-4a15-b4a9-6ccbab919b08|2014-06-30 00:00:00.000|/1/1/2/         |
               6|998320692       |adventure-works\jossef0     |Design Engineer                         |1959-03-11|M            |M     |2008-01-24|true        |            6|            23|true       |e39056f1-9cd5-478d-8945-14aca7fbdcdd|2014-06-30 00:00:00.000|/1/1/3/         |
               7|134969118       |adventure-works\dylan0      |Research and Development Manager        |1987-02-24|M            |M     |2009-02-08|true        |           61|            50|true       |4f46deca-ef01-41fd-9829-0adab368e431|2014-06-30 00:00:00.000|/1/1/4/         |
               8|811994146       |adventure-works\diane1      |Research and Development Engineer       |1986-06-05|S            |F     |2008-12-29|true        |           62|            51|true       |31112635-663b-4018-b4a2-a685c0bf48a4|2014-06-30 00:00:00.000|/1/1/4/1/       |
               9|658797903       |adventure-works\gigi0       |Research and Development Engineer       |1979-01-21|M            |F     |2009-01-16|true        |           63|            51|true       |50b6cdc6-7570-47ef-9570-48a64b5f2ecf|2014-06-30 00:00:00.000|/1/1/4/2/       |
              10|879342154       |adventure-works\michael6    |Research and Development Manager        |1984-11-30|M            |M     |2009-05-03|true        |           16|            64|true       |eaa43680-5571-40cb-ab1a-3bf68f04459e|2014-06-30 00:00:00.000|/1/1/4/3/       |
			  -- more --

Click to view Full table

Sample table: Sales.SalesPerson

businessentityid|territoryid|salesquota|bonus|commissionpct|salesytd    |saleslastyear|rowguid                             |modifieddate           |
----------------+-----------+----------+-----+-------------+------------+-------------+------------------------------------+-----------------------+
             274|           |          |    0|            0| 559697.5639|            0|48754992-9ee0-4c0e-8c94-9451604e3e02|2010-12-28 00:00:00.000|
             275|          2|    300000| 4100|        0.012|3763178.1787| 1750406.4785|1e0a7274-3064-4f58-88ee-4c6586c87169|2011-05-24 00:00:00.000|
             276|          4|    250000| 2000|        0.015|4251368.5497| 1439156.0291|4dd9eee4-8e81-4f8c-af97-683394c1f7c0|2011-05-24 00:00:00.000|
             277|          3|    250000| 2500|        0.015|3189418.3662| 1997186.2037|39012928-bfec-4242-874d-423162c3f567|2011-05-24 00:00:00.000|
             278|          6|    250000|  500|         0.01|1453719.4653| 1620276.8966|7a0ae1ab-b283-40f9-91d1-167abf06d720|2011-05-24 00:00:00.000|
             279|          5|    300000| 6700|         0.01| 2315185.611| 1849640.9418|52a5179d-3239-4157-ae29-17e868296dc0|2011-05-24 00:00:00.000|
             280|          1|    250000| 5000|         0.01|1352577.1325|  1927059.178|be941a4a-fb50-4947-bda4-bb8972365b08|2011-05-24 00:00:00.000|
             281|          4|    250000| 3550|         0.01|2458535.6169| 2073505.9999|35326ddb-7278-4fef-b3ba-ea137b69094e|2011-05-24 00:00:00.000|
             282|          6|    250000| 5000|        0.015|2604540.7172| 2038234.6549|31fd7fc1-dc84-4f05-b9a0-762519eacacc|2011-05-24 00:00:00.000|
             283|          1|    250000| 3500|        0.012|1573012.9383| 1371635.3158|6bac15b2-8ffb-45a9-b6d5-040e16c2073f|2011-05-24 00:00:00.000|
             284|          1|    300000| 3900|        0.019|1576562.1966|            0|ac94ec04-a2dc-43e3-8654-dd0c546abc17|2012-09-23 00:00:00.000|
             285|           |          |    0|            0| 172524.4512|            0|cfdbef27-b1f7-4a56-a878-0221c73bae67|2013-03-07 00:00:00.000|
             286|          9|    250000| 5650|        0.018|1421810.9242| 2278548.9776|9b968777-75dc-45bd-a8df-9cdaa72839e1|2013-05-23 00:00:00.000|
             287|           |          |    0|            0|  519905.932|            0|1dd1f689-df74-4149-8600-59555eef154b|2012-04-09 00:00:00.000|
             288|          8|    250000|   75|        0.018|1827066.7118| 1307949.7917|224bb25a-62e3-493e-acaf-4f8f5c72396a|2013-05-23 00:00:00.000|
             289|         10|    250000| 5150|         0.02|4116871.2277| 1635823.3967|25f6838d-9db4-4833-9ddc-7a24283af1ba|2012-05-23 00:00:00.000|
             290|          7|    250000|  985|        0.016|3121616.3202| 2396539.7601|f509e3d4-76c8-42aa-b353-90b7b8db08de|2012-05-23 00:00:00.000|

Click to view Full table

Sample Output:

lastname    |firstname|
------------+---------+
Ansman-Wolfe|Pamela   |
Saraiva     |José     |

Click me to see the solution

198. From the following table write a query in SQL to find product models where the maximum list price is more than twice the average.

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

productmodelid|
--------------+
            58|
             8|
            87|
           116|
            68|
            51|
            70|
            80|
            52|
            84|
            92|
           101|
            69|
...

Click me to see the solution

199. From the following tables, write a query in SQL to find the first and last names of employees who have sold a product with the ProductNumber 'BK-M68B-42'. Return the distinct columns LastName and FirstName.

Sample table: Person.Person

businessentityid|persontype|namestyle|title|firstname               |middlename      |lastname              |suffix|emailpromotion|additionalcontactinfo|demographics|rowguid                             |modifieddate           |
----------------+----------+---------+-----+------------------------+----------------+----------------------+------+--------------+---------------------+------------+------------------------------------+-----------------------+
               1|EM        |false    |     |Ken                     |J               |Sánchez               |      |             0|                     |[XML]       |92c4279f-1207-48a3-8448-4636514eb7e2|2009-01-07 00:00:00.000|
               2|EM        |false    |     |Terri                   |Lee             |Duffy                 |      |             1|                     |[XML]       |d8763459-8aa8-47cc-aff7-c9079af79033|2008-01-24 00:00:00.000|
               3|EM        |false    |     |Roberto                 |                |Tamburello            |      |             0|                     |[XML]       |e1a2555e-0828-434b-a33b-6f38136a37de|2007-11-04 00:00:00.000|
               4|EM        |false    |     |Rob                     |                |Walters               |      |             0|                     |[XML]       |f2d7ce06-38b3-4357-805b-f4b6b71c01ff|2007-11-28 00:00:00.000|
               5|EM        |false    |Ms.  |Gail                    |A               |Erickson              |      |             0|                     |[XML]       |f3a3f6b4-ae3b-430c-a754-9f2231ba6fef|2007-12-30 00:00:00.000|
               6|EM        |false    |Mr.  |Jossef                  |H               |Goldberg              |      |             0|                     |[XML]       |0dea28fd-effe-482a-afd3-b7e8f199d56f|2013-12-16 00:00:00.000|
               7|EM        |false    |     |Dylan                   |A               |Miller                |      |             2|                     |[XML]       |c45e8ab8-01be-4b76-b215-820c8368181a|2009-02-01 00:00:00.000|
               8|EM        |false    |     |Diane                   |L               |Margheim              |      |             0|                     |[XML]       |a948e590-4a56-45a9-bc9a-160a1cc9d990|2008-12-22 00:00:00.000|
               9|EM        |false    |     |Gigi                    |N               |Matthew               |      |             0|                     |[XML]       |5fc28c0e-6d36-4252-9846-05caa0b1f6c5|2009-01-09 00:00:00.000|
			   -- more --

Click to view Full table

Sample table: sales.SalesOrderHeader

salesorderid|revisionnumber|orderdate              |duedate                |shipdate               |status|onlineorderflag|purchaseordernumber|accountnumber |customerid|salespersonid|territoryid|billtoaddressid|shiptoaddressid|shipmethodid|creditcardid|creditcardapprovalcode|currencyrateid|subtotal   |taxamt    |freight  |totaldue   |comment|rowguid                             |modifieddate           |
------------+--------------+-----------------------+-----------------------+-----------------------+------+---------------+-------------------+--------------+----------+-------------+-----------+---------------+---------------+------------+------------+----------------------+--------------+-----------+----------+---------+-----------+-------+------------------------------------+-----------------------+
       43659|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO522145787        |10-4020-000676|     29825|          279|          5|            985|            985|           5|       16281|105041Vi84182         |              | 20565.6206| 1971.5149| 616.0984| 23153.2339|       |79b65321-39ca-4115-9cba-8fe0903e12e6|2011-06-07 00:00:00.000|
       43660|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18850127500      |10-4020-000117|     29672|          279|          5|            921|            921|           5|        5618|115213Vi29411         |              |  1294.2529|  124.2483|  38.8276|  1457.3288|       |738dc42d-d03b-48a1-9822-f95a67ea7389|2011-06-07 00:00:00.000|
       43661|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18473189620      |10-4020-000442|     29734|          282|          6|            517|            517|           5|        1346|85274Vi6854           |             4| 32726.4786| 3153.7696|  985.553| 36865.8012|       |d91b9131-18a4-4a11-bc3a-90b6f53e9d74|2011-06-07 00:00:00.000|
       43662|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18444174044      |10-4020-000227|     29994|          282|          6|            482|            482|           5|       10456|125295Vi53935         |             4| 28832.5289| 2775.1646| 867.2389| 32474.9324|       |4a1ecfc0-cc3a-4740-b028-1c50bb48711c|2011-06-07 00:00:00.000|
       43663|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO18009186470      |10-4020-000510|     29565|          276|          4|           1073|           1073|           5|        4322|45303Vi22691          |              |   419.4589|   40.2681|  12.5838|   472.3108|       |9b1e7a40-6ae0-4ad3-811c-a64951857c4b|2011-06-07 00:00:00.000|
       43664|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16617121983      |10-4020-000397|     29898|          280|          1|            876|            876|           5|         806|95555Vi4081           |              | 24432.6088| 2344.9921|   732.81| 27510.4109|       |22a8a5da-8c22-42ad-9241-839489b6ef0d|2011-06-07 00:00:00.000|
       43665|             8|2011-05-31 00:00:00.000|2011-06-12 00:00:00.000|2011-06-07 00:00:00.000|     5|false          |PO16588191572      |10-4020-000146|     29580|          283|          1|            849|            849|           5|       15232|35568Vi78804          |              | 14352.7713| 1375.9427| 429.9821| 16158.6961|       |5602c304-853c-43d7-9e79-76e320d476cf|2011-06-07 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: Sales.SalesOrderDetail

salesorderid|salesorderdetailid|carriertrackingnumber|orderqty|productid|specialofferid|unitprice|unitpricediscount|rowguid                             |modifieddate           |
------------+------------------+---------------------+--------+---------+--------------+---------+-----------------+------------------------------------+-----------------------+
       43659|                 1|4911-403C-98         |       1|      776|             1| 2024.994|                0|b207c96d-d9e6-402b-8470-2cc176c42283|2011-05-31 00:00:00.000|
       43659|                 2|4911-403C-98         |       3|      777|             1| 2024.994|                0|7abb600d-1e77-41be-9fe5-b9142cfc08fa|2011-05-31 00:00:00.000|
       43659|                 3|4911-403C-98         |       1|      778|             1| 2024.994|                0|475cf8c6-49f6-486e-b0ad-afc6a50cdd2f|2011-05-31 00:00:00.000|
       43659|                 4|4911-403C-98         |       1|      771|             1| 2039.994|                0|04c4de91-5815-45d6-8670-f462719fbce3|2011-05-31 00:00:00.000|
       43659|                 5|4911-403C-98         |       1|      772|             1| 2039.994|                0|5a74c7d2-e641-438e-a7ac-37bf23280301|2011-05-31 00:00:00.000|
       43659|                 6|4911-403C-98         |       2|      773|             1| 2039.994|                0|ce472532-a4c0-45ba-816e-eefd3fd848b3|2011-05-31 00:00:00.000|
       43659|                 7|4911-403C-98         |       1|      774|             1| 2039.994|                0|80667840-f962-4ee3-96e0-aeca108e0d4f|2011-05-31 00:00:00.000|
       43659|                 8|4911-403C-98         |       3|      714|             1|  28.8404|                0|e9d54907-e7b7-4969-80d9-76ba69f8a836|2011-05-31 00:00:00.000|
       43659|                 9|4911-403C-98         |       1|      716|             1|  28.8404|                0|aa542630-bdcd-4ce5-89a0-c1bf82747725|2011-05-31 00:00:00.000|
       43659|                10|4911-403C-98         |       6|      709|             1|      5.7|                0|ac769034-3c2f-495c-a5a7-3b71cdb25d4e|2011-05-31 00:00:00.000|
       43659|                11|4911-403C-98         |       2|      712|             1|   5.1865|                0|06a66921-6b9f-4199-a912-ddafd383472b|2011-05-31 00:00:00.000|
       43659|                12|4911-403C-98         |       4|      711|             1|  20.1865|                0|0e371ee3-253e-4bb0-b813-83cf4224f972|2011-05-31 00:00:00.000|
	   -- more --

Click to view Full table

Sample table: Production.Product

productid|name                            |productnumber|makeflag|finishedgoodsflag|color       |safetystocklevel|reorderpoint|standardcost|listprice|size|sizeunitmeasurecode|weightunitmeasurecode|weight |daystomanufacture|productline|class|style|productsubcategoryid|productmodelid|sellstartdate          |sellenddate            |discontinueddate|rowguid                             |modifieddate           |
---------+--------------------------------+-------------+--------+-----------------+------------+----------------+------------+------------+---------+----+-------------------+---------------------+-------+-----------------+-----------+-----+-----+--------------------+--------------+-----------------------+-----------------------+----------------+------------------------------------+-----------------------+
        1|Adjustable Race                 |AR-5381      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |694215b7-08f7-4c0d-acb1-d734ba44c0c8|2014-02-08 10:01:36.827|
        2|Bearing Ball                    |BA-8327      |false   |false            |            |            1000|         750|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |58ae3c20-4f3a-4749-a7d4-d568806cc537|2014-02-08 10:01:36.827|
        3|BB Ball Bearing                 |BE-2349      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |9c21aed2-5bfa-4f18-bcb8-f11638dc2e4e|2014-02-08 10:01:36.827|
        4|Headset Ball Bearings           |BE-2908      |false   |false            |            |             800|         600|           0|        0|    |                   |                     |       |                0|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |ecfed6cb-51ff-49b5-b06c-7d8ac834db8b|2014-02-08 10:01:36.827|
      316|Blade                           |BL-2036      |true    |false            |            |             800|         600|           0|        0|    |                   |                     |       |                1|           |     |     |                    |              |2008-04-30 00:00:00.000|                       |                |e73e9750-603b-4131-89f5-3dd15ed5ff80|2014-02-08 10:01:36.827|
      317|LL Crankarm                     |CA-5965      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |L    |     |                    |              |2008-04-30 00:00:00.000|                       |                |3c9d10b7-a6b2-4774-9963-c19dcee72fea|2014-02-08 10:01:36.827|
      318|ML Crankarm                     |CA-6738      |false   |false            |Black       |             500|         375|           0|        0|    |                   |                     |       |                0|           |M    |     |                    |              |2008-04-30 00:00:00.000|                       |                |eabb9a92-fa07-4eab-8955-f0517b4a4ca7|2014-02-08 10:01:36.827|
	  -- more --

Click to view Full table

Sample Output:

lastname         |firstname|
-----------------+---------+
Alberts          |Amy      |
Ansman-Wolfe     |Pamela   |
Blythe           |Michael  |
Campbell         |David    |
Carson           |Jillian  |
Ito              |Shu      |
Jiang            |Stephen  |
Mensa-Annan      |Tete     |
Mitchell         |Linda    |
Pak              |Jae      |
Reiter           |Tsvi     |
Saraiva          |José     |
Tsoflias         |Lynn     |
Valdez           |Rachel   |
....

Click me to see the solution

200. Create a table public.gloves from Production.ProductModel for the ProductModelID 3 and 4.
From the following table write a query in SQL to include the contents of the ProductModelID and Name columns of both the tables.

Sample table: Production.ProductModel

productmodelid|name                       |catalogdescription|instructions|rowguid                             |modifieddate           |
--------------+---------------------------+------------------+------------+------------------------------------+-----------------------+
             1|Classic Vest               |                  |            |29321d47-1e4c-4aac-887c-19634328c25e|2013-04-30 00:00:00.000|
             2|Cycling Cap                |                  |            |474fb654-3c96-4cb9-82df-2152eeffbdb0|2011-05-01 00:00:00.000|
             3|Full-Finger Gloves         |                  |            |a75483fe-3c47-4aa4-93cf-664b51192987|2012-04-30 00:00:00.000|
             4|Half-Finger Gloves         |                  |            |14b56f2a-d4aa-40a4-b9a2-984f165ed702|2012-04-30 00:00:00.000|
             5|HL Mountain Frame          |                  |            |fdd5407b-c2db-49d1-a86b-c13a2e3582a2|2011-05-01 00:00:00.000|
             6|HL Road Frame              |                  |            |4d332ecc-48b3-4e04-b7e7-227f3ac2a7ec|2008-03-31 00:00:00.000|
             7|HL Touring Frame           |                  |[XML]       |d60ed2a5-c100-4c54-89a1-531404c4a20f|2015-04-15 16:34:28.980|
             8|LL Mountain Frame          |                  |            |65bf3f6d-bcf2-4db6-8515-fc5c57423037|2012-10-19 09:56:38.273|
             9|LL Road Frame              |                  |            |ddc67a2f-024a-4446-9b54-3c679baba708|2011-05-01 00:00:00.000|
            10|LL Touring Frame           |                  |[XML]       |66c63844-2a24-473c-96d5-d3b3fd57d834|2015-04-15 16:34:28.980|
            11|Long-Sleeve Logo Jersey    |                  |            |20efe3f1-a2f8-4dde-b74b-18265f61f863|2011-05-01 00:00:00.000|
            12|Men's Bib-Shorts           |                  |            |219e2f87-26a9-483b-b968-04578e943096|2012-04-30 00:00:00.000|
            13|Men's Sports Shorts        |                  |            |45fe0d77-6645-473c-a116-1232baea8d43|2012-04-30 00:00:00.000|
            14|ML Mountain Frame          |                  |            |0d48c51d-7603-4010-9265-0491805bb010|2012-04-30 00:00:00.000|
            15|ML Mountain Frame-W        |                  |            |aa77697c-6d1c-48f1-845c-3cb089498715|2012-04-30 00:00:00.000|
            16|ML Road Frame              |                  |            |3494e8ff-7daf-4860-abf6-97842048e272|2011-05-01 00:00:00.000|
            17|ML Road Frame-W            |                  |            |ca18ecfd-2023-4fa7-a556-0321153bca34|2012-04-30 00:00:00.000|
            18|Mountain Bike Socks        |                  |            |36b1a76a-dff3-4a55-86f9-65eb1cb18d7b|2011-05-01 00:00:00.000|
            19|Mountain-100               |[XML]             |            |fca0665b-b956-489a-a5ec-6f0b4aa14d02|2011-05-01 00:00:00.000|
            20|Mountain-200               |                  |            |3b78edff-2aa9-4ac1-8c3d-94090b5f53a9|2012-04-30 00:00:00.000|
            21|Mountain-300               |                  |            |ecddd0d7-2db2-464d-b2da-89bffc6276aa|2012-04-30 00:00:00.000|
            22|Mountain-400-W             |                  |            |6d2fcce4-ffce-4662-a3f8-5d18f0eedcd8|2013-04-30 00:00:00.000|
            23|Mountain-500               |[XML]             |            |866dbad3-5999-4329-beac-d826d959d9a1|2012-10-19 09:56:38.273|
            24|Racing Socks               |                  |            |bd8ba6f8-7e16-4fa3-b3b3-2036dd4a2ae0|2013-04-30 00:00:00.000|
            25|Road-150                   |[XML]             |            |94ffb702-0cbc-4e3f-b840-c51f0d11c8f6|2011-05-01 00:00:00.000|
            26|Road-250                   |                  |            |3770c5e3-8dc9-43c7-b735-7aff21645d96|2012-04-30 00:00:00.000|
            27|Road-350-W                 |                  |            |dfe49035-7720-4ff4-b28b-16250ee46259|2013-04-30 00:00:00.000|
            28|Road-450                   |[XML]             |            |8456bb94-b4dd-4a47-a76b-d0e54ab4285d|2011-05-01 00:00:00.000|
            29|Road-550-W                 |                  |            |f85f84f2-9ce0-4ecc-9c29-e78021ffc877|2012-04-30 00:00:00.000|
            30|Road-650                   |                  |            |42e1c597-6dd9-4071-b1a5-1dc5cdcbdbca|2011-05-01 00:00:00.000|
            31|Road-750                   |                  |            |2bf795f4-2666-4691-af14-d490c7334a8a|2012-10-19 09:56:38.273|
            32|Short-Sleeve Classic Jersey|                  |            |6beccf2d-eacd-496b-995b-d692567565cd|2013-04-30 00:00:00.000|
            33|Sport-100                  |                  |            |47f7c450-d16a-4cea-be6e-2d6c8c8f81ee|2011-05-01 00:00:00.000|
            34|Touring-1000               |[XML]             |            |52e7f2c1-dbff-4518-927d-c7d46f9ed32e|2012-10-19 09:56:38.273|
            35|Touring-2000               |[XML]             |            |aa10d9e6-e33f-4da8-ace1-992fcd6bb171|2012-10-19 09:56:38.273|
            36|Touring-3000               |                  |            |f5a6ec78-4451-45db-955f-db197de8b059|2012-10-19 09:56:38.273|
            37|Women's Mountain Shorts    |                  |            |a08dd61a-6155-4051-9a11-223232ea51cd|2013-04-30 00:00:00.000|
            38|Women's Tights             |                  |            |a96ff80d-d52a-432f-9701-731bef16efcc|2012-04-30 00:00:00.000|
            39|Mountain-400               |                  |            |37d261a7-00cf-4880-ac1a-533b6b4365b0|2011-05-01 00:00:00.000|
            40|Road-550                   |                  |            |30450264-4ab8-45e0-8bb5-4d407ea2950a|2012-04-30 00:00:00.000|
            41|Road-350                   |                  |            |d71bd21c-239e-4c2b-98a3-101962d6b2d3|2012-10-19 09:56:38.273|
            42|LL Mountain Front Wheel    |                  |            |aa977b32-acd8-4c53-a560-88a02ac1954d|2012-10-19 09:56:38.273|
            43|Touring Rear Wheel         |                  |[XML]       |e878fcaa-61cc-4014-988a-51f52643f7aa|2015-04-15 16:34:28.997|
            44|Touring Front Wheel        |                  |[XML]       |6da78798-3793-4b8e-829e-dba9d140b1d4|2015-04-15 16:34:28.997|
            45|ML Mountain Front Wheel    |                  |            |c3ff3f93-60a8-4957-b076-b7d0984ee70f|2012-04-30 00:00:00.000|
            46|HL Mountain Front Wheel    |                  |            |cca597fb-195f-4ec5-bf5c-15b98d176f4c|2012-04-30 00:00:00.000|
            47|LL Touring Handlebars      |                  |[XML]       |84138622-1ea6-489f-9c98-6e3924cfbac0|2015-04-15 16:34:29.010|
            48|HL Touring Handlebars      |                  |[XML]       |9da82e49-80ad-4918-9a54-31f4b0c8eabb|2015-04-15 16:34:29.027|
            49|LL Road Front Wheel        |                  |            |90f759c1-2073-4d9f-854b-c6b6f3bf9162|2012-04-30 00:00:00.000|
            50|ML Road Front Wheel        |                  |            |980c8cd0-4903-41f2-9ffc-773c7fe4c254|2012-04-30 00:00:00.000|
            51|HL Road Front Wheel        |                  |            |02a562e2-4dfa-4778-bbac-bbddcecf99b0|2012-04-30 00:00:00.000|
            52|LL Mountain Handlebars     |                  |            |699c2ac5-5406-46d2-863d-dcfb23fc7943|2012-04-30 00:00:00.000|
            53|Touring Pedal              |                  |[XML]       |b98a3207-56fc-405c-a040-3c7a90cc7890|2015-04-15 16:34:29.027|
            54|ML Mountain Handlebars     |                  |            |c9fcc804-2cd7-4b8a-b186-9c409cc19df9|2012-04-30 00:00:00.000|
            55|HL Mountain Handlebars     |                  |            |782c991b-a660-4561-a3f4-9bbd74259747|2012-04-30 00:00:00.000|
            56|LL Road Handlebars         |                  |            |a7e65199-84a8-437e-ad55-360c1df1d788|2012-04-30 00:00:00.000|
            57|ML Road Handlebars         |                  |            |02200aa0-c369-4d77-a67c-75973efda81b|2012-04-30 00:00:00.000|
            58|HL Road Handlebars         |                  |            |2489ddc5-1c89-4dec-af22-b0112ccec467|2012-04-30 00:00:00.000|
            59|LL Headset                 |                  |            |39afbba9-0f6c-44ee-b5e1-32fa93f897e6|2012-04-30 00:00:00.000|
            60|ML Headset                 |                  |            |6ba9f3b6-e08b-4ac2-a725-b41114c2a283|2012-04-30 00:00:00.000|
            61|HL Headset                 |                  |            |e196d02e-9bf6-4c67-b772-ed9f86ccf44c|2012-04-30 00:00:00.000|
            62|LL Mountain Pedal          |                  |            |8123f7e2-a5f4-4047-b69d-e74313dfebce|2013-04-30 00:00:00.000|
            63|ML Mountain Pedal          |                  |            |be9cdc56-f4ab-40f1-b338-2e08e0627abd|2013-04-30 00:00:00.000|
            64|HL Mountain Pedal          |                  |            |8da73708-8dae-44ae-ac6c-6e37022c1ffe|2013-04-30 00:00:00.000|
            65|ML Touring Seat/Saddle     |                  |            |63a2199f-f5b5-49bd-bcfc-bec1d1d16d8b|2013-04-30 00:00:00.000|
            66|LL Touring Seat/Saddle     |                  |[XML]       |4a17c43a-1a55-41bb-bc97-612f47cedeb3|2015-04-15 16:34:29.043|
            67|HL Touring Seat/Saddle     |                  |[XML]       |059a2000-7549-4b49-8e0c-2de6b2771ef4|2015-04-15 16:34:29.043|
            68|LL Road Pedal              |                  |            |218b016c-7454-4193-b518-21955c783d72|2013-04-30 00:00:00.000|
            69|ML Road Pedal              |                  |            |3cdf61d6-6209-436f-b235-82e8f159208b|2013-04-30 00:00:00.000|
            70|HL Road Pedal              |                  |            |35677b42-72ca-4d9e-a966-dd874b83ef45|2013-04-30 00:00:00.000|
            71|LL Mountain Seat/Saddle 1  |                  |            |a166af4c-87bb-41aa-8496-d76b26008fb3|2013-04-30 00:00:00.000|
            72|ML Mountain Seat/Saddle 1  |                  |            |baa9405b-68ca-4c18-bc9c-1c4acf49bafc|2013-04-30 00:00:00.000|
            73|HL Mountain Seat/Saddle 1  |                  |            |bbe4918f-198d-43c7-9f4b-79bc2aa08f2b|2013-04-30 00:00:00.000|
            74|LL Road Seat/Saddle 2      |                  |            |24e3e7d4-4053-4035-9d69-f451642f0c1e|2013-04-30 00:00:00.000|
            75|ML Road Seat/Saddle 1      |                  |            |394ed69c-2cc4-4a85-9080-8534112b66fe|2013-04-30 00:00:00.000|
            76|HL Road Seat/Saddle 1      |                  |            |b83ab7ae-ba3f-40df-8296-361915a3a60c|2013-04-30 00:00:00.000|
            77|ML Road Rear Wheel         |                  |            |15702f98-bd92-4fe8-86bc-52f5fd049d3d|2012-04-30 00:00:00.000|
            78|HL Road Rear Wheel         |                  |            |438cbcfa-05ff-4a29-ad95-ecf41dcb83d5|2012-04-30 00:00:00.000|
            79|LL Mountain Seat/Saddle 2  |                  |            |8bbeb399-5a87-4e40-9f52-462fb54f2183|2013-04-30 00:00:00.000|
            80|ML Mountain Seat/Saddle 2  |                  |            |5cefbb6e-3b7e-414f-ac1b-8f6df741fb21|2013-04-30 00:00:00.000|
            81|HL Mountain Seat/Saddle 2  |                  |            |98726f80-e9b9-4141-9cf5-bd2ef07dce25|2013-04-30 00:00:00.000|
            82|LL Road Seat/Saddle 1      |                  |            |00ce9171-8944-4d49-ba37-485c1d122f5c|2013-04-30 00:00:00.000|
            83|ML Road Seat/Saddle 2      |                  |            |feeb8440-446e-4df8-9482-d529c4fc5e8f|2013-04-30 00:00:00.000|
            84|HL Road Seat/Saddle 2      |                  |            |0d3a6ad7-6891-4de9-b14f-e1a841eb220c|2013-04-30 00:00:00.000|
            85|LL Mountain Tire           |                  |            |e3cdc5dd-27c3-4891-9d5e-0d46d1b8457f|2013-04-30 00:00:00.000|
            86|ML Mountain Tire           |                  |            |0434f63a-a361-4d0b-a9fc-8ac2a866ce85|2013-04-30 00:00:00.000|
            87|HL Mountain Tire           |                  |            |ce1b1064-6679-4212-8f56-2b2617ec56a5|2013-04-30 00:00:00.000|
            88|LL Road Tire               |                  |            |e7b00dff-8136-4947-b503-994584cc89e7|2013-04-30 00:00:00.000|
            89|ML Road Tire               |                  |            |d566eb0f-6945-43d8-bc40-bb3d2f4ef7ed|2013-04-30 00:00:00.000|
            90|HL Road Tire               |                  |            |a4b205df-955a-494e-8428-1898aea76f24|2013-04-30 00:00:00.000|
            91|Touring Tire               |                  |            |3bcc63d6-9340-4b93-b5f2-73fa90758bf5|2013-04-30 00:00:00.000|
            92|Mountain Tire Tube         |                  |            |8cfbe7f2-eec3-4ba6-8187-c8a3614f1f0b|2013-04-30 00:00:00.000|
            93|Road Tire Tube             |                  |            |2771d2d2-2e35-4c12-966e-ce9070df6d53|2013-04-30 00:00:00.000|
            94|Touring Tire Tube          |                  |            |deeea9bc-3c8c-4e73-b6b0-64c81a5d99e3|2013-04-30 00:00:00.000|
            95|LL Bottom Bracket          |                  |            |217e7475-d3f4-46fa-836a-d9e53103e71b|2013-04-30 00:00:00.000|
            96|ML Bottom Bracket          |                  |            |09caa74e-f47b-4fca-b206-9d3e46df9751|2013-04-30 00:00:00.000|
            97|HL Bottom Bracket          |                  |            |816360e1-3dee-4568-bf2f-9828243d887b|2013-04-30 00:00:00.000|
            98|Chain                      |                  |            |aca920b2-d0f9-49f3-b879-573202b08c2f|2013-04-30 00:00:00.000|
            99|LL Crankset                |                  |            |5b59f032-9b73-4d90-b252-eafd6a871ff1|2013-04-30 00:00:00.000|
           100|ML Crankset                |                  |            |68c6cb29-d94a-40c5-aaad-90aa6e7c5ea1|2013-04-30 00:00:00.000|
           101|HL Crankset                |                  |            |809668a3-d492-41fb-a196-cfe092a12aa2|2013-04-30 00:00:00.000|
           102|Front Brakes               |                  |            |1099a23a-c9ed-41b1-8cc1-e2c1c54a10c8|2013-04-30 00:00:00.000|
           103|Front Derailleur           |                  |            |10e0c8fd-ca13-437b-8e22-51853ae160a7|2013-04-30 00:00:00.000|
           104|LL Fork                    |                  |            |0481d7e1-4970-4efa-a560-020f6579918d|2012-04-30 00:00:00.000|
           105|ML Fork                    |                  |            |5f115aa4-0553-4478-84b3-5dcf3abe0d08|2012-04-30 00:00:00.000|
           106|HL Fork                    |                  |            |7706a8fd-9513-40bc-95e8-301b55b67db2|2012-04-30 00:00:00.000|
           107|Hydration Pack             |                  |            |cfeef30f-f059-4447-92a8-47001e69f3db|2013-04-30 00:00:00.000|
           108|Taillight                  |                  |            |dba643d4-4cf2-4507-b947-e817d8c5792b|2012-04-30 00:00:00.000|
           109|Headlights - Dual-Beam     |                  |            |7b17ebf1-cb73-4934-9689-1dc26cf22d9c|2012-04-30 00:00:00.000|
           110|Headlights - Weatherproof  |                  |            |1fadb88f-af88-4e94-bb1e-6158c48e6b40|2012-04-30 00:00:00.000|
           111|Water Bottle               |                  |            |3688268a-260c-48bf-bf71-fff350d4d3d5|2013-04-30 00:00:00.000|
           112|Mountain Bottle Cage       |                  |            |2194e65b-9c13-46e1-a655-3ebff8a96719|2013-04-30 00:00:00.000|
           113|Road Bottle Cage           |                  |            |9416c2dd-55d8-469d-8edf-ef447c511897|2013-04-30 00:00:00.000|
           114|Patch kit                  |                  |            |7c738101-c01e-45a2-a0e0-b28aeba1dc40|2013-04-30 00:00:00.000|
           115|Cable Lock                 |                  |            |e7e17f11-a7fd-4c3c-b701-68f0ae26143e|2012-04-30 00:00:00.000|
           116|Minipump                   |                  |            |90cef1a7-d817-403e-814c-40e305eeefef|2012-04-30 00:00:00.000|
           117|Mountain Pump              |                  |            |b35598f6-b413-4138-8081-5dc7d4c64b64|2012-04-30 00:00:00.000|
           118|Hitch Rack - 4-Bike        |                  |            |f570e0d1-e978-4ff2-b5b1-08f01ab60219|2013-04-30 00:00:00.000|
           119|Bike Wash                  |                  |            |90b1b93d-ebc8-44a2-ac08-cdd1d20ca39c|2013-04-30 00:00:00.000|
           120|Touring-Panniers           |                  |            |f06999a1-3aa7-4e85-b8cb-049eb2c391fa|2012-04-30 00:00:00.000|
           121|Fender Set - Mountain      |                  |            |c88d1136-a8bb-46bb-94aa-8c1854f813cc|2013-04-30 00:00:00.000|
           122|All-Purpose Bike Stand     |                  |            |6eab8607-d927-40e1-af30-d8a2a953050c|2013-04-30 00:00:00.000|
           123|LL Mountain Rear Wheel     |                  |            |29521f66-2926-471f-867b-668b0b9ec2b0|2012-04-30 00:00:00.000|
           124|ML Mountain Rear Wheel     |                  |            |d968d774-778e-4399-a3c5-375176418229|2012-04-30 00:00:00.000|
           125|HL Mountain Rear Wheel     |                  |            |95450545-adf7-48f3-899e-964de8920dc6|2012-04-30 00:00:00.000|
           126|LL Road Rear Wheel         |                  |            |95946bd4-c6d9-4344-8066-317d8957ea21|2012-04-30 00:00:00.000|
           127|Rear Derailleur            |                  |            |f9327e5d-f8b6-40c5-bfa9-63f886bdfc24|2013-04-30 00:00:00.000|
           128|Rear Brakes                |                  |            |71d47afd-da3a-43f1-83ad-69c71f96ef33|2013-04-30 00:00:00.000|

Click to view Full table

Sample Output:

productmodelid|name                       |
--------------+---------------------------+
           122|All-Purpose Bike Stand     |
           119|Bike Wash                  |
           115|Cable Lock                 |
            98|Chain                      |
             1|Classic Vest               |
             2|Cycling Cap                |
           121|Fender Set - Mountain      |
           102|Front Brakes               |
           103|Front Derailleur           |
             3|Full-Finger Gloves         |
             4|Half-Finger Gloves         |
...

Click me to see the solution

 

More to Come !

SQL AdventureWorks Editor:

Practice Online


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/adventureworks/adventureworks-exercises1.php