By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Grouping mysql result as per arrey

P: 1
i am using one database in mysql in which it is having a record of source IP(sip), destination IP(dip), source port(sport), destination Port(dport). when doing select query
(select count(sport) as port, sport from IPtable limit 20); the result is as this query states means port sport
3 | 80
5 | 8080
15 | 21
3 | 20
25 | 443
16 | 1234
49 | 2352
15 | 2353

i want to group these ports like

web (80, 8080, 443)
ftp (20, 21)
chat (2352, 2353)
others("rest other ports")

and want output result as

count | port

================

33 | web

18 | ftp

16 | application

64 | others

please help because i want to create pi chart from this output
Feb 23 '15 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,359
First of all, your original SQL shouldn't have run, it's missing a group by clause.

Create a table that lists the port number with it's classification. Join that to your table on the port number and use the classification instead of the port number.
Feb 23 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.