Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mailboxo71
Starting Member
3 Posts |
Posted - 2011-01-20 : 22:43:21
|
| Please help me, I can't find any proper tutorial that would properly help me on this.I have the following database structure, I need a SQL query to retrieve a list of the 5 most popular states that had orders.--------------------------------------------Orders ------ id date shipping_amount order_status customer_id (Customers.id) Customers----------idfirst_namelast_namecitystateThe output should look something like this:+-----------+------------+| State | # Orders |+-----------+------------+| NY | 55 || CA | 40 || NJ | 33 || FL | 21 || MO | 12 |+-----------+------------+ |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-01-20 : 22:45:44
|
| What have you tried so far?I'll give you two hints: (1) INNER JOIN (2) GROUP BYshow us what you have, and we'll help you straighten it out. |
 |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2011-01-20 : 22:47:03
|
you can't find any tutorial that explains how to do a join? a google of "query results from two tables" returns about 381,000 results, most of which on page 1 would show you how. Smells like a bit of homework, so here is a hint.CustomerID (From ORDERS) = ID (from CUSTOMERS) Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
mailboxo71
Starting Member
3 Posts |
Posted - 2011-01-21 : 00:20:48
|
| Sorry, I am stumped.Anyone who can help me compose this, I really appreciate it. |
 |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-21 : 00:37:48
|
| if that really a home work then you should try at least your self... Make any thing even its wrong and post it here we'll step wise guide you :Dby the way if you know little about select statement. so you can get your work done via above hints !!! :D |
 |
|
|
mailboxo71
Starting Member
3 Posts |
Posted - 2011-01-21 : 10:45:08
|
| if u can supply some really relevant tutorials then pls give link.Ask this forum is like talkin to a brick |
 |
|
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2011-01-21 : 12:45:43
|
quote: Originally posted by mailboxo71 Ask this forum is like talkin to a brick
I suggest you not be rude when you're asking people to help you. Rudeness makes them want to leave you alone to suffer. |
 |
|
|
|
|
|