简体   繁体   English

跳过每个唯一列值的行

[英]Skipping row for each unique column value

I have a table from which I would like to extract all of the column values for all rows. 我有一个表,我想从中提取所有行的所有列值。 However, the query needs to be able to skip the first entry for each unique value of id_customer . 但是,查询需要能够跳过id_customer每个唯一值的第一个条目。 It can be assumed that there will always be at least two rows containing the same id_customer . 可以假设总是至少有两行包含相同的id_customer

I've compiled some sample data which can be found here: http://sqlfiddle.com/#!9/c85b73/1 我编译了一些示例数据,可以在这里找到: http//sqlfiddle.com/#!9 / c85b73 / 1

The results I would like to achieve are something like this: 我想要实现的结果是这样的:

id_customer | id_cart | date
----------- | ------- | -------------------
1           | 102     | 2017-11-12 12:41:16
2           | 104     | 2015-09-04 17:23:54
2           | 105     | 2014-06-05 02:43:42
3           | 107     | 2011-12-01 11:32:21

Please let me know if any more information/better explanation is required, I expect it's quiet a niche solution. 如果需要更多信息/更好的解释,请告诉我,我希望它是一个安静的利基解决方案。

One method is: 一种方法是:

select c.*
from carts c
where c.date > (select min(c2.date) from carts c2 where c2.id_customer = c.id_customer);

If your data is large, you want an index on carts(id_customer, date) . 如果您的数据很大,则需要carts(id_customer, date)的索引carts(id_customer, date)

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

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