Mam 2 tabele items i players:
Kod
player_depotitems
+------------+---------+------+-----+---------+-------+
| Field      | Type    | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| player_id  | int(11) | NO   | PRI | NULL    |       |
| itemtype   | int(11) | NO   |     | NULL    |       |
+------------+---------+------+-----+---------+-------+

players:
+------------+---------+------+-----+---------+-------+
| Field      | Type    | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| id  | int(11) | NO   | PRI | NULL    | auto_increment |
| name| int(11) | NO   |     | NULL    |       |
+------------+---------+------+-----+---------+-------+


I teraz chciałbym z tabeli items wybrać te player_id, dla których liczba rekordów z itemtype = 10 jest większa od 400. Ktoś ma jakiś pomysł? Kombinuje z różnymi podzapytaniami ale nie bardzo mi to wychodzi niestety :/



edit: okazało się to banalnie proste:
  1. SELECT DISTINCT name FROM players AS a LEFT JOIN player_depotitems AS b ON a.id=b.player_id WHERE (SELECT count(*) FROM player_depotitems WHERE itemtype=10 AND player_id=a.id) > 400;


Można zablokować czy co tam smile.gif