Is your SQL query the only method you're using to generate the original (faulty) file?
As I was reading about your predicament, it reminded me of instances when-- in the original file construction-- the file was set to APPEND rather than replace/recreate the data. While this meant the first view looked fine, additional updates replicated data and inflated the numbers.
A quick check you can do is compare the number of records in your bad file with your good extract and see if they match: if the former is heavily inflated, it's likely that you are somehow duplicating data elements.
It's also possible to erringly duplicate data elements within your SQL code; but since your extract worked fine, I don't think this is an issue.
Perhaps a more likely option is that a unique delimiter got left out-- meaning something that uniquely identifies measure-- leading to unexpected aggregations. You might see this when totaling sales by CITY, for example. If you fail to include STATE, Columbus, Ohio will be aggregated with ~18 other cities named Columbus in the USA (ok... goofy example maybe).
I'm uncertain if these kernels of thought can help you out... if not-- someone smarter than me will be by soon!
Good luck! -- Michael
Take a look at the video in this link:
If you create your own data source in excel as shown in the video and do "Replace data source" in a temp copy of your workbook, do the two sheets show the same sort of discrepancy? (Note: You don't have to pull out all your data into excel. See if the discrepancy occurs with 100 rows or so of your data.)
I'm suggesting this so that if you go through this exercise and still see the problem, you'll have an uploadable packaged workbook that you can share here. Pare out everything else except the two sheets. I'm curious to take a look.