4 ms·
This is cool, and kudos to you for writing it, and getting it out there. I've always found that more than half the "hard work" is actually finishing something
by loxias 4y ago
This is cool, and kudos to you for writing it, and getting it out there. I've always found that more than half the "hard work" is actually finishing something and getting it out there, and you get all my respect for doing that.
Querying Excel spreadsheets with SQL, however, is something that can already be done with no additional tools, no custom plugins, just good old fashioned command line knowledge.
(first, download superstore.xls, some test data I found [0])
loxias@host:~$ sqlite3 -csv :memory: -cmd ".import '| ssconvert -T Gnumeric_stf:stf_csv superstore.xls fd://1' orders" -cmd '.mode column' 'SELECT State, AVG(Profit), COUNT(*) FROM orders GROUP BY State ORDER BY AVG(Profit) DESC LIMIT 5'
State AVG(Profit) COUNT(*)
------------ ---------------- --------
Vermont 204.088936363636 11
Rhode Island 130.100523214286 56
Indiana 123.375411409396 149
Montana 122.2219 15
Minnesota 121.608847191011 89
loxias@host:~$ sqlite3 -csv :memory: -cmd ".import '| ssconvert -T Gnumeric_stf:stf_csv superstore.xls fd://1' orders" -cmd '.mode column' 'SELECT State, AVG(Profit), COUNT(*) FROM orders GROUP BY State ORDER BY AVG(Profit) ASC LIMIT 5'
State AVG(Profit) COUNT(*)
-------------- ----------------- --------
Ohio -36.1863040511728 469
Colorado -35.8673510989011 182
North Carolina -30.0839847389558 249
Tennessee -29.1895825136612 183
Pennsylvania -26.5075984667803 587
And there you have the 5 top and 5 worst performing states by profit margin.
Look ma! No code! No temp files even! :D
[0] https://community.tableau.com/s/question/0D54T00000CWeX8SAL/sample-superstore-sales-excelxls\\ https://community.tableau.com/s/question/0D54T00000CWeX8SAL/...*
- eatonphil 4y agoYou just went from requiring one bit of code to requiring another. I.e. Does every Linux distro and Mac and Windows come with ssconvert?
- loxias 4y ago(heavily edited for tone and clarity) > You just went from requiring one bit of code to requiring another Not in the slightest. I went from requiring customized code, including a whole build framework for a specific programming language to requiring only the tools one can assume are installed, and no code. For the task of "querying spreadsheets with sqlite", there are only two programs you can assume the user already has: Sqlite, and spreadsheet software. :) I think that's a safe and reasonable assumption, no? ssconvert is part of Gnumeric. One can do the same thing with libreoffice but I didn't know the syntax offhand. [0] [0] loxias@host:~$ libreoffice --convert-to csv superstore.xls