如何在SYBASE中提取小日期记录
我正在使用以下查询;
select count(id) as total,
convert(date, my_dte, 101) as new_dte
from my_table
where convert(date, my_dte, 101) between '05/01/2014' and '05/31/2014'
group by convert(date, my_dte, 101)
order by convert(date, my_dte, 101)这是这个查询的输出
**total new_dte**
73 05/02/2014
14 05/06/2014
90 05/19/2014
36 05/21/2014我只想得到最小的约会记录。我正在使用这个查询;
select max_rec.total
from
(
select count(id) as total,
convert(date, my_dte, 101) as new_dte,
ROW_NUMBER () OVER(PARTITION BY total ORDER BY new_date DESC ) as rn
from my_table
where convert(date, my_dte, 101) between '05/01/2014' and '05/31/2014'
group by convert(date, my_dte, 101)
order by convert(date, my_dte, 101)
) max_rec
where max_rec.rn = 1;但这不起作用,这让我在而不是上出错。
期望输出:
**total new_dte**
73 05/02/2014任何帮助都将是学徒。
发布于 2014-05-09 23:09:14
你能不能
将原始查询包装为子查询。
创建另一个带最小日期值的子查询
对两个子查询执行内部连接,以从匹配所需日期的原始查询中获取记录。
https://stackoverflow.com/questions/23548492
复制相似问题