Solved

Counting the product delivery

Posted on 2011-03-10
2
221 Views
Last Modified: 2012-05-11
Hi, I have two tables namely tblProduct and tblDelivery with the following definition:

tblProduct - pid,pdesc
tblDelivery - pid,date,time,location

where the keys are bold.

Now I want to construct a sql statement to display pid,pdesc,totalNumberOfDeliveryBasedOnDate sorted by pid, date

Please advice me on how to construct this sql statement.
0
Comment
Question by:bpyeo
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 500 total points
ID: 35093611
SELECT P.pid, P.pdesc, total AS totalNumberOfDelivery
FROM tblProduct P
   INNER JOIN (      SELECT X.pid, X.[date], COUNT(*) as total
                        FROM tblDelivery X
                        GROUP BY X.pid, X.[date])  D ON P.pid = D.pid

ORDER BY P.pid, D.[date]
0
 
LVL 5

Expert Comment

by:mayankagarwal
ID: 35093641
select a.pid, a.desc, count(b.pid), b.date from tblProduct a, tblDelivery  b where a.pid = b.pid group by b.date
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now