改成insert into [daydata] ([aiflso2],[aiflNo]) (select avg(aiflso2),avg(aiflNo) from (select top 10 aiflso2,aiflNo from realdata order by time desc)) 试试 不过,vb里好像不支持嵌套sql语句吧。
试试这个: insert into [daydata] ([aiflso2],[aiflNo]) select avg(aiflso2),avg(aiflNo) from (select top 10 aiflso2,aiflNo from realdata order by time desc) as a
insert into [daydata] select avg(ST.aiflso2) AS [aiflso2],avg(ST.aiflNo) AS [aiflNo] from (select top 10 aiflso2,aiflNo from realdata order by time desc) AS ST
把SQL命令直接发给数据库去做.VB里有这功能.
INSERT INTO daydata ( aiflso2, aiflNo ) SELECT avg(aiflso2), avg(aiflNo) FROM [select top 10 aiflso2,aiflNo from realdata order by time desc]. AS [%$##@_Alias]谢谢大家。我刚才突然发现,Access自动给我添加了最后 . As[%$##@_Alias] 然后我把它拷进程序,都OK了,不过它添加的是什么意思呢?
我猜是表名,如果没猜错的话,下面的语句也行 INSERT INTO daydata ( aiflso2, aiflNo ) SELECT avg(BB.aiflso2), avg(BB.aiflNo) FROM (select top 10 aiflso2,aiflNo from realdata order by time desc) AS BB
是表的别名, 把[select top 10 aiflso2,aiflNo from realdata order by time desc] 看成一个表。
试试
不过,vb里好像不支持嵌套sql语句吧。
insert into [daydata] ([aiflso2],[aiflNo])
select avg(aiflso2),avg(aiflNo)
from (select top 10 aiflso2,aiflNo from realdata order by time desc) as a
select avg(ST.aiflso2) AS [aiflso2],avg(ST.aiflNo) AS [aiflNo] from
(select top 10 aiflso2,aiflNo from realdata order by time desc) AS ST
SELECT avg(aiflso2), avg(aiflNo)
FROM [select top 10 aiflso2,aiflNo from realdata order by time desc]. AS [%$##@_Alias]谢谢大家。我刚才突然发现,Access自动给我添加了最后 . As[%$##@_Alias]
然后我把它拷进程序,都OK了,不过它添加的是什么意思呢?
INSERT INTO daydata ( aiflso2, aiflNo )
SELECT avg(BB.aiflso2), avg(BB.aiflNo)
FROM (select top 10 aiflso2,aiflNo from realdata order by time desc) AS BB
把[select top 10 aiflso2,aiflNo from realdata order by time desc]
看成一个表。