mysqlテーブルに次のテーブルがあります
a_ad_display
╔═══════╦══════════╗
║ ADVID ║ ADTYPEID ║
╠═══════╬══════════╣
║ 1 ║ 1 ║
║ 2 ║ 1 ║
║ 3 ║ 4 ║
║ 3 ║ 3 ║
║ 2 ║ 2 ║
║ 1 ║ 4 ║
║ 1 ║ 3 ║
║ 4 ║ 1 ║
║ 4 ║ 1 ║
╚═══════╩══════════╝
a_mediatype
╔═════════╦═══════════╗
║ MEDIAID ║ MEDIANAME ║
╠═════════╬═══════════╣
║ 1 ║ Animation ║
║ 2 ║ video ║
║ 3 ║ Image ║
╚═════════╩═══════════╝
a_ad_type
╔══════════╦════════╗
║ ADTYPEID ║ ADTYPE ║
╠══════════╬════════╣
║ 1 ║ e Ad ║
║ 2 ║ b Ad ║
║ 3 ║ c Ad ║
║ 4 ║ d Ad ║
╚══════════╩════════╝
a_advertise
╔═══════╦═════════╗
║ ADVID ║ MEDIAID ║
╠═══════╬═════════╣
║ 1 ║ 1 ║
║ 2 ║ 1 ║
║ 3 ║ 2 ║
║ 4 ║ 3 ║
╚═══════╩═════════╝
今私がフェッチしたいのは次のとおりです...
adType | Image | video | Animation
eAd | 0 | 2 | 2 ...
b Ad |...
c Ad |...
d Ad |.....
そして、すべてのアドタイプについて賢明なように、私はデータが欲しいです..誰かがこれについて私を案内してくれますか...
これは私が試したものです...
SELECT Distinct
at.adtype,
COUNT(IF(am.medianame = 'Animation',1,0)) AS Animation,
COUNT(IF(am.medianame = 'Video',1,0)) AS Video,
COUNT(IF(am.medianame = 'Image',1,0)) AS Image
FROM a_ad_type as at
LEFT JOIN a_ad_display as ad ON at.adtypeId = ad.adtypeId
LEFT JOIN a_advertise as adv ON adv.advertiseId = ad.advId
LEFT JOIN a_mediatype as am ON am.mediaId = adv.mediaTypeId
GROUP BY at.adtype