shmideo Posted December 5, 2014 Share Posted December 5, 2014 HiCould do with some help. I have 20 clients (client-1, client-2, client-3) and so on. Each client makes several calls per day.How can I get a row count from two columns (Date, clid) and echo the count for each client? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 5, 2014 Share Posted December 5, 2014 Total count for each client SELECT clid, COUNT(*) as tot FROM tablename GROUP BY clid Total count each day for each client SELECT clid, date, COUNT(*) as tot FROM tablename GROUP BY clid, date Quote Link to comment Share on other sites More sharing options...
shmideo Posted December 5, 2014 Author Share Posted December 5, 2014 Thanks Barand, This works, but due to the clid format, which for example: "Client-1-+012345678" <012345678>" . There may be several instances of the same number. It groups by clid and it does exactly as it's supposed to, but I'm trying to get a count for all rows per client, so is there a way to group by clid except say maybe only by the client name, ie, ignore everything after the '-+'? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 5, 2014 Share Posted December 5, 2014 There is if you design your tables correctly and don't just throw different bits of data together into a single field. As a workaround for now you could try ... GROUP BY SUBSTRING_INDEX(clid, '+', 1) Quote Link to comment Share on other sites More sharing options...
shmideo Posted December 6, 2014 Author Share Posted December 6, 2014 Yes exactly, however I have no control of the table layout but I'll give this a try. Thanks for your help. 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.