Last active
July 6, 2020 04:35
-
-
Save ks--ks/b64b10ce95065655431b5728d4e52aeb to your computer and use it in GitHub Desktop.
Data converting in sqlite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--convert `$150.00` to cents `15000` query sqlite> | |
select replace(replace(Amount, '$', ''), '.', '') from test limit 5; | |
-- convert `$150.00` to cents `15000` in integer so we can `sum` query sqlite> | |
select cast(replace(replace(Amount, '$', ''), '.', '') as integer) | |
from test | |
limit 5; | |
-- check column type sqlite> | |
select typeof(created_at) | |
from test | |
limit 5; | |
-- text convert `03-02-2017` to `2017-02-03` query `sqlite> | |
select created_at, date(substr(created_at,7,4)||'-'||substr(created_at,4,2)||'-'||substr(created_at,1,2)) | |
from test | |
limit 5; | |
-- export query output to file and exit | |
.once output.txt | |
.exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment