日期:2014-05-19  浏览次数:20480 次

[咨询]一个比较复杂的 SQL 查询语句
数据库中有两个表   tableA   和   tableB

tableA   和   tableB   中都有数据项   :   订单号

tableA   中数据项还有订单产生的日期比如   2007-10-1   ,
但是   tableB   中没有日期项。

我想将   tableB   在   2005-5-5   至   2007-7-7   之间产生的所有订单纪录找出来
语句怎么写?谢谢

------解决方案--------------------
select b.* from tableB as b
inner join tableA as a on a.订单号 = b.订单号
where a.日期 between '2005-5-5 ' and '2005-5-5 '
------解决方案--------------------
select b.*
from tableA a innert join tableB b on a.订单号=b.订单号
where a.订单产生的日期 between '2005-5-5 ' and '2007-7-7 '
------解决方案--------------------
try

Select B.* From tableA Inner Join tableB On A.订单号 = B.订单号 Where A.订单日期 Between '2005-05-05 ' And '2007-07-07 '
------解决方案--------------------
select b.* from tableB as b
inner join tableA as a on a.订单号 = b.订单号
where a.日期 between '2005-5-5 ' and '2007-7-7 '

------解决方案--------------------
select ... from tablea a left join tableb b
on a.订单号=b.订单号
where date between '2005-5-5 ' and '2007-7-7 '
order by date

大致这个样子吧
------解决方案--------------------
select b.* from tableB b
inner join tableA a
on a.订单号 = b.订单号
where a.日期 between '2005-5-5 ' and '2007-7-7 '

------解决方案--------------------
可能是设置了ROWVERSION字段,程序或者存储过程中有乐观锁定的设计,在修改数据时会检测ROWVERSION的值,如果不满足会返回提示
------解决方案--------------------
對string賦值最好不要換行,要換行的話就把每行都作為一個字符串拼接起來

strcmd = "delete b from tableB as b " &
"inner join tableA as a on a.订单号 = b.订单号 " &
"where a.日期 between '2005-5-5 ' and '2007-7-7 ' "
------解决方案--------------------
select tableB.* from tableB
inner join tableA on tableA.订单号 = tableB.订单号
where tableA.日期 between '2005-5-5 ' and '2007-7-7 '

------解决方案--------------------
订单号 是主键吗,两表一一对应应该很好解决

------解决方案--------------------
各位大虾这条语句能否这样写:
select * from b
where 订单号 in (select 订单号 from a
where 日期 between '2005-5-5 ' and '2005-5-5 ')