以下に小さな bash スクリプトを書きましたが、意図したとおりに動作しますが、読みやすくするためにいくつかのコメントと改行を追加したため、コードが壊れてしまいました。コメントと改行を削除すると、有効なスクリプトになります。
### read all measurements from the database and list each value only once
sqlite3 -init /tmp/timeout /tmp/testje.sqlite \
'select distinct measurement from errors order by measurement;' |
### remove the first line of stdout as this is a notification rather than intended output
sed '1d' |
### loop though all found values
while read error; do
### count the number of occurences in the original table and print that
sqlite3 -init /tmp/timeout /tmp/testje.sqlite \
"select $error,count( measurement ) from errors where measurement = '$error' ;"
done
結果は次のようになります。
134 1
136 1
139 2
159 1
質問: -loop を SQL ステートメントsqlite3
に変換することは可能ですか? while
言い換えれば、sqlite3for
は、前のクエリの結果をループするために、ある種の -loop をサポートしていますか?
は非常に限られたデータベースであり、必要sqlite3
なものは複雑すぎる可能性があります。私はそれを探してきましたが、私は実際にはデータベースのオタクであり、これまでに得たヒットは別のデータベースであるか、まったく別の問題を解決しています.
最も簡単な答え (ところで私は望んでいません) は、「sqlite3 はループをサポートしていません」です。