oracel (列,列) in (值1,值2)的用法

cheniqit1 2012-03-30 06:28:18
由于有一个excle数据拼接成一个sql语句


select  s_landedcost,s_styleno,s_seasonyear,s_seasoncode 
from t_style
where (s_styleno,s_seasonyear,s_seasoncode) in
('NH199','2005','N'
,'NH199','2005','N' );


不知道可以否?
...全文
121 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssqtjffcu 2012-03-31
  • 打赏
  • 举报
回复

--可以这样
select s_landedcost, s_styleno, s_seasonyear, s_seasoncode
from t_style
where (s_styleno, s_seasonyear, s_seasoncode) in
(('NH199', '2005', 'N'),( 'NH199', '2005', 'N'));
cheniqit1 2012-03-31
  • 打赏
  • 举报
回复
成功, 感谢给位,泪流满面.
ssqtjffcu 2012-03-30
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
由于有一个excle数据拼接成一个sql语句



SQL code
select s_landedcost,s_styleno,s_seasonyear,s_seasoncode
from t_style
where (s_styleno,s_seasonyear,s_seasoncode) in
('NH199','2005','N'
,'NH199','2005'……
[/Quote]

不可以这样写的,这样写oracle会报错
下面这样可以

select *
from emp
where (job, deptno) in (SELECT JOB, DEPTNO FROM EMP WHERE DEPTNO = 20)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO FLAG
----- ---------- --------- ----- ----------- --------- --------- ------ ----
7876 ADAMS CLERK 7788 1987-5-23 1100.00 20
7369 SMITH1 CLERK 7912 1980-12-17 800.00 20
7566 JONES MANAGER 7839 1981-4-2 2975.00 20
7902 FORD ANALYST 7566 1981-12-3 3000.00 20
7788 SCOTT ANALYST 7566 1987-4-19 3000.00 20
youqi1984 2012-03-30
  • 打赏
  • 举报
回复
select s_landedcost,s_styleno,s_seasonyear,s_seasoncode
from t_style
where (s_styleno,s_seasonyear,s_seasoncode) in
(
select 'NH199','2005','N' from dual
union all
select 'NH199','2005','N' from dual
)tb;
dawugui 2012-03-30
  • 打赏
  • 举报
回复
不能这么用.假设
'NH199','2005','N'
'NH199','2005','N'
是某个表t的三个列,c1 , c2 , c3

select m.s_landedcost,m.s_styleno,m.s_seasonyear,m.s_seasoncode
from t_style m
where exists (select 1 from t where m.s_styleno = t.c1 and m.s_seasonyear = t.c2 and m.s_seasoncode = t.c3)

select m.s_landedcost,m.s_styleno,m.s_seasonyear,m.s_seasoncode
from t_style m,t
where m.s_styleno = t.c1 and m.s_seasonyear = t.c2 and m.s_seasoncode = t.c3




17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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