100分求一sql语句

meetyou930 2006-06-15 04:21:38
表如下:
id department_type low_account low_sign high_account high_sign persons operator_type
1 d1 0 =< 5 <= p1 10
2 d1 50 =< 100 <= p4 12
3 d2 5 < 50 < p2 12
4 其他 0 =< 300 < p3 11

low_sign和high_sign代表符号.
已知 department_type(可能是d3)和account,如果department_type=d3,按照其他处理.
如果sql语句解决不了,存储过程也行.
...全文
159 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunnyrain 2006-06-19
  • 打赏
  • 举报
回复
vi_department_type
vi_account


for v_record in (select * from table where department_type<>'其他') loop
v_sql:=v_sql ||' select * from table where '||v_record.department_type||'='''||vi_department_type||''' and low_account '||v_record.low_sign||' vi_account and vi_account '||v_record.high_sign||' high_account union ';
end loop;

v_sql:=v_sql||' select * from table where department_type='''其他''' and not exists (select * from table where department_type ='''||vi_department_type||''') and 0<='||vi_account||' and '||vi_account||'<=300';



大概这样吧,不知道有没有用
eagle4510 2006-06-18
  • 打赏
  • 举报
回复
怎么这么设计这个表啊 “=<” 用“<=”不行吗?
建议使用游标,成生动态sql语句。
meetyou930 2006-06-15
  • 打赏
  • 举报
回复
对了,最好写成函数,我需要返回persons和operator_type,这两个字段的值.
meetyou930 2006-06-15
  • 打赏
  • 举报
回复
有人帮我写了ms-sql的,谁能该成oracle的:
这个应该可以静态处理:

if not exists (
select 1 from tablename
where department_type =@department_type
)
select * from tablename
where department_type ='其他'
and (
(low_sign='<'
and low_account<@account
) or
(low_sign='<='
and low_account<=@account
)
)
and (
(high_sign='>'
and high_account>@account
) or
(high_sign='>='
and high_account<=@account
)
)
else
select * from tablename
where department_type =@department_type
and (
(low_sign='<'
and low_account<@account
) or
(low_sign='<='
and low_account<=@account
)
)
and (
(high_sign='>'
and high_account>@account
) or
(high_sign='>='
and high_account<=@account
)
)
fjmingyang 2006-06-15
  • 打赏
  • 举报
回复
问题表述的不明确,你要什么结果?
qiaozhiwei 2006-06-15
  • 打赏
  • 举报
回复
我的理解是你的表记录表示的是一个范围,你知道了account,要得到一个范围,但是你的表数据好像不是很清楚,请把问题表述清楚一点

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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