简体   繁体   English

选择具有不同值的行

[英]Selecting rows which have different values

I want to select rows which have 10 different soru_id from end of the table. 我想选择表末尾有10个不同的soru_id的行。 It has to return only red marked rows. 它必须仅返回带有红色标记的行。 Table structure and red marked rows are in picture below. 表结构和带有红色标记的行如下图所示。 How can i do it? 我该怎么做?
http://i47.tinypic.com/2132iir.jpg http://i47.tinypic.com/2132iir.jpg

Assuming the soru_id decides the beginning/end of the table 假设soru_id决定表的开始/结束

Try this: 尝试这个:

SELECT DISTINCT soru_id
  FROM <YOUR_TABLE>
 ORDER BY date_created DESC 
 LIMIT 10;

In case you need the full row instead of soru_id alone. 如果您需要整行而不是单独的soru_id。 then try this: 然后试试这个:

SELECT *
FROM <YOUR_TABLE> a
JOIN
  ( SELECT soru_id,
           MAX(date_created) date_created
   FROM <YOUR_TABLE>
   GROUP BY soru_id LIMIT 10) b ON a.soru_id = b.soru_id
AND a.creation_date = b.creation_date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM