[英]Add a Max value calculated column to a Where clause?
I created a Max value calculated column for trw1, trw2, and trw3.我为 trw1、trw2 和 trw3 创建了一个最大值计算列。 However I can not get the calculated column to work in the where clause.但是我无法让计算列在 where 子句中工作。
select *, s.knum as SPI_Knum, s.customer_id as Customer_id, s.season as SPI_Season,
s.inv as Inventory, s.owner_type as Room_type, s.status, s.trw1, s.trw2, s.trw21,
b.[ln curr bal] as MTG_Bal,
(select max(HighTrw)
from (values (trw1), (trw2), (trw21)) As updatedate(HighTrw)
) as High_TRW
where m.knum is null
and d.knum is null
and st.customer_id is null
and b.[ln curr bal] between '15000' and '7500'
and max(HighTrw) between '625' and '600'
I am trying to use this to set criteria.我正在尝试使用它来设置标准。 so basically I need to show anything that has a value between 15000 and 7500 but also has a TRW between 625 and 600 from the calculated row.所以基本上我需要显示任何值在 15000 和 7500 之间但 TRW 介于 625 和 600 之间的计算行。
In order to successfully use the where
clause, you'll need to use the entire subquery:为了成功使用where
子句,您需要使用整个子查询:
select s.id, s.trw1, s.trw2, s.trw3,
(select max(HighTrw)
from (values (trw1), (trw2), (trw3)) As updatedate(HighTrw))
as High_TRW
from my_table as s
where (select max(HighTrw)
from (values (trw1), (trw2), (trw3)) As updatedate(HighTrw)) between '600' and '625'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.