2011-07-12 108 views
0

我有一個包含防火牆日誌的表。我試圖形成一個查詢,它會給我一個過去X天的所有連接的遞減報告。sql查詢幫助使用distinct和count()

這是查詢我到目前爲止:

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) 

想知道,如果這個查詢看起來理智(我戴着帽子程序員以管理員,所以也不太清楚)。

謝謝!

回答

1

在我看來,你的查詢是正確的和適當的。

+0

大,感謝您抽空回覆的時間。 – wufoo

1

看起來好像沒什麼問題,但我認爲LIKE應該像

oob_prefix like 'INPUT%' 

因爲oob_prefixINPUT_x

+0

啊,是的。優秀的捕獲。謝謝。 – wufoo