问个sql查询语句
tab1中有一个字段c1,其数据的长度要么是1要么是4,根据这个字段查询对应的数据
如果c1的长度是1,那么数据要从tab2中查询相应的数据
如果c1的长度是4,那么数据要从tab3中查询相应的数据
最后的结果:
c1 结果
a 张三
abcd 山东
怎么写?
把表的结构描述清楚,tab1和其它两张表都没有关联根据什么查
tab2和tab3中都有与c1数据对应的数据,且是唯一的,
SQL code:
if(len(c1)=1)
begin
select * from tab2 where c1=@c1
end
else
begin
select * from tab3 where c1=@c1
end
你干脆把他们整成一张表,在定义属性c1,再根据c1的值来查会更好些.......
case when a.l= '1' then b.x
when a.l = '4' then c.x end
在sqlserver中有case语法,看下帮助就明白了
飘过
SQL code:
declare @t table( userName varchar(20))
insert into @t values( 'a')
insert into @t values( 'abcd')
declare @t1 table(userName varchar(20) , nameDescription varchar(20))
insert into @t1 values( 'a' , '张三')
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......
Oracle中SQL语句中
drop table 表名 cascadeconstraints
与
drop table 表名 cascadeconstraint
有什么区别?
constraint和constraints在oracle中是一样使用的
官方建议使用constraint
引用
constraint和c ......