这个语句如何写

dqj 2007-08-24 03:59:23
select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
---when user_id=10004 then 1
---when user_id <>10004 then 2
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004
and ydqx >=visible

ydqx 是表中没有的列,在'and ydqx >=visible'中总是报:列名 'ydqx' 无效。

不知道该如何在where 后引用 ydqx
...全文
179 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dqj 2007-08-24
  • 打赏
  • 举报
回复
谢了
a2krh 2007-08-24
  • 打赏
  • 举报
回复
好像需要套一层子表
select a.*
from(
select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
---when user_id=10004 then 1
---when user_id <>10004 then 2
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004
) a
where a.ydqx >= a.visible
paoluo 2007-08-24
  • 打赏
  • 举报
回复
...
paoluo 2007-08-24
  • 打赏
  • 举报
回复
或者使用子查詢


Select * From(
select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004) A
Where ydqx >=visible
Limpire 2007-08-24
  • 打赏
  • 举报
回复
select * from

(select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004) a

where ydqx >=visible
paoluo 2007-08-24
  • 打赏
  • 举报
回复
計算列不能直接拿來使用,必須寫全

select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
---when user_id=10004 then 1
---when user_id <>10004 then 2
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004
and (case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
---when user_id=10004 then 1
---when user_id <>10004 then 2
else 2 end) >=visible
dqj 2007-08-24
  • 打赏
  • 举报
回复
select visible,ydqx = case
when post_id =1 then 4
when post_id =2 then 4
when ui.Department_id=ar.Department_id then 3
else 2 end from userinfo ui , article ar--
where id=4114 and user_id=10004
and ydqx >=visible

ydqx 是表中没有的列,在'and ydqx >=visible'中总是报:列名 'ydqx' 无效。

不知道该如何在where 后引用 ydqx

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧