Create Computed Column using data from another table

后端 未结 5 729
忘掉有多难
忘掉有多难 2020-12-01 16:52

I have a SQL Server 2008 R2 database. This database has two tables called Pictures and PictureUse.

Picture table has the following columns:

Id (int)          


        
5条回答
  •  北海茫月
    2020-12-01 17:55

    This will work

    SELECT  P.id
            ,P.PictureName 
            ,COUNT(P.id) as [Count] 
            FROM Picture P
            INNER JOIN PictureUse PU 
            ON P.id=PU.Pictureid 
            GROUP BY P.id,P.PictureName 
    

提交回复
热议问题