access里的sql语句转换为sql server的sql语句的问题
SELECT CellMaster.[LineNo], CellMaster.CellNo, Last(CellStatus.StatusDate) AS [Date], Last(CellStatus.Status) AS Status
FROM CellMaster LEFT JOIN CellStatus ON (CellMaster.CellNo = CellStatus.CellNo) AND (CellMaster.[LineNo] = CellStatus.[LineNo])
GROUP BY CellMaster.[LineNo], CellMaster.CellNo
ORDER BY CellMaster.[LineNo], CellMaster.CellNo;
这个sql语句怎么转换成sql server里的sql,sql server里没有last()函数。
问题点数:100、回复次数:8Top
1 楼wgsasd311(自强不息)回复于 2006-02-27 16:22:54 得分 0
LAST()函数实现什么功能?Top
2 楼dulei115(前途无亮)回复于 2006-02-27 16:26:57 得分 0
min()?max()?Top
3 楼gesnpt(gesnpt)回复于 2006-02-27 17:08:10 得分 0
LAST()函数的功能是取最后一条记录Top
4 楼scmail81(琳·风の狼(修罗))回复于 2006-02-27 17:17:03 得分 50
try:
select CellMaster.[LineNo], CellMaster.CellNo,
(select top 1 StatusDate from CellMaster where CellMaster.CellNo = CellStatus.CellNo AND CellMaster.[LineNo] = CellStatus.[LineNo] order by StatusDate DESC) as StatusDate,
(select top 1 Status from CellMaster where CellMaster.CellNo = CellStatus.CellNo AND CellMaster.[LineNo] = CellStatus.[LineNo] order by StatusDate DESC) as Status
from CellMasterTop
5 楼libin_ftsafe(子陌红尘:TS for Banking Card)回复于 2006-02-27 17:22:28 得分 50
没有直接对应的功能,可以借助临时表实现:
select identity(int,1,1) as id,* into #CellStatus from CellStatus
select
a.LineNo,a.CellNo,b.StatusDate as [Date],b.Status
from
CellMaster a
left join
#CellStatus b
on
a.CellNo=b.CellNo and a.LineNo=b.LineNo
and
not exists(select 1 from #CellStatus where CellNo=b.CellNo and LineNo=b.LineNo and id>b.LineNo)Top
6 楼weinickli(总有路,总没走)回复于 2006-02-27 17:27:13 得分 0
学习一下Top
7 楼gesnpt(gesnpt)回复于 2006-02-27 17:40:58 得分 0
有没有方法用用户自定义函数直接实现access里的LAST()这个函数Top
8 楼yyjzsl(阿木)回复于 2006-02-27 22:31:00 得分 0
偶也来学习下.Top




