[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Count, GroupBy and where SQL Statement, without GroupBy

Posted on 2007-03-28
7
Medium Priority
?
333 Views
Last Modified: 2012-06-21
Hi all

I am having trouble in writing a SQL statement.  Actually don't know if it is possible.

What I am trying to do is count a number of records but group by 1 record but also have a date from which to start counting.

So, Table 1 = UserDetails
StaffID (Numeric,Unique Identifyer), DateStarted (DateTime)

Table 2 = DataWritten
RecordNumber (Numeric, Inique Identifyer), DateEntered (DateTime)

Table 3 = RecordsRead
RecorNumber (Numeric, Unique Identifyer), StaffID (Numeric), DateRead (DateTime)

So now, I want to
Count = RecordsRead.RecordNumber
GroupBy = RecordsRead.StaffID
Where RecordsRead.DateRead = UserDetails.DateStarted (But not GroupBy DateRead).

As stated earlier, not sure, if it is possible, but would make live a lot easier.

I will be displaying this on a web page ASP Classic if this helps.

Baker
0
Comment
Question by:Bakersville
  • 3
  • 3
7 Comments
 
LVL 28

Expert Comment

by:imran_fast
ID: 18807733
you mean this


select count(RecordsRead.RecordNumber),RecordsRead.StaffID
from RecordsRead
inner join UserDetails
on RecordsRead.DateRead = UserDetails.DateStarted
group by RecordsRead.StaffID
0
 
LVL 28

Expert Comment

by:imran_fast
ID: 18807737
or this
select count(RecordsRead.RecordNumber),RecordsRead.StaffID
from RecordsRead
inner join UserDetails
on RecordsRead.DateRead = UserDetails.DateStarted
and UserDetails.StaffID=RecordsRead.StaffID
group by RecordsRead.StaffID
0
 
LVL 11

Assisted Solution

by:MacNuttin
MacNuttin earned 400 total points
ID: 18807760
is RecorNumber a typo?
What does this give you?

select DateStarted,dw.RecordNumber,DateEntered,count(rr.RecordNumber) as NumCount,rr.StaffID,DateRead FROM RecordsRead rr left join UserDetails ud  on ud.StaffID = rr.StaffID join DataWritten dw on dw.RecordNumber = rr.recordnumber
0
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!

 
LVL 1

Author Comment

by:Bakersville
ID: 18808300
Thank you both for your quick replies.  Yes RecorNumber is a typo.

I will give it a go and let you know how i get on.

Thank again
Baker
0
 
LVL 1

Author Comment

by:Bakersville
ID: 18809089
imran_fast, thanks again for this but on the Second option, it does count, but it counts the Records Read,RecordNumber not DataWritten.RecordNumber where > DataWritten.DateStarted.
I've tried to change it but my head hurts now.

MacNuttin, i've tried your but it comes up with a GroupBy clause error and once that fixed a where clause error.

Baker
0
 
LVL 28

Accepted Solution

by:
imran_fast earned 1600 total points
ID: 18828103
You mean this

select count(DataWritten.RecordNumber),UserDetails.StaffID
from DataWritten
inner join UserDetails
on DataWritten.DateStarted < UserDetails.DateStarted
group by UserDetails.StaffID
0
 
LVL 1

Author Comment

by:Bakersville
ID: 18835019
Thank you imran_fast, works perfectly.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

873 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