Solved

Count, GroupBy and where SQL Statement, without GroupBy

Posted on 2007-03-28
7
328 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
[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
  • 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 100 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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 400 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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 the fundamental information of how to create a table.

695 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