GROUP BY ステートメントを使用せずに、結合されたテーブルで COUNT を実行する方法はありますか? この結果を解析しているレガシー アプリケーションにこの SQL を挿入する必要がありますが、GROUP BY 部分を処理できません。
これは私が今持っているものです(SQLサーバーでは機能しますが、他のアプリでは機能しません):
SELECT TOP 10 au.pref_language,au.username,am.IsOpenIdAccount,am.facebookid,au.sex,au.firstname,au.middlename,au.lastname,am.email,
c.id AS objectid,c.title AS objecttitle,c.friendlyurl as objecturl,c.objecttype,am.CreateDate,c.description_nl,c.description_en,
COUNT(distinct ap.id) as totalphotos,
COUNT(distinct ar.id) as totalreviews,
COUNT(distinct fm.id) as totalfreemedia
FROM locations c
INNER JOIN aspnet_users au on au.UserId=c.userid
INNER JOIN aspnet_membership am ON am.userid=au.userid
LEFT JOIN location_photos ap on ap.objectid=c.id
LEFT JOIN location_reviews ar on ar.objectid=c.id
LEFT JOIN freemedia fm on fm.objectid=c.id AND fm.objecttype=c.objecttype
WHERE c.title<>''
GROUP BY au.pref_language,au.username,am.IsOpenIdAccount,am.facebookid,au.sex,au.firstname,au.middlename,au.lastname,am.email,
c.id ,c.title ,c.friendlyurl ,c.objecttype,am.CreateDate,c.description_nl,c.description_en
そして、私はこのようなものが必要です:
SELECT TOP 10 au.pref_language,au.username,am.IsOpenIdAccount,am.facebookid,au.sex,au.firstname,au.middlename,au.lastname,am.email,
c.id AS objectid,c.title AS objecttitle,c.friendlyurl as objecturl,c.objecttype,am.CreateDate,c.description_nl,c.description_en,
COUNT(distinct ap.id) as totalphotos,
COUNT(distinct ar.id) as totalreviews,
COUNT(distinct fm.id) as totalfreemedia
FROM locations c
INNER JOIN aspnet_users au on au.UserId=c.userid
INNER JOIN aspnet_membership am ON am.userid=au.userid
LEFT JOIN location_photos ap on ap.objectid=c.id
LEFT JOIN location_reviews ar on ar.objectid=c.id
LEFT JOIN freemedia fm on fm.objectid=c.id AND fm.objecttype=c.objecttype
WHERE c.title<>''