desjardins2010 Posted March 19, 2014 Share Posted March 19, 2014 I'm trying to structure this query properly but failing with all attempts. i have a table that has 5 fields id, http_referrer,ip,hit,today what I want to do is query this table to show me all the http_referrer's GROUPED up so only 1 row for ALL say 255 results that came from www.google.ca and the SUM'd hits so RFERRER HIT google.ca 255 phpfreaks.com 15 I tried SELECT SUM(hit) as 'hits' FROM `global_stats` GROUP BY `http_referrer` this don't work Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/ Share on other sites More sharing options...
Barand Posted March 19, 2014 Share Posted March 19, 2014 try SELECT http_referrer, SUM(hit) as 'hits' FROM `global_stats` GROUP BY `http_referrer` Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/#findComment-1473170 Share on other sites More sharing options...
desjardins2010 Posted March 19, 2014 Author Share Posted March 19, 2014 Ok this worked BUT one more question regarding this I notice that I get alot of sites that are the same CORE site but different appending ID's so they showing as different sites... is there an easy way to just match the www.something.com and leave our the ?asdfmsdmfs just curious no biggy I can handle if not Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/#findComment-1473174 Share on other sites More sharing options...
Psycho Posted March 19, 2014 Share Posted March 19, 2014 Ok this worked BUT one more question regarding this I notice that I get alot of sites that are the same CORE site but different appending ID's so they showing as different sites... is there an easy way to just match the www.something.com and leave our the ?asdfmsdmfs just curious no biggy I can handle if not You could use RegEx in your query, but that is a sub-optimal solution since RegEx will be slow. Instead, you should handle this when saving the records to your database by stripping off the extraneous bit. If you do need the full URL then you should add a column and put the base URL in one and the parameters of the URL in the other. Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/#findComment-1473176 Share on other sites More sharing options...
Barand Posted March 19, 2014 Share Posted March 19, 2014 try like this SELECT SUBSTRING_INDEX(http_referrer, '?', 1) as referrer , SUM(hit) as hits FROM global_stats GROUP BY referrer Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/#findComment-1473179 Share on other sites More sharing options...
Solution desjardins2010 Posted March 19, 2014 Author Solution Share Posted March 19, 2014 Sweet that worked perfect thanks Barand Quote Link to comment https://forums.phpfreaks.com/topic/287094-help-with-a-query-please/#findComment-1473196 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.