I have a mysql query that pulls into excel via an ODBC connection. This query determines top 5 per group in descending order for the data it pulls and gives it a ranking number (1 through 5 in order of value per each unique item in group).
— The issue is when the data is imported into Excel, all the values of the ‘rank’ field are set at 1 (they should vary between 1 and 5), instead of the correct numbers. I’ve tried a whole host of things, but cannot figure out why excel is doing this.
I’m using mysql, and excel 2010.
Things I’ve tried:
1) Creating a new connection
2) Casting the rank output as a char
3) Concatenating the rank with text as a string.
4) deleting the worksheet and recreating it.
5) changing the column order in the sql
Thanks for any help you can provide. paraphrased query is below.
select
rank,
center,
supervisor_id,
missed,
box,
missed_percent
from
(select
supervisor_id,
missed,
box,
missed_percent,
@ranking := if(@warehouse = center, @ranking + 1,1) as rank,
@warehouse := center as center
from
(select
a.center,
f.supervisor_id,
sum(missed) as missed,
count(box) as box,
sum(missed) / count(box) as missed_percent,
(SELECT @ranking:= 0) s
from
seventy_subquery_table
left join people f on a.employee_id = f.employee_id
group by
a.center,
f.supervisor_id
) m
order by center, missed_percent desc
) m2
where m2.rank <= 5
order by center, rank
I actually just figured it out! The issue is within the second wrapping subquery – Apparently the ODBC connection to excel executes logically different then running it in mysql. So in this case something could work when ran, but no through ODBC.
Where mysql is shows correct data, excel doesn’t Adding (SELECT @warehouse:= ”) to the second subquery fixed the issue! I hope someone else can learn from this as it was frustrating