Unix Technical Forum

Query problem

This is a discussion on Query problem within the MySQL General forum forums, part of the MySQL category; --> Hi all, Iam having the one table name called AccessDetails and data inside that tables is following, Date Time ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 04:08 PM
sivasakthi
 
Posts: n/a
Default Query problem

Hi all,

Iam having the one table name called AccessDetails and data inside that
tables is following,

Date Time UserName SiteName
ScanType Status Virus_Category

| 2008-04-16 | 13:05:31 | 172.16.1.22 | - | www.veer.com
|C | A | unclassified |
| 2008-04-16 | 13:05:31 | 172.16.1.52 | - | blogactiv.eu
|C | O | unclassified |
| 2008-04-16 | 13:05:32 | 172.16.1.22 | - | www.veer.com
|V | A | Internet |
| 2008-04-16 | 13:05:32 | 172.16.1.52 | - |
www.verylowsodium.com |C | D | unclassified |
| 2008-04-16 | 13:05:32 | 172.16.1.52 | - | blogactiv.eu
|V | A | unclassified |


In that , I need to calculate the number of total sites , number of
total Accessed Sites,number of total Denied Sites and number of total
Overriden Sites based on the particular Virus_Category,UserName,Date


How can form the query to achieve that??

I have used the following query but the total site is not correctly
displayed..


select
count(a.UserName),sum(b.totalsites),sum(a.Allow),s um(a.Denied),sum(a.Over),sum(b.totalconn) from (select a.UserName,sum(a.Allow) as Allow,sum(a.Denied) as Denied,sum(a.Over) as Over from (select UserName,case Status when 'A' then count(distinct SiteName) else 0 END as Allow ,case Status when 'D' then count(distinct SiteName) else 0 END as Denied,case Status when 'O' then count(distinct SiteName) else 0 END as Over from AccessDetails where Virus_category = 'unclassified ' and Date<='2008-04-16' and Date>='2008-04-16' and ScanType='C' group by UserName, Status) a group by a.UserName) a left join (select UserName,count(distinct SiteName)as totalsites, count(Time)as totalconn from AccessDetails where Virus_category = 'unclassified ' and Date<='2008-04-16' and Date>='2008-04-16' and ScanType='C' and Virus_category <> '-' and UserName <> '-' group by UserName)b on a.UserName=b.UserName where b.totalsites is not null



Thanks In Advance ,



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 04:09 PM
Daniel Brown
 
Posts: n/a
Default Re: Query problem

On Wed, Apr 16, 2008 at 4:35 AM, sivasakthi <msivasakthi@gmail.com> wrote:
> Hi all,
>
> Iam having the one table name called AccessDetails and data inside that
> tables is following,
>

[snip=schema]
>
> In that , I need to calculate the number of total sites , number of
> total Accessed Sites,number of total Denied Sites and number of total
> Overriden Sites based on the particular Virus_Category,UserName,Date
>
>
> How can form the query to achieve that??
>
> I have used the following query but the total site is not correctly
> displayed..


You may want to look into the ROLLUP modifier. Here's the manual entry:
http://dev.mysql.com/doc/refman/5.0/...modifiers.html

--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:31 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com