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

x
?
Solved

Count, GroupBy and where SQL Statement, without GroupBy

Posted on 2007-03-28
7
Medium Priority
?
332 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 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

618 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