请问 我用语句select A, B, C from employees
where employeeID = '10000'
去查询,现在是没有任何记录,但是我怎么表示如果无记录将任何记录都赋予0, 就是结果是------------------
A B C
0 0 0谢谢! 急~
where employeeID = '10000'
去查询,现在是没有任何记录,但是我怎么表示如果无记录将任何记录都赋予0, 就是结果是------------------
A B C
0 0 0谢谢! 急~
select count(*) from employees where employeeID = '10000'
if not exists(select * from employees
where employeeID = '10000') select 0,0,0
where employeeID = '10000' and year in (2001,2002,2003,2004)
去查询,现在是没有任何记录,但是我怎么表示如果无记录将任何记录都赋予0, 就是结果是------------------
year A B C
2001 1 2 3
2002 3 4 5但是现在 2003 和 2004 的数据都差不出来 所以我想给负值成0 既------------------
year A B C
2001 1 2 3
2002 3 4 5
2003 0 0 0
2004 0 0 0这样怎么搞呢?
在 left join 就出来了,在用 isnull (字段,0)
RIGHT JOIN (
SELECT 2001 'YE' UNION SELECT 2002 UNION SELECT 2003 UNION SELECT 2004
) T2 ON T1.[YEAR]=T2.YE
where employeeID = '10000' and year in (2001,2002,2003,2004)
select top1 from (
select A, B, C from employees
where employeeID = '10000'
union all
select 0,0,0 )
year A B C
2001 1 2 3
2002 3 4 5
2003 null null null
2004 null null null
结果是猜的