sql语句的问题.

我有这样一张表
--------
author song
john yestody once more
john null
john null
wubai luo wei d shenglin
wubai null
wubai null
问题: 将作者的几个歌曲(如果是NULL)都变成第一首歌的名字。
[215 byte] By [wh_xiexing-谢兴] at [2008-1-9]
# 1
补充, 其中 athor 和 song 是字段名
wh_xiexing-谢兴 at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...
# 2
--try ...
--table's name is tbl .
select auther ,case when song is null then (select top 1 song from tbl where song
is not null and auther =a.auther order by song ) else song end as [song]
from tbl a
xiaoku-野蛮人-v at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...
# 3
select a.author, a.song case when null then b.song end from table a, (select author, distinct(song) as song from table where song is not null group by author) b where a.author = b.author
Elysium-東鱗覀爫 at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...
# 4
用表变量@ta测试:--(把@ta变为表名就行了)
declare @ta table (author varchar(10), song varchar(30))
insert @ta
select 'john', 'yestody once more'
union all select 'john', null
union all select 'john', null
union all select 'wubai', 'luo wei d shenglin'
union all select 'wubai', null
union all select 'wubai', null

select author,
song=case when song is null then (select top 1 song from @ta where author=a.author)else song end
from @ta a

(所影响的行数为 6 行)

author song
---------- ------------------------------
john yestody once more
john yestody once more
john yestody once more
wubai luo wei d shenglin
wubai luo wei d shenglin
wubai luo wei d shenglin

(所影响的行数为 6 行)

# 5
不好意思啊, 我是财鸟, 哪位大哥给讲解一下select auther ,case when song is null then (select top 1 song from tbl where song
is not null and auther =a.auther order by song ) else song end as [song]
from tbl a
这个语句中的case when 是什么语句, 如何用啊?
wh_xiexing-谢兴 at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...
# 6
条件判断,如果song的值是null的话从tb1取出第一个符合条件的值作为song的值,否则(不为空)用song的值作为列的值.
# 7
case when是条件语句,看联机帮助嘛,野蛮人的语句应该比我那效率高
Elysium-東鱗覀爫 at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...
# 8
case when

-------------
简洁点的case when 相当于 C里面的 (?:)

xiaoku-野蛮人-v at 2007-10-18 > top of Msdn China Tech,MS-SQL Server,基础类...