Question: A query of the table information for table Supplier returns the following information: cid name type notnull dflt_value pk 0 Id INTEGER 0 None 1

A query of the table information for table Supplier returns the following information:

cid name type notnull dflt_value pk
0 Id INTEGER 0 None 1
1 CompanyName TEXT 1 None 0
2 ContactName TEXT 0 None 0
3 ContactTitle TEXT 0 None 0
4 City TEXT 0 None 0
5 Country TEXT 0 None 0
6 Phone TEXT 0 None 0
7 Fax TEXT 0 None 0

A query of the table information for table Customer returns the following information:

cid name type notnull dflt_value pk
0 Id INTEGER 0 None 1
1 FirstName TEXT 1 None 0
2 LastName TEXT 1 None 0
3 City TEXT 0 None 0
4 Country TEXT 0 None 0
5 Phone TEXT 0 None 0

A query of the table information for table Product returns the following information:

cid name type notnull dflt_value pk
0 Id INTEGER 0 None 1
1 ProductName TEXT 1 None 0
2 SupplierId INTEGER 1 None 0
3 UnitPrice REAL 1 0 0
4 Package TEXT 0 None 0
5 IsDiscontinued INTEGER 1 0 0

A query of the table information for table Order returns the following information:

cid name type notnull dflt_value pk
0 Id INTEGER 0 None 1
1 OrderDate TEXT 1 None 0
2 OrderNumber TEXT 0 None 0
3 CustomerId INTEGER 1 None 0
4 TotalAmount REAL 0 0 0

A query of the table information for table OrderItem returns the following information:

cid name type notnull dflt_value pk
0 Id INTEGER 0 None 1
1 OrderId INTEGER 1 None 0
2 ProductId INTEGER 1 None 0
3 UnitPrice REAL 1 0 0
4 Quantity INTEGER 1 1 0

Your Task

List the LastName, FirstName, and the total number of orders placed by each customer (as OrderCount) for all customers.

Sort your results so that the customer with the highest number of orders appear at the top. If two customers have the same number of orders they should be listed in alphabetical order or lastname and then firstname.

Note: This question requires you to write SQL syntax ONLY. Absolutely no python code should be used. Only the SQL itself.

For example:

Result
LastName FirstName OrderCount ---------- ---------- ---------- Pavarotti Jose 31 Mendel Roland 30 Kloss Horst 28 Larsson Maria 19 McKenna Patricia 19 Berglund Christina 18 Hernndez Carlos 18 Wilson Paula 18 Lebihan Laurence 17 Franken Peter 15 Koskitalo Pirkko 15 Messner Renate 15 Cramer Philip 14 Gonzlez Carlos 14 Jablonski Karl 14 Lincoln Elizabeth 14 Pontes Mario 14 Roulet Annette 14 Carvalho Lcia 13 Fresnire Jean 13 Hardy Thomas 13 Cartrain Pascale 12 Izquierdo Felipe 12 Moroni Maurizio 12 Citeaux Frdrique 11 Ibsen Palle 11 Limeira Janete 11 Snyder Howard 11 Angel Paol Miguel 10 Ashworth Victoria 10 Bennett Helen 10 Holz Michael 10 Mller Rita 10 Pedro Frey Jos 10 Pfalzheim Henriette 10 Phillips Rene 10 Pipps Georg 10 Rovelli Giovanni 10 Saveley Mary 10 Batista Bernardo 9 Braunschwe Art 9 Fonseca Andr 9 Kumar Hari 9 Parente Paula 9 Devon Ann 8 Rodriguez Lino 8 Wang Yang 8 Wilson Fran 8 Cruz Aria 7 Dewey Catherine 7 Karttunen Matti 7 Moos Hanna 7 Moreno Antonio 7 Petersen Jytte 7 Piestrzeni Zbyszek 7 Accorti Paolo 6 Anders Maria 6 Bergulfsen Jonas 6 Domingues Anabela 6 Fernndez Guillermo 6 Josephs Karin 6 Ottlieb Sven 6 Simpson Patricio 6 Afonso Pedro 5 Camino Alejandra 5 Feuer Alexander 5 Gutirrez Sergio 5 Henriot Paul 5 Latimer Yoshi 5 Moncada Yvonne 5 Ranc Martine 5 Saavedra Eduardo 5 de Castro Isabel 5 Labrune Janine 4 Nixon Liz 4 Perrier Dominique 4 Tonini Daniel 4 Trujillo Ana 4 Yorres Jaime 4 Brown Elizabeth 3 Crowther Simon 3 Nagy Helvetius 3 Schmitt Carine 3 Sommer Martn 3 Tannamuri Yoshi 3 Wong Liu 3 Pereira Manuel 2 Steel John 2 Chang Francisco 1 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!