How to implement tag counting

前端 未结 4 1475
再見小時候
再見小時候 2021-02-03 13:46

I have my tags desinged like this in my database:

Table: Item 
Columns: ItemID, Title, Content 

Table: Tag 
Columns: TagID, Title 

Table: ItemTag 
Columns: Ite         


        
4条回答
  •  鱼传尺愫
    2021-02-03 14:22

    select t.Title, count(it.TagID) as TagCount
    from Tag t
      inner join ItemTag it on t.TagID = it.TagID
      inner join Item i on it.ItemID = i.ItemID
    where i.ItemID = @currentItemID -- optional, if you only want current page
    group by t.Title
    

提交回复
热议问题