Hi, I got an sql situation I have data like this:
select * from data;
DATA_HASH OPT_HASH TOTAL_QUERYS
228AB820 00000000 1
228AB820 00000000 1
0A8C0D24 97B17E23 1
0A8C0D24 97B17E23 1
0A8C0D24 97B17E23 1
0A8C0D24 97B17E23 1
0A8C0D24 97B17E23 1
38BA6FA6 97B17E23 1
38BA6FA6 97B17E23 1
38BA6FA6 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
FD852A75 97B17E23 1
0A8C0D24 D8F0E8E4 1
23 record(s) selected.
Now what I need to do is to group the data and count the number of occourences where data_hash and options_hash occour.
That is done by this statement:
select data_hash,opt_hash,SUM(total_querys) as total FROM data GROUP BY opt_hash,data_hash ORDER BY total DESC
DATA_HASH OPT_HASH TOTAL
FD852A75 97B17E23 12
0A8C0D24 97B17E23 5
38BA6FA6 97B17E23 3
228AB820 00000000 2
0A8C0D24 D8F0E8E4 1
5 record(s) selected.
Now here is the problem I only want the highest occource of OPT_HASH per DATA_HASH so the output I want would be
DATA_HASH OPT_HASH TOTAL
FD852A75 97B17E23 12
0A8C0D24 97B17E23 5
38BA6FA6 97B17E23 3
228AB820 00000000 2
Now you say well do it in php, well the problem is this is a subselect query so I need to get it to return the correct results.
Any help is greatly appreciated!!!