我有一张这样的表:
id package start_date option
1 342323 2012-02-02 1
2 3423333 2012-02-06 1
3 552234 2012-02-14 2
我只想选择(top 1)
。{/ p>的minimum start_date
行
我尝试了where start_date = MIN(start_date)
,但它无效。
我正在使用SQL Server 2008。
答案 0 :(得分:4)
select top 1 * from table
order by start_date
答案 1 :(得分:1)
对于Sql server
select top 1 * from tbl_name order by start_date
对于Mysql
select * from tbl_name order by start_date asc limit 1
答案 2 :(得分:1)
尝试:
where start_date = (select min(start_date) from yourtable)
答案 3 :(得分:1)
SELECT * FROM myTable
ORDER BY start_date ASC
LIMIT 1
答案 4 :(得分:1)
SELECT * from Yourtable
WHERE start_date = (SELECT (Min(yt1.Start_Date) FROM YourTable as yt1)
答案 5 :(得分:1)
对于MSSQL
select top 1 * from your_table order by start_date asc
答案 6 :(得分:0)
此SQL Server特定的查询应该可以获得所需的数据。试试这个:
select top 1 * from tbl_name order by start_date asc
答案 7 :(得分:0)
你也可以使用:
;With top_record as
(
SELECt *
,row_number() OVER (order by start_date ASC) as row
FROM yourtable
)
SELECT * from top_record WHERE row = 1
这样,您就可以灵活地使用DENSE_RANK / RANK而不是ROW_NUMBER()来确定如何处理关系