当前位置:数据库 > SQLServer >>

(60分)SQL查询语句 access的能用,那MsSql应该怎么写?

这句asp查询语句:“select top 1 * from SMT_ypxxone (select top 1 * from SMT_ypxxone order by SMT_date desc) order by SMT_date” 在access数据库可以正常运行;MSSQL就asp超时 请问如上语句在MSSQL环境下怎么写?先行谢过~ 如能解决,请在:http://zhidao.zzzyk.com/question/123154990.html 回复一下,两个问题都给分(共60分)
答案:仅从语法上看:第一个from后面的SMT_ypxxone 去掉,给括号括起来的查询中间表取个别名
select top 1 * 
from (select top 1 * from SMT_ypxxone order by SMT_date desc) t
order by SMT_date
其他:为什么要套两个查询啊
子查询没意义啊?
楼主补充下问题!
倒序 找第一条记录 
可以用MAX() MIN() 函数的三 select top 1 * from SMT_ypxxone order by SMT_date desc

直接这样写就可以了。
MSSQL子查询里面是不能有order by 的。 不懂的不要误人子弟。
mssqlserver一样可以在子查询里用order by

下面说下楼主的问题。
你的语句应该是语法错误
select top 1 * from SMT_ypxxone (select top 1 * from SMT_ypxxone order by SMT_date desc) order by SMT_date

SMT_ypxxone是表名
(select top 1 * from SMT_ypxxone order by SMT_date desc)返回的也是一个数据集
只要在 中间加一个逗号分隔开就可以了 

上一个:请教一个MSSQL查询语句的问题
下一个:做wordpress博客网站。买没有Mssql/Mysql空间的主机可以吗?

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,