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
. It can be assumed that there will always be at least two rows containing the same id_customer
.
我有一个表,我想从中提取所有行的所有列值。但是,查询需要能够跳过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.
如果需要更多信息/更好的解释,请告诉我,我希望它是一个安静的利基解决方案。
1 个解决方案
#1
3
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)
.
如果您的数据很大,则需要购物车上的索引(id_customer,date)。
#1
3
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)
.
如果您的数据很大,则需要购物车上的索引(id_customer,date)。