declare @maxdate datetime
select @maxdate = max(ApplyDate) from dbo.Apply where DepartmentName = '生产部'
select ApplyNumber from dbo.Apply where DepartmentName = '生产部' and ApplyDate = @maxdate如何把上面两个查询语句合并为一条查询语句???
select @maxdate = max(ApplyDate) from dbo.Apply where DepartmentName = '生产部'
select ApplyNumber from dbo.Apply where DepartmentName = '生产部' and ApplyDate = @maxdate如何把上面两个查询语句合并为一条查询语句???
解决方案 »
- 如何将in改成exists
- 我先安装了vs2005 附带安装了sql express,现在安装sql develop,在线等
- 如何从excel导入数据到sqlserver的表中,并按id更新该表中的信息?
- 解决了,马上给分100,绝对不延期
- 财务收费系统的日志存储表设计?
- 导出的数据库中,数据表字段设置的“标识”变成“否”了,有什么办法保存这些设置?
- 大家新年好!我有一个问题请教:我想每天4点钟系统自动执行一个存储过程abc,那要怎么做?
- 索引问题,这种数据库加索引合适吗?
- 查找某个字符在字符串中第N次出现的位置
- 如何在程序中用代码实现sql数据库的数据备份,恢复?
- 简单查询语句?
- SQL Server 2005 为什么不能导入 Access
select ApplyNumber from dbo.Apply where DepartmentName = '生产部' and ApplyDate =
(select max(ApplyDate) from dbo.Apply where DepartmentName = '生产部')----方法2:
select ApplyNumber from dbo.Apply where DepartmentName = '生产部' and ApplyDate =
(select top 1 ApplyDate from dbo.Apply where DepartmentName = '生产部' order by ApplyDate DESC)----方法3:
select ApplyNumber from dbo.Apply as a where DepartmentName = '生产部' and
not exists(select 1 from dbo.Apply where DepartmentName = '生产部' and ApplyDate > a.ApplyDate)