Ich habe eine BLOB-Spalte, die ich gleichzeitig mit einer anderen Spalte auswählen möchte, und eine COUNT der Anzahl der zugeordneten Zeilen in einer anderen Tabelle. Hier ist, was ich habe:eindeutige Zeilen mit COUNT und einer BLOB-Spalte - DB2
SELECT locations.id, locations.name, photo,
COUNT(items.id) OVER (PARTITION BY locations.id) AS num_items
FROM locations
LEFT OUTER JOIN items ON locations.id = items.location_id
ORDER BY locations.name ASC
photo
ist die BLOB-Spalte. Diese Abfrage wird alle Daten, die ich will, aber ich sehe x Zeilen für jeden location
, wo x ist die Anzahl der item
Reihen im Zusammenhang mit diesen location
.
Also ich bin immer:
id name photo num_items
1 location1 3
1 location1 3
1 location1 3
2 location2 1
3 location3 2
3 location3 2
4 location4 0
Was ich will:
id name photo num_items
1 location1 3
2 location2 1
3 location3 2
4 location4 0
Das Problem ist, dass Sie nicht DISTINCT
tun können, GROUP BY
oder MIN
auf einer BLOB
Spalte.