求SQL语句.(1分)

  • 主题发起人 tingyuxuan1
  • 开始时间
T

tingyuxuan1

Unregistered / Unconfirmed
GUEST, unregistred user!
Sybase数据库是否支持多表复合查询?
有2个表:
table1,table2.
table1字段 : id,ma,num
table2字段 : id,time,ne, time 是datetime型:如 2002-9-20 11:00:00
ne是char型 如 : WANG
如何根据table2的time和ne条件查询出table1中id与table2查询出的id相同且num>0
的table1的ma和num ?
 
select ma,num from table1
where num>0 and id in (select id from table2 where time=" " and ne= " ")
 
select ma,num
from table1
where num>0 and exists(
select *
from table2
where table1.id=table2.id and (time条件 and ne条件))
 
这样会提示 string 与 datetime 类型不匹配 。
 
Sybase数据库是否支持多表复合查询?
???
 
SqlStr:='select a.ma,a.num from table1 a,table2 b where b.time=:BT and b.ne =:BN and
a.id = b.id and b.num > 0';//BT,BN分别是sql语句中的变量,可以进行赋值

query1.close;
query1.sql.clear;
query1.sql.add(sqlstr);
query1.ParamByName('BT').AsString:='';//如果是日期型数据,请查阅相关的帖子
query1.ParamByName('BN').AsString:='';//在''中填写锁需要的值
query1.open;
query1.active;
 
time 条件怎么写啊 ?
 
我没用过Sybase数据库,对不起了。
 
cast('2002-9-8' as datetime)
 
支持,看HElp,很受用的
 
多人接受答案了。
 
顶部