Solved

need select with count

Posted on 2007-03-31
2
161 Views
Last Modified: 2010-08-05
I have a query:
Select Distinct email, quote, product, DATE From tblTest
that generates the following type of data...
a_s@company.org      102297      prod1            2/26/2007
a_k@company.org      60448      prod2      2/8/2007
a_k@company.org      72454      prod2      2/8/2007
a_k@company.org      133024      prod2      3/19/2007
a_k@company.org      133030      prod2      3/19/2007
a_k@company.org      134622      prod2      3/20/2007
a_k@company.org      134936      prod2      3/20/2007
a_k@company.org      134981      prod2      3/20/2007
a_l@company.org      987610      prod2      2/16/2007
a_l@company.org      84018      prod1            2/9/2007
a_l@company.org      85573      prod2      2/13/2007
A_T@company.org      32334      prod2      1/14/2007
A_T@company.org      88763      prod2      3/13/2007
A_T@company.org      123372      prod2      3/22/2007
a_c@company.org      62272      prod1            1/23/2007
a_c@company.org      84560      prod3      2/9/2007
a_c@company.org      100968      prod1            2/23/2007
a_c@company.org      135166      prod3      3/20/2007
A_L@company.org      105942      prod4      2/28/2007
a_j@company.org      37878      prod2      12/28/2006

How can I get the count of distinct quotes,product,date per email in the same table? I know how to get it in a different table with email and count...
but something like this:
a_s@company.org      102297      prod1            2/26/2007      1
a_k@company.org      60448      prod2      2/8/2007      7
a_k@company.org      72454      prod2      2/8/2007      7
a_k@company.org      133024      prod2      3/19/2007      7
a_k@company.org      133030      prod2      3/19/2007      7
a_k@company.org      134622      prod2      3/20/2007      7
a_k@company.org      134936      prod2      3/20/2007      7
a_k@company.org      134981      prod2      3/20/2007      7
a_l@company.org      987610      prod2      2/16/2007      3
a_l@company.org      84018      prod1            2/9/2007      3
a_l@company.org      85573      prod2      2/13/2007      3
A_T@company.org      32334      prod2      1/14/2007      3
A_T@company.org      88763      prod2      3/13/2007      3
A_T@company.org      123372      prod2      3/22/2007      3
a_c@company.org      62272      prod1            1/23/2007      4
a_c@company.org      84560      prod3      2/9/2007      4
a_c@company.org      100968      prod1           2/23/2007      4
a_c@company.org      135166      prod3      3/20/2007      4
A_L@company.org      105942      prod4      2/28/2007      1
a_j@company.org      37878      prod2      12/28/2006      1

Is it possible even?


0
Comment
Question by:acdagirl
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18829084
select t.*, ( select count(*) from tblTest i where i.email = t.email )
from tblTest t
0
 

Author Comment

by:acdagirl
ID: 18829121
I modified to to give me the fields of interest as my tblTest contains more fields, etc. that might skew the whole "distinct" thing I was looking for versus the t.* idea... I got what I needed. thanks!
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

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

21 Experts available now in Live!

Get 1:1 Help Now