dinedal / textql

Execute SQL against structured text like CSV or TSV
MIT License
9.07k stars 300 forks source link

Trying to sum and divide #126

Closed hegga closed 4 years ago

hegga commented 4 years ago

Hi!

Thank you for an awesome piece of software! I am however struggling with a problem, I have a size (in bytes) which I am trying to convert to GB, but all of the size fields are returned with "0". How can I fix this?

textql -header -sql "select date, sum(size)/1024/1024/1024 as size group by date" data_2020_09.csv

Other variants I have tried without any luck:

textql -header -sql "select date, sum(size)/1024/1024/1024 group by date" data_2020_09.csv
textql -header -sql "select date, (sum(size)/1024/1024/1024) as size group by date" data_2020_09.csv
dinedal commented 4 years ago

Just multiply one of the numbers by 1.0 so it becomes a floating point:

textql -header -sql "select date, (sum(size)*1.0)/1024/1024/1024 as size group by date" data_2020_09.csv
dinedal commented 4 years ago

Or better yet, cast as float:

textql -header -sql "select date, cast(sum(size) as float)/1024/1024/1024 as size group by date" data_2020_09.csv
hegga commented 4 years ago

Thank you! This worked perfectly.