0

I tried to do that query but it doesn't work because of the error 1241 I can't use NOT IN with more than 1 column and I can't use two atributtes before the NOT IN.

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);

How can I resolve it?

david
  • 407
  • 3
  • 11
  • Your query doesn't make much sense. `HAVING max(puntos)`, for instance, simply filters out all rows where the maximum value of `puntos` is zero or `NULL`. You should ask another question, provide sample data and desired results and explain what you are trying to do. – Gordon Linoff Aug 30 '15 at 12:53

1 Answers1

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>
Strawberry
  • 33,750
  • 13
  • 40
  • 57