一线光芒 2015-01-28 05:45 采纳率: 0%
浏览 1568

怎么用sql满足这个需求?

dbo.Brand(品牌)

图片说明

dbo.BrandAttention(品牌关注)

图片说明

现在有一个需求, 查询4个字段 其中3个字段是Brand表中的3个字段
KeyId, BrandName, BrandImage
最后一个字段需求是这样的:
这里一共有10个品牌, 如果当前品牌在BrandAttention表里被UserId为131的关注过,
ps: BrandAttention中出现相同的
则第4个字段的值为1, 否则第4个字段的值为0
最后查询效果为

图片说明

  • 写回答

3条回答 默认 最新

  • danielinbiti 2015-01-28 06:34
    关注

    select t.*,(select count(*) from BrandAttention where userid='131' and 关联字段=Brand.关联字段) as IsAttention from Brand

    评论

报告相同问题?