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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 List of Query

Author  Topic 

WoodHouse
Posting Yak Master

211 Posts

Posted - 2010-05-11 : 08:53:55
Orders Table

Order_Day Prod_Id Customer_ID Qty_Sold
1/5/2010 P1 C1 10
10/5/2010 P2 C2 30
1/4/2010 P2 C1 20
10/4/2010 P1 C2 40
1/3/2010 P2 C1 30
10/3/2010 P1 C2 20

Customer Table
CustID City
C1 Chennai
C2 Delhi


a) Write a SQL query to get Total Quantity Sold by Month. The output should have two columns - Month and Total Quantity Sold.

b) Write a SQL query to get Total Quantity Sold by City. The output should have two columns – City Name and Total Quantity Sold.

c) Assuming the above Order tables have more than 100 distinct Prod_ids transaction, write a Sql to get Top 10 Distinct Product_ids by Quantity_sold. Don’t use any function, write the Sql to get the results. The output should have two columns Product_Id and Quantity_Sold.

d) Get me all the products that were ordered by customer C1 on 10/4/2010 AND 10/3/2010. The result should include ONLY those products that were ordered by C1 on BOTH the days.


Please help me the best answers for above questions.


Thanks a Lot

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-11 : 08:55:50
What have you tried so far?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

WoodHouse
Posting Yak Master

211 Posts

Posted - 2010-05-11 : 09:00:00
Hi Madhi

I am trying But I expect best method from experts so for that i will learn what i have done wrong things..

I hope you help me

Thanks a Lot
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-05-11 : 09:13:00
Your questions sound like homework / test questions.

At least make a stab at the questions and then you'll get feedback about what you are doing and why it's right or wrong.

You won't learn anything if you don't try.

A Hint to get you started.

a) GROUP BY and SUM -- I leave extracting the MONTH portion of the date to you

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2010-05-11 : 10:20:45
quote:
Originally posted by Transact Charlie

Your questions sound like homework / test questions.



Ding, ding, ding - give the man a cigar! Finals time is upon us once again. I suspect there will be a lot of this for a while. As both Madhi and TC stated, what have YOU tried?

Terry

-- A word to the wise ain't necessary - it's the stupid ones that need the advice. -- Bill Cosby
Go to Top of Page
   

- Advertisement -