このチューニングでは、ユーザー調整可能なパラメータが数多くあり、それらをSQL文に直接編集するのではなく、いくつかのテキストファイルを作成し、sqlite3 db.sqlite ".read query.sql" > result.csv
でクエリを実行し、結果をCSVとして取得することができます。問題は、SQL文でselect関数をハードコーディングするか、テキストファイルをインポートしてselectを使用すると、結果が異なることです。sqlite(LIKEまたはLIKE)がLIKE(select)と異なる結果を返す
.headers off
.mode csv
CREATE TEMP TABLE IF NOT EXISTS zipcodes(zipcode text primary key);
.import zipcodes.txt zipcodes
CREATE TEMP TABLE IF NOT EXISTS dates(year text primary key);
.import dates.txt dates
CREATE TEMP TABLE IF NOT EXISTS history_codes(code text primary key);
.import history_codes.txt history_codes
.print "CALLSIGN,FIRST,LAST,ADDRESS,BOX,CITY,STATE,ZIP"
select
DISTINCT
COUNT(*)
from PUBACC_EN
JOIN PUBACC_HD ON PUBACC_EN.unique_system_identifier = PUBACC_HD.unique_system_identifier
JOIN PUBACC_AM ON PUBACC_EN.unique_system_identifier = PUBACC_AM.unique_system_identifier
JOIN PUBACC_AD ON PUBACC_EN.unique_system_identifier = PUBACC_AD.unique_system_identifier
JOIN PUBACC_HS ON PUBACC_EN.unique_system_identifier = PUBACC_HS.unique_system_identifier
WHERE (radio_service_code = "HA" or radio_service_code = "HV")
and PUBACC_AM.callsign <> ''
and PUBACC_HS.code LIKE (select code from history_codes)
and (street_address <> '' OR po_box <> '')
and applicant_type_code == "I"
and NOT previous_operator_class <> ''
and NOT previous_callsign <> ''
-- and grant_date like (select year from dates)
and (grant_date like "%2015%" or grant_date like "%2016%")
and zip_code IN (select zipcode from zipcodes)
ORDER BY PUBACC_AM.callsign ASC
;
DROP TABLE zipcodes;
DROP TABLE dates;
DROP TABLE history_codes;
お知らせ
-- and grant_date like (select year from dates)
and (grant_date like "%2015%" or grant_date like "%2016%")
日付テーブルに含まれる行:
sqlite> select * from dates;
%2015%
%2016%
だから、ハードコードされたと同じ項目があります。ここ
は、全体のSQLファイルでありますライン。コメントを使用してステートメントを交換すると、レコードの数が変わります。私はここに日付のアイテムしか表示していませんが、私もzipcodesやhistory_codesで同じことをすると、私は別の結果になります。ユーザーがパラメータのテキストファイルを編集し、その情報をクエリにインポートできるようにするにはどうすればよいですか?
ありがとうございます。
これは完全に働きました。なぜ私はそれを早く考えなかったのか分かりませんが、私はそれをあまりにも長く見ていました。 ;)乾杯。 –