Maybe this (UNTESTED):
SELECT a."%album artist%" "Album Artist",
'[' || coalesce(a.date,'') || '] ' || a.album "Date - Album",
a.discnumber, a.title "Title"
FROM MediaLibrary a
JOIN (SELECT album, discnumber, "%album artist%"
FROM MediaLibrary
GROUP BY 1, 2, 3
HAVING count(*) <> max(CAST(totaltracks AS INTEGER))) b
ON a.album = b.album
AND a."%album artist%" = b."%album artist%"
AND a.discnumber = b.discnumber
ORDER BY a."%album artist%" COLLATE NaturalNoCase,
a.date, a.album, discnumber, tracknumber
Thanks, I had an error (see attached) with this above which I fixed with the below. But I notice there's no reference to tracknumber because it's not giving me the correct results.
SELECT a."%album artist%" "Album Artist",
'[' || coalesce(a.date,'') || '] ' || a.album "Date - Album",
a.discnumber "Disc Number", a.title "Title"
FROM MediaLibrary a
JOIN (SELECT album, discnumber, "%album artist%"
FROM MediaLibrary
GROUP BY 1, 2, 3
HAVING count(*) <> max(CAST(totaltracks AS INTEGER))) b
ON a.album = b.album
AND a."%album artist%" = b."%album artist%"
AND a.discnumber = b.discnumber
ORDER BY a."%album artist%" COLLATE NaturalNoCase,
a.date, a.album, a.discnumber, tracknumber