?
Solved

Counting the product delivery

Posted on 2011-03-10
2
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
tigin44 earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

765 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