I hope someone can point out where I am going wrong, but I looked at this for the last 30 minutes and did not get anywhere with it.
I have a temporary table filled with data, the front-end application cannot do any logic for me, so please excuse the ugly logic of case statements in the table.
The user is happy with the result, which returns when I get the top 10 entries. Now they have decided that they want to see the group of the remaining countries (all lines are not in the top ten) as “Other”.
I tried to create a grouping of countries that are not in the top 10, but without working, I planned UNION'ing this result in the top 10 results.
SELECT c.Country, count(*) AS 'Total_Number_of_customers', COALESCE(ili.new_customers,0) AS 'New_Customers', COALESCE(ilb.existing_first,0) AS 'Existing_First_Trans', COALESCE(ilc.existing_old,0) AS 'Existing_Prev_Trans'
FROM
LEFT JOIN (SELECT z.country, count(*) AS 'new_customers' FROM
LEFT JOIN (SELECT zy.country, count(*) AS 'existing_first' FROM
LEFT JOIN (SELECT zx.country, count(*) AS 'existing_old' FROM
GROUP BY c.country, ili.new_customers, ilb.existing_first, ilc.existing_old
ORDER BY 2 DESC
Here is the SQL that I use to get the results from my table.
For reference, each row in my temporary table contains the client identifier, the date they were created, and the type of my client, which is typical of what I'm trying to achieve.
Hope this is a simple problem and I'm just a little slow.
Thanks a lot in Adv.