如何根据SQL Server中的其他列显示结果

时间:2015-10-11 14:41:30

标签: sql sql-server

如何根据另外两列显示一列中的改进或减少

select * from tbl_employee where empid='77' and age> 30 

如果天目标 - 提交的链接大于1,则应显示未到达,反之亦然。达到/未达到性能而不是显示数字

1 个答案:

答案 0 :(得分:0)

您可以使用case

select c.Categoryname, DayTarget, l.LnkSubmsnDate, l.LnkSubmtdBy,
       COUNT(LinkId) as submittedLinks,
       (DayTarget - COUNT(LinkId)) as performance,
       (case when DayTarget > COUNT(LinkId) then 'NotReached'
             else 'Reached'
        end) as MadeIt
from tbl_Link l left join
     Tbl_DaySubmission ds
     on l.ProjectId = ds.projectid and l.CategoryId = ds.CatId left join
     tbl_Category c
     on l.CategoryId = c.CategoryId
where LnkSubmsnDate = '2015-10-10' and l.ProjectId = '109'
group by c.Categoryname, ds.DayTarget, LnkSubmsnDate, l.LnkSubmtdBy;

如果您不想要实际的号码,请删除performance列。