select
case t1.d1 + t2.v1 + t2.c1
begin
then t1.d1
else ''
end from t1 inner join t2
on t1.id= t2.id大概这样吧没测试过。。 如果不需要空的数据 这个就算子查询外面+一层就可以乐吧
case t1.d1 + t2.v1 + t2.c1
begin
then t1.d1
else ''
end from t1 inner join t2
on t1.id= t2.id大概这样吧没测试过。。 如果不需要空的数据 这个就算子查询外面+一层就可以乐吧
解决方案 »
- 请问QQ空间的“您上次离开后新增的访客数”在数据库上要怎么设计?
- excel数据导入到SQL,这个还真有难度?
- 关于触发器的问题
- 将excel里的数据表结构生成脚本,插入到SQL数据库中生成数据表
- sql 6.5的序列号?
- 用sql server 2000 for jdbc 驱动程序怎样设置classpath路径?
- (升级版)一个不算难也不算简单的问题!希望高手可以看下!
- 请教一个SQL存储过程的面试题
- 关于SQL Server 在win2000下内存无法释放的问题(最终结果)
- 存储过程的输出参数能用表变量吗?
- 有两条记录,型号这个字段的值是相同的,但适用于距查询型号=‘某某’不能显示第二条记录!
- *********sql语句高手帮忙来看,如何实现两表多对多更新? 急! 在线等
a.*
from
T1 a,T2 b
where
a.ID = b.ID
and
b.l = 'and'
and
1 = (case when b.v1='>' and a.d1>b.c1 then 1
when b.v1='=' and a.d1=b.c1 then 1
when b.v1='<' and a.d1<b.c1 then 1
end)
and
1 = (case when b.v2='>' and a.d2>b.c2 then 1
when b.v2='=' and a.d2=b.c2 then 1
when b.v2='<' and a.d2<b.c2 then 1
end)
union all
select
a.*
from
T1 a,T2 b
where
a.ID = b.ID
and
b.l = 'and'
and
(1 = (case when b.v1='>' and a.d1>b.c1 then 1
when b.v1='=' and a.d1=b.c1 then 1
when b.v1='<' and a.d1<b.c1 then 1
end)
or
1 = (case when b.v2='>' and a.d2>b.c2 then 1
when b.v2='=' and a.d2=b.c2 then 1
when b.v2='<' and a.d2<b.c2 then 1
end))
select
a.*
from
T1 a,T2 b
where
a.ID = b.ID
and
b.l = 'and'
and
1 = (case when b.v1='>' and a.d1>b.c1 then 1
when b.v1='=' and a.d1=b.c1 then 1
when b.v1='<' and a.d1<b.c1 then 1
end)
and
1 = (case when b.v2='>' and a.d2>b.c2 then 1
when b.v2='=' and a.d2=b.c2 then 1
when b.v2='<' and a.d2<b.c2 then 1
end)
union all
select
a.*
from
T1 a,T2 b
where
a.ID = b.ID
and
b.l = 'or'--这里改成'or'
and
(1 = (case when b.v1='>' and a.d1>b.c1 then 1
when b.v1='=' and a.d1=b.c1 then 1
when b.v1='<' and a.d1<b.c1 then 1
end)
or
1 = (case when b.v2='>' and a.d2>b.c2 then 1
when b.v2='=' and a.d2=b.c2 then 1
when b.v2='<' and a.d2<b.c2 then 1
end))