sql query help using distinct and count()
I have a table containing firewall logs. I'm trying to form a query which will give me a descending report of all connections for past X number of days.
This is the query I have so far:
select distinct ip_saddr,oob_time_sec,count(*) as cnt
from ulog
where (oob_prefix like '%INPUT%' and oob_time_sec >= '$phpdays')
group by ip_saddr
order by cnt desc;
table
-----------------------------------------------------------------
ip_saddr = ip address
oob_time_sec = time since unix epoch in seconds
ulog = database table
oob_prefix = string from firewall entry (INPUT_x/OUTPUT_x traffic)
Would like to know if this query looks sane (I'm an Admin wearing a progra开发者_运维知识库mmer hat, so not too sure).
Thanks!
In my view your Query is right and Proper.
Looks fine to me but I think the LIKE
should be like
oob_prefix like 'INPUT%'
since oob_prefix
has INPUT_x
精彩评论