老兄,两个表通过什么关联,你可以使用Left join写的
解决方案 »
- sql2000 有关于数据库备份
- ???问个sql server 关于sysuser表的问题
- 一个小小的求平均分问题?
- 100分:如何恢复带全文索引的数据库
- 怎样将变量放在from子句后?
- 【求助】 怎么能查询到一个表部分列的全部数据
- 怎样编写程序自动将某个文本文件的数据导入数据库的表中,并且保留原来的数据,只是增加!
- 关于ADO访问加过密ACCESS2000数据库问题
- 关于sql中分组的一个问题
- 在SQL服务器属性中,GENERAL选项卡中有 STARTUP PARAMETERS…
- 急!!! 请教sql7.0 中如何自动执行存储过程?
- 请问:ORA-00205:???????? 代表什么意思?
date //交易日期 主关键字
fOpen
fHigh
fLow
fClose
fVolume
dr
tq
select table1.code,table1.date,fOpen,fHigh,fLow,fClose,fVolume,dr,tq
from table1,table2
where
table1.code = table2.code and
table1.date >= table2.date and
table1.date =
(select max(date) from table2 where code = table1.code)
order by patientinfo.checkid
from table1,table2
where
table1.code = table2.code and
table1.date >= table2.date and
table1.date =
(select max(date) from table2 where code = table1.code)
(select max(date) from table2 where code = table1.code)
table1.date存在,但max(date) 极有可能比table1.date小.谢谢你.
你试一试吧,我不知道对不对。我现在没法试
from table1,table2
where
table1.code = table2.code and
table1.date >= table2.date and
//这回没问题了
table2.date =
(select max(date) from table2 where code = table1.code)
上面的方法太差了!我想功能也不完善!
他们如何相等那!
select a.* ,b.dr,b.tq
from table1 a,table2 b
where
a.code=b.code and decode(a.date-b.date,0,a.date=b.date,max(a.date-b.date))
我想这个问题的思路是这样的!具体问题你看看
sql server下可以
select a.* ,b.dr,b.tq
from table1 a,table2 b
where
a.code=b.code and (case a.date-b.date when 0 then a.date=b.date max(a.date-b.date)))
哈哈我想不错的!
我想知道你是那里的朋友阿
(select max(date) from table2 where code = table1.code)
这样只能取出一个date ,对于不同的code 取出的date一样,这样肯定不行
看看我写的代码.在SQL7.0下运行正常
SELECT table1.fOpen, table1.fHigh, table1.fLow,
table1.fClose, table1.fVolume, table1.fAmount, table2.DR,
table2.TQ, table1.date, table2.Date
FROM table2 INNER JOIN
table1 ON table2.code = table1.code
WHERE (table2.Date =
(SELECT MAX(table2.Date)
FROM table2
WHERE (table2.Code = table1.code) AND
(table2.Date <= table1.date)))
SELECT b_table1.*, b_table2.f3, b_table2.f4, b_table2.Date as date2
FROM b_table2 ,
b_table1 ,
(
SELECT MAX(b_table2.Date) as date2 ,b_table1.code,b_table1.Date FROM b_table2 ,b_table1
WHERE (b_table2.Code = b_table1.code) AND (b_table2.Date <= b_table1.date)
group by b_table1.code , b_table1.Date
) t3
where b_table2.code = t3.code and b_table1.code =t3.code and b_table1.date =t3.date and b_table2.date = t3.date2