【发布时间】:2018-01-31 13:28:48
【问题描述】:
我知道I can't reference an alias in the WHERE clause,但这是为什么呢?是不是有不同的解释?
这样的事情会产生错误:
declare @myTable table
(
num numeric(5,2),
den numeric(5,2)
)
insert into @mytable
select 1, 2
union
select 1, 3
union
select 2, 3
union
select 2, 4
union
select 2, 5
union
select null, 1
select num/den as 'calc' from @myTable
where calc is not null
order by calc
但这会返回行:
declare @myTable table
(
num numeric(5,2),
den numeric(5,2)
)
insert into @mytable
select 1, 2
union
select 1, 3
union
select 2, 3
union
select 2, 4
union
select 2, 5
union
select null, 1
select num/den as 'calc' from @myTable
--where calc is not null
order by calc
【问题讨论】:
-
没关系,找到原因了:stackoverflow.com/questions/31808423/…