我正在尝试获取附件中的结果。 但是我需要 where 子句让用户在 power bi 中选择自己的日期。
每当我尝试在 where 子句中添加日期时,我都无法按预期显示结果。 我可以知道有人对此有提示/线索吗?
非常感谢
[tabe1](https://i.sstatic.net/68gp0ZBM.png)
[table2](https://i.sstatic.net/JfliZmA2.png)
[expectation](https://i.sstatic.net/xpzArhiI.png)
SELECT
table1.team,
table2.datee,
table2.price
from
table1 left join table2 on table1.team=table2.team
and table2.datee='2406'
--where table2.datee='2406' --need this for users to input but will not display the result as expected
将用户的输入参数放入“table2.datee=[@param]”处的联接中应该可以解决问题。如果由于某种原因这不是一个选项,您可以使用临时表通过 where 子句获得相同的结果:
CREATE TEMPORARY TABLE tmp (
SELECT *
FROM Table2 t2
WHERE t2.DATEE = 2406
);
SELECT t1.TEAM, t2.DATEE, t2.PRICE
FROM Table1 t1
LEFT JOIN tmp t2 ON t1.Team = t2.Team;