POV-Ray : Newsgroups : povray.off-topic : Another stupid SQL query problem Server Time
4 Nov 2024 17:38:01 EST (-0500)
  Another stupid SQL query problem (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Halbert
Subject: Another stupid SQL query problem
Date: 21 Apr 2008 16:38:53
Message: <480cfb5d$1@news.povray.org>
If we have any SQL gurus out there (not mentioning any names, Gail :-) I 
have a simple problem I with undoubtedly a simple answer.
I have a log table:

Log_time | IP | Script_Name| Email | DK

I need to select based on the criteria Log_time between two dates, script 
name =  '/EN/travelsync/content/getthere.asp', and DK = 'TEST'
So far we get:

SELECT Log_time, IP, Script_Name, Email, DK
FROM uselog
WHERE
Log_time >  '2008-01-31' and Log_time < '2008-03-01' and Script_Name = 
'/EN/travelsync/content/getthere.asp' and DK = 'TEST'


I need to add a field indicating the number of times an email address occurs 
and not return multiple records for the same email address.

That's hard to explain, but hopefully I managed to do it.
If anyone here knows what I must do please let me know. Thanks!

--


Post a reply to this message

From: Gail Shaw
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 16:58:27
Message: <480cfff3@news.povray.org>
"Halbert" <hal### [at] gmailcom> wrote in message
news:480cfb5d$1@news.povray.org...
> If we have any SQL gurus out there (not mentioning any names, Gail :-)

Hmmm, am I hearing things?

> I
> have a simple problem I with undoubtedly a simple answer.
> I have a log table:
>
> Log_time | IP | Script_Name| Email | DK

Ok. Think I understand. It's a little complex, but not really difficult.
Do need some things clarifying.

Say you have 3 rows with the same Email, different IP, different Log time
and different script. (is that possible?)
What log time, IP, script do you want returning? The ones that match the
latest log-time? Oldest log time? Any one, doesn't matter?

Oh, what DB engine? Oracle, My SQL, SQL Server, other? What version?

If no one's helped by morning, I'll take a look, but it's 11pm here...


Post a reply to this message

From: Halbert
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 17:04:05
Message: <480d0145$1@news.povray.org>
The script name will not be a variable. But the email could come from 
different IPs at different times. They want to have counts for the number of 
times individuals used the getthere.asp script.
We are using MS SQL Server (2000 in this case)
Thanks again.


s
"Gail Shaw" <initialsurname@sentech sa dot com> wrote in message 
news:480cfff3@news.povray.org...
>
> "Halbert" <hal### [at] gmailcom> wrote in message
> news:480cfb5d$1@news.povray.org...
>> If we have any SQL gurus out there (not mentioning any names, Gail :-)
>
> Hmmm, am I hearing things?
>
>> I
>> have a simple problem I with undoubtedly a simple answer.
>> I have a log table:
>>
>> Log_time | IP | Script_Name| Email | DK
>
> Ok. Think I understand. It's a little complex, but not really difficult.
> Do need some things clarifying.
>
> Say you have 3 rows with the same Email, different IP, different Log time
> and different script. (is that possible?)
> What log time, IP, script do you want returning? The ones that match the
> latest log-time? Oldest log time? Any one, doesn't matter?
>
> Oh, what DB engine? Oracle, My SQL, SQL Server, other? What version?
>
> If no one's helped by morning, I'll take a look, but it's 11pm here...
>
>


Post a reply to this message

From: Gail Shaw
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 17:10:09
Message: <480d02b1@news.povray.org>
"Halbert" <hal### [at] gmailcom> wrote in message
news:480d0145$1@news.povray.org...
> The script name will not be a variable. But the email could come from
> different IPs at different times. They want to have counts for the number
of
> times individuals used the getthere.asp script.
> We are using MS SQL Server (2000 in this case)
> Thanks again.
>

Ok, so say this is the input (as a comma-seperated list). What do you want
as results?

Logtime, IP, Email
2008/01/01 10:15, 10.2.45.56, me@here
2008/01/01 10:25, 10.2.45.56, me@here
2008/01/01 16:15, 10.2.78.156, me@here
2008/01/02 12:15, 10.2.15.74, me@here
2008/01/02 12:15, 10.2.15.74, me@here
2008/01/02 12:17, 10.2.15.74, me@here
2008/01/02 12:19, 10.2.15.74, me@here
2008/01/01 12:15, 10.5.25.34, you@somewhere
2008/01/01 13:15, 10.5.25.34, you@somewhere
2008/01/01 14:15, 10.5.25.34, you@somewhere
2008/01/01 18:15, 10.5.25.38, you@somewhere


Post a reply to this message

From: Halbert
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 17:18:35
Message: <480d04ab$1@news.povray.org>
> Logtime, IP, Email
> 2008/01/01 10:15, 10.2.45.56, me@here
> 2008/01/01 10:25, 10.2.45.56, me@here
> 2008/01/01 16:15, 10.2.78.156, me@here
> 2008/01/02 12:15, 10.2.15.74, me@here
> 2008/01/02 12:15, 10.2.15.74, me@here
> 2008/01/02 12:17, 10.2.15.74, me@here
> 2008/01/02 12:19, 10.2.15.74, me@here
> 2008/01/01 12:15, 10.5.25.34, you@somewhere
> 2008/01/01 13:15, 10.5.25.34, you@somewhere
> 2008/01/01 14:15, 10.5.25.34, you@somewhere
> 2008/01/01 18:15, 10.5.25.38, you@somewhere
>

me@here,7
you@somewhere,4


Post a reply to this message

From: Darren New
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 17:30:19
Message: <480d076b$1@news.povray.org>
Halbert wrote:
>> Logtime, IP, Email
>> 2008/01/01 10:15, 10.2.45.56, me@here
>> 2008/01/01 10:25, 10.2.45.56, me@here
>> 2008/01/01 16:15, 10.2.78.156, me@here
>> 2008/01/02 12:15, 10.2.15.74, me@here
>> 2008/01/02 12:15, 10.2.15.74, me@here
>> 2008/01/02 12:17, 10.2.15.74, me@here
>> 2008/01/02 12:19, 10.2.15.74, me@here
>> 2008/01/01 12:15, 10.5.25.34, you@somewhere
>> 2008/01/01 13:15, 10.5.25.34, you@somewhere
>> 2008/01/01 14:15, 10.5.25.34, you@somewhere
>> 2008/01/01 18:15, 10.5.25.38, you@somewhere
>>
> 
> me@here,7
> you@somewhere,4

That's easy, then.

select email, count(*) from logtable where '2008-...' < logtime and 
logtime < '2008...' group by email

The "group by" (and possibly "with rollup" and "having" clauses) is what 
you need to read up on.

If you need one of the IP addresses or other columns to come back, it's 
harder.
-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

From: Halbert
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 17:34:51
Message: <480d087b$1@news.povray.org>
> That's easy, then.
>
> select email, count(*) from logtable where '2008-...' < logtime and 
> logtime < '2008...' group by email
>
> The "group by" (and possibly "with rollup" and "having" clauses) is what 
> you need to read up on.
>
> If you need one of the IP addresses or other columns to come back, it's 
> harder.


In reality, I need to select based on DK (a company identifier,)the script 
name and the date range but I think that it would be sufficient to return 
with only the email and the count.


Post a reply to this message

From: Darren New
Subject: Re: Another stupid SQL query problem
Date: 21 Apr 2008 20:03:05
Message: <480d2b39$1@news.povray.org>
Halbert wrote:
>> That's easy, then.
>>
>> select email, count(*) from logtable where '2008-...' < logtime and 
>> logtime < '2008...' group by email
>>
>> The "group by" (and possibly "with rollup" and "having" clauses) is what 
>> you need to read up on.
>>
>> If you need one of the IP addresses or other columns to come back, it's 
>> harder.
> 
> 
> In reality, I need to select based on DK (a company identifier,)the script 
> name and the date range but I think that it would be sufficient to return 
> with only the email and the count. 

The "group by" lets you select on anything. (I.e., the "where" clause 
can refer to any column, including joins with other tables etc.)  But 
everything you *return* has to either be mentioned in the "group by" 
clause or has to be a summary function (like count(), sum(), avg(), 
etc).  (I forget what those kinds of functions are called in SQL, but...)

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

From: Gail Shaw
Subject: Re: Another stupid SQL query problem
Date: 22 Apr 2008 00:38:41
Message: <480d6bd1@news.povray.org>
"Halbert" <hal### [at] gmailcom> wrote in message
news:480d087b$1@news.povray.org...
> > That's easy, then.
> >
> > select email, count(*) from logtable where '2008-...' < logtime and
> > logtime < '2008...' group by email
> >
> > The "group by" (and possibly "with rollup" and "having" clauses) is what
> > you need to read up on.
> >
> > If you need one of the IP addresses or other columns to come back, it's
> > harder.
>
> In reality, I need to select based on DK (a company identifier,)the script
> name and the date range but I think that it would be sufficient to return
> with only the email and the count.

Still very simple.

SELECT Email, Count(*)
FROM uselog
WHERE
Log_time >  '2008-01-31' and Log_time < '2008-03-01' and Script_Name =
'/EN/travelsync/content/getthere.asp' and DK = 'TEST'
group by Email


Post a reply to this message

From: Gail Shaw
Subject: Re: Another stupid SQL query problem
Date: 22 Apr 2008 00:39:07
Message: <480d6beb@news.povray.org>
"Darren New" <dne### [at] sanrrcom> wrote in message
news:480d2b39$1@news.povray.org...

> The "group by" lets you select on anything. (I.e., the "where" clause
> can refer to any column, including joins with other tables etc.)  But
> everything you *return* has to either be mentioned in the "group by"
> clause or has to be a summary function (like count(), sum(), avg(),
> etc).  (I forget what those kinds of functions are called in SQL, but...)

Aggregate.


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.