下面我有一段代码,我一直在努力打印两列的内容:FILE_DATE_PROCESSED和DATE_ENTERED。我只想要前两行。例如,这是我到目前为止的查询结果:
FILE_DATE_PROCESSED DATE_ENTERED
2015-12-31 19:32:45.000 2015-06-09 14:26:35.180
2015-12-31 19:32:45.000 2015-06-09 14:26:34.360
2015-12-31 19:32:45.000 2015-06-09 14:26:35.180
2015-12-31 19:32:45.000 2015-06-09 14:46:16.350
2015-12-31 19:32:45.000 2015-06-09 15:00:01.870
2015-12-31 19:32:45.000 2015-06-09 15:00:03.823
2015-12-31 19:32:45.000 2015-06-09 15:00:03.403
2015-12-31 19:32:45.000 2015-06-09 15:59:11.583
2015-12-31 19:32:45.000 2015-06-09 14:47:07.900
2015-12-31 19:32:45.000 2015-06-09 14:58:19.110
2015-12-31 19:32:45.000 2015-06-09 14:20:09.023
2015-12-31 19:32:45.000 2015-06-09 15:42:25.887
2015-12-31 19:32:45.000 2015-06-09 14:26:35.850
2015-12-31 19:32:45.000 2015-06-09 15:00:02.840
2015-12-31 19:32:45.000 2015-06-09 14:58:19.773
2015-12-31 19:32:45.000 2015-06-09 14:41:09.040
2015-12-31 19:32:45.000 2015-06-09 14:41:09.040
2015-12-31 19:32:45.000 2015-06-09 14:58:18.250
2015-12-31 19:32:45.000 2015-06-09 14:41:16.877
这是我想要的结果:
FILE_DATE_PROCESSED DATE_ENTERED
2015-12-31 19:32:45.000 2015-06-09 14:26:35.180
语法很可能非常简单,但由于我对SQL很新,我对实际语法有点不确定。以下是我正在处理的查询:
SELECT FILE_DATE_PROCESSED, DATE_ENTERED FROM FILE_DATE_PROCESSED
答案 0 :(得分:2)
您可以在要在mysql中显示的n行中更改1。
SELECT FILE_DATE_PROCESSED, DATE_ENTERED FROM FILE_DATE_PROCESSED LIMIT 1
将第二个用于SQL Server
SELECT TOP 1 FILE_DATE_PROCESSED, DATE_ENTERED FROM FILE_DATE_PROCESSED
答案 1 :(得分:1)
您的代码不清楚,但如果这是sql server,请使用:
SELECT top 1 FILE_DATE_PROCESSED, DATE_ENTERED FROM FILE_DATE_PROCESSED
可选:添加order by
以确保获得所需的行; e.g:
SELECT top 1 FILE_DATE_PROCESSED, DATE_ENTERED
FROM FILE_DATE_PROCESSED
order by DATE_ENTERED
编辑添加:
如果您想要最后输入的行,请使用:
SELECT top 1 FILE_DATE_PROCESSED, DATE_ENTERED
FROM FILE_DATE_PROCESSED
order by DATE_ENTERED desc
添加desc
告诉SQL按最新的date_entered
列对结果进行排序,然后选择最前一行(例如最新一行)。