sql语句的问题.
我有这样一张表
--------
author song
john yestody once more
john null
john null
wubai luo wei d shenglin
wubai null
wubai null
问题: 将作者的几个歌曲(如果是NULL)都变成第一首歌的名字。
--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
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
用表变量@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 行)
不好意思啊, 我是财鸟, 哪位大哥给讲解一下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 是什么语句, 如何用啊?