Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Counting the product delivery

Posted on 2011-03-10
2
Medium Priority
?
227 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

610 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