我有一個像下面這樣的表結構。我需要選擇User_Id =100
和User_sub_id = 1
和time_used = minimum of all
以及其中Timestamp
最高的那一行。我的查詢輸出結果如下:調試SQL查詢
US;1365510103204;NY;1365510103;100;1;678;
我的查詢看起來像這樣。
select *
from my_table
where CODE='DE'
and User_Id = 100
and User_sub_id = 1
and time_used = (select min(time_used)
from my_table
where CODE='DE'
and User_Id=100
and User_sub_id= 1);
這將返回所有4行。我只需要1個時間戳最高的那個。 非常感謝
CODE: Timestamp: Location: Time_recorded: User_Id: User_sub_Id: time_used
"US;1365510102420;NY;1365510102;100;1;1078;
"US;1365510102719;NY;1365510102;100;1;978;
"US;1365510103204;NY;1365510103;100;1;878;
"US;1365510102232;NY;1365510102;100;1;678;
"US;1365510102420;NY;1365510102;100;1;678;
"US;1365510102719;NY;1365510102;100;1;678;
"US;1365510103204;NY;1365510103;100;1;678;
"US;1365510102420;NY;1365510102;101;1;678;
"US;1365510102719;NY;1365510102;101;1;638;
"US;1365510103204;NY;1365510103;101;1;638;
您正在使用哪些DBMS? Postgres的?甲骨文? – 2013-05-03 12:21:09
@a_horse_with_no_name。 Postgres – 2013-05-03 12:24:07