我有一个Sqlite数据库,我使用Select和Union All语句创建了一个View accounts_in_transactions ,如下所示:
CREATE VIEW accounts_in_transactions AS
SELECT transactions_data._id,
((transactions_data.value) * -1) AS value, transactions_data.type,
transactions_data.acc_from_id AS acc_id,
transactions_data.acc_name_from AS acc_name
FROM transactions_data
UNION ALL
SELECT transactions_data._id,
transactions_data.value AS value, transactions_data.type,
transactions_data.acc_to_id AS acc_id,
transactions_data.acc_name_to AS acc_name
FROM transactions_data;
我运行SELECT * FROM accounts_in_transactions;
,我得到了预期的结果。
但是当我尝试这样做时:
SELECT accounts_in_transactions.acc_id, accounts._id
FROM acounts
JOIN accounts_in_transactions
ON accounts._id = accounts_in_transactions.acc_id;
我没有结果。 ( accounts._id 在 accounts_in_transactions.acc_id 中具有相同的值)
但如果我使用它:
SELECT transactions_data.acc_from_id, transactions_data.acc_to_id , accounts._id
FROM accounts
JOIN transactions_data
ON accounts._id IN (transactions_data.acc_from_id,transactions_data.acc_to_id);
工作正常......
我的代码中是否存在问题,或者我无法在带有UNION ALL语句的View的查询中使用Join,或者这是Sqlite中的限制?
提前致谢!