Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择2个最新的“选项”;“组/批次”;表中的记录_Mysql_Sql_Select - Fatal编程技术网

Mysql 选择2个最新的“选项”;“组/批次”;表中的记录

Mysql 选择2个最新的“选项”;“组/批次”;表中的记录,mysql,sql,select,Mysql,Sql,Select,我有如下mysql表中的数据: id customer_id int_proc 1 A 1 2 A 4 3 A 5 4 A 5 5 A 5 6 A 5 7 B 6 8 B 7 9 B 9

我有如下mysql表中的数据:

id  customer_id  int_proc
1   A               1
2   A               4
3   A               5
4   A               5
5   A               5
6   A               5
7   B               6           
8   B               7
9   B               9
10  B               9
10  B               9
11  C               22
我想从最新的2个int_proc值中获取所有数据,其中customer_id是A和B

我的结果应该是这样的:

id  customer_id  int_proc
2   A               4
3   A               5
4   A               5
5   A               5
6   A               5
8   B               7
9   B               9
10  B               9
非常感谢您的帮助

SELECT  t.ID 
       ,t.Customer_id
       ,t.Int_Proc
FROM TestTable t 
LEFT JOIN (  SELECT Customer_Id , MIN(Int_Proc) as Int_Proc
             FROM TestTable
             GROUP BY Customer_Id )r
ON t.customer_id  = r.customer_id  
AND t.int_proc = r.int_proc
WHERE r.customer_id IS NULL AND r.int_proc IS NULL

谢谢但它真的有效吗?我刚刚添加/修改了一些B部分,它返回了B的更多(全部)结果,而不是最新的2个。事实上,这不是一个“可能的重复”-这是一个直接的问题:OP没有更新这个问题的细节,而是打开了另一个问题(得到了回答)。