Solved

Counting the product delivery

Posted on 2011-03-10
2
222 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flattening heirachies 3 31
transaction in asp.net, sql server 6 33
SQL - Use results of SELECT DISTINCT in a JOIN 4 23
Proper Case SQL Command 2 13
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 the fundamental information of how to create a table.

821 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