如何设置单个变量以在SQL的“transactions.amount> 5”部分中使用,该部分用于以下SELECT语句的两个部分?那么我可以在查询中设置一次值(例如,在本例中为5),然后UNION ALL语句的两边都可以引用它?
我正在使用Microsoft Access,因此这是一个访问查询。
SELECT transactions.title, transactions.amount, categories.title
FROM transactions LEFT JOIN (categories RIGHT JOIN [trans-cat] ON categories.ID = [trans-cat].categoryID) ON transactions.ID = [trans-cat].transactionID
WHERE NOT EXISTS (select transactionID from [trans-cat] where transactions.ID = [trans-cat].transactionID ) AND transactions.amount > 5
union all
SELECT transactions.title, transactions.amount, categories.title
FROM transactions INNER JOIN (categories INNER JOIN [trans-cat] ON categories.ID = [trans-cat].categoryID) ON transactions.ID = [trans-cat].transactionID
WHERE transactions.amount > 5
答案 0 :(得分:0)
根据@cha的回复:
如果对两个条件使用相同的参数名称(即[threshold]),则需要指定一次参数