我明白了:
$ echo "SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;" | sqlite
SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;
SQL error: near "AS": syntax error
$ sqlite
SQLite version 2.8.17
Enter ".help" for instructions
sqlite> SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;
SQL error: near "AS": syntax error
然而,完全相同的SQL
SELECT cast((strftime('%s','2017-11-01 22:25:28')-strftime('%s','2017-10-15 12:40:28')) AS real)/60/60 AS elapsed_hours;
在http://www.sqlitetutorial.net/tryit/query/sqlite-date/
上正常工作怎么了?我的SQLite是:
$ apt-cache policy sqlite
sqlite:
Installed: 2.8.17-14fakesync1
Candidate: 2.8.17-14fakesync1
Version table:
*** 2.8.17-14fakesync1 500
500 http://ca.archive.ubuntu.com/ubuntu zesty/universe amd64 Packages
100 /var/lib/dpkg/status
THX
答案 0 :(得分:0)
哦,谢谢@muistooshort,我认为我最新的ubuntu有最新的SQLite,
但经过调查后,我发现我应该安装/使用sqlite3
而不是sqlite
。
$ apt-get install sqlite3 sqlite-