0

友達。次のクエリと混同しています。

c = db.rawQuery("SELECT strftime('%W', tm.txn_date) AS week, 
               sum(case when cm.master_id = 1 then (tm.amount - tm.pre_amount) else 0 end) AS Income, 
               sum(case when cm.master_id = 2 then (tm.pre_amount - tm.amount) else 0 end) AS Expense 
               FROM transmaster tm 
               INNER JOIN subcatmasters scm ON tm.scmaster_id = scm.id 
               INNER JOIN catmasters cm ON scm.catmaster_id = cm.id 
               WHERE strftime('%m', tm.txn_date) = '05' 
               GROUP BY week ORDER BY week DESC", null);

これは完全に機能しますが。

c = db.rawQuery("SELECT strftime('%W', tm.txn_date) AS week, 
               sum(case when cm.master_id = 1 then (tm.amount - tm.pre_amount) else 0 end) AS Income, 
               sum(case when cm.master_id = 2 then (tm.pre_amount - tm.amount) else 0 end) AS Expense 
               FROM transmaster tm 
               INNER JOIN subcatmasters scm ON tm.scmaster_id = scm.id 
               INNER JOIN catmasters cm ON scm.catmaster_id = cm.id 
               WHERE strftime('%m', tm.txn_date) = '"+05+"' 
               GROUP BY week ORDER BY week DESC", null);

これはうまくいきませんでした。問題の友人は何ですか。

月番号を明示的に指定したいので、WHERE strftime('%m', tm.txn_date) = '05'この行をWhyに変更します。WHERE strftime('%m', tm.txn_date) = '"+05+"'

私を助けてください。前もって感謝します。

4

2 に答える 2

1

これを試して :

c = db.rawQuery("SELECT strftime('%W', tm.txn_date) AS week, 
               sum(case when cm.master_id = 1 then (tm.amount - tm.pre_amount) else 0 end) AS Income, 
               sum(case when cm.master_id = 2 then (tm.pre_amount - tm.amount) else 0 end) AS Expense 
               FROM transmaster tm 
               INNER JOIN subcatmasters scm ON tm.scmaster_id = scm.id 
               INNER JOIN catmasters cm ON scm.catmaster_id = cm.id 
               WHERE strftime('%m', tm.txn_date) = '0"+5+"' 
               GROUP BY week ORDER BY week DESC", null);

どうですか?

于 2013-05-07T14:22:26.067 に答える
1

よりクリーンな何かを行い、月番号の変数を宣言する必要があります。

String monthNumber = "05";
String request = "SELECT strftime('%W', tm.txn_date) AS week, " +
               "sum(case when cm.master_id = 1 then (tm.amount - tm.pre_amount) else 0 end) AS Income, " +
               "sum(case when cm.master_id = 2 then (tm.pre_amount - tm.amount) else 0 end) AS Expense " +
               "FROM transmaster tm " +
               "INNER JOIN subcatmasters scm ON tm.scmaster_id = scm.id " +
               "INNER JOIN catmasters cm ON scm.catmaster_id = cm.id " +
               "WHERE strftime('%m', tm.txn_date) = '" + monthNumber + "' " +
               "GROUP BY week ORDER BY week DESC";
c = db.rawQuery(request, null);
于 2013-05-07T14:46:58.747 に答える