innitboy Posted January 20, 2007 Share Posted January 20, 2007 I have 3 columns of data 500 -- 150 -- 54500 -- 150 -- 32500 -- 148 -- 75500 -- 132 -- 98I would like it to display this1. 500 - 430The sum of the unique rows in 2nd column (150 + 148 + 132 = 430)Should I be looking to make 3 different tables from this data and join them or can i get the sum of the 2nd column filtered by the first column in this same table,Here is some code but its not workingThanks in advance for any help :)[code]$query = "SELECT id, 1stlevelkey, FROM keywords where 1stlevelkey = '".$stlevelkey."' group by 1stlevelkey "; $result = mysql_query($query);while ($row = mysql_fetch_assoc($result)) { $query = "SELECT id, 1stlevelkey, sum(2ndlevel) / count(2ndlevel) as count2ndFROM keywords where 1stlevelkey = '".$firstlevelkey."' group by 1stlevelkey "; $result = mysql_query($query);while ($row = mysql_fetch_assoc($result)) {print_r($row['1stlevelkey']);echo "-";print_r($row['count2nd']);echo "<br>"; }} [/code] Quote Link to comment Share on other sites More sharing options...
innitboy Posted January 20, 2007 Author Share Posted January 20, 2007 I can get it to return the list grouped by the 2nd column with the code belowlike this500 - 150500 -- 148500 -- 132however i cannot get it to do this500 - 430[code]$query = "SELECT id, 1stlevelkey, sum(distinct 2ndlevel) / count(distinct 2ndlevel) as count2nd FROM keywords group by 2ndlevelkey "; $result = mysql_query($query);while ($row = mysql_fetch_assoc($result)) {print_r($row['1stlevelkey']);echo "-";print_r($row['count2nd']);echo "<br>"; } [/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.