我应该写一个能够显示SQLite结果的shell脚本,我已经写了一个可以向SQLite数据库添加条目的脚本。现在我想在添加条目后显示结果。
以下是我的脚本:
格式应该像这样:
以下是我的脚本:
echo 'insert into myTable (Date, Details, Category, Average) values (datetime('\''now'\'','\''localtime'\''), '\'''$1''\'', '\'''$2''\'', '$3');'|sqlite3 /Users/user/Documents/Test/dbName.db
接下来,我希望该脚本能够通过echo/spit语句输出内容:
select sum(Average) from (select * from myTable where Category = 'category1');
select sum(Average) from (select * from myTable where Category = 'category2');
格式应该像这样:
Category1 total = <output of first statement>
Category2 total = <output of second statement>
就是这样。我在SQL方面还很新手,对shell脚本也不是很擅长。我也在寻找好的教程来解释这类问题。