如何使用两个不同的列mySQL从查询中获取数据而不是在其他查询中?

时间:2015-08-30 10:34:07

标签: mysql database mysql-workbench

我尝试进行该查询,但由于错误1241我无法使用NOT IN超过1列,并且我无法在NOT IN之前使用两个atribut。

SELECT * FROM futbol.puntos WHERE Equipo, Liga
NOT IN
(SELECT  der.Equipo,der.Liga,der.Puntos 
FROM (SELECT p.Equipo, p .Liga, p.Puntos,
    IF(@prev_liga != p.Liga,
        @rownum:= 1,
        @rownum := @rownum + 1) rank,
    @prev_liga:=p.Liga
FROM (SELECT Equipo, Liga, Puntos FROM puntosmitadliga GROUP BY Liga, Puntos, Equipo ORDER BY Liga, Puntos DESC) p, 
     (SELECT
            @rownum:= NULL,
            @prev_liga := 0) r) der WHERE der.rank <= 3 ORDER BY der.Liga, der.rank) GROUP BY Liga HAVING max(puntos);

我该如何解决?

1 个答案:

答案 0 :(得分:0)

SELECT * FROM my_table;
+----------------+-------------+
| customerNumber | orderNumber |
+----------------+-------------+
|             40 |           1 |
|             30 |           2 |
|             40 |           3 |
|             20 |           4 |
|             30 |           5 |
+----------------+-------------+

SELECT * 
  FROM my_table 
 WHERE (customernumber,ordernumber) NOT IN ((40,1),(30,3));
+----------------+-------------+
| customerNumber | orderNumber |
+----------------+-------------+
|             30 |           2 |
|             40 |           3 |
|             20 |           4 |
|             30 |           5 |
+----------------+-------------+
4 rows in set (0.07 sec)

mysql>