2016-02-05 43 views
1
SELECT det.tag_id,det.category_id,det.subcategory_id,det.event_id,dt.tag_name 
FROM `do_experience_tags` det 
INNER JOIN `do_category` dc ON (det.subcategory_id=dc.`category_id` AND dc.is_master_category=1) 
INNER JOIN do_tags dt ON (det.tag_id=dt.tag_id) 

tagid catid  subcatid event_id  tag_name 
174  4   25   2   #music 
174  4   25   1   #music 

如何獲得相同的標記名稱的數量在新列得到算我的標籤出現在MySQL查詢

回答

2

使用count功能:

SELECT det.tag_id, count(*) 
    FROM `do_experience_tags` det 
    INNER JOIN `do_category` dc ON  
    (det.subcategory_id=dc.`category_id` AND  
    dc.is_master_category=1) 
    INNER JOIN do_tags dt ON (det.tag_id=dt.tag_id) 
GROUP BY det.tag_id 
0

,如果你想顯示count到每行然後你可以像下面這樣做

select t1.id,t1.detail, 
(select count(*) from t1 inner join t2 on t1.id =t2.id) as count 
from t1 
inner join t2 on t1.id =t2.id 

如果你想分組值使用分組