0

列の値を分割するのに助けが必要です。これが私がこれまでに得たものです

select
recordid, productname,
case when future06 like '%418%' then (Books
case when future06 like '%421%' then (Video) else null
end
from schema.dbo.table1

Booksとは、列Videoの下にある2つの主要な製品です。future063番目の列として持つ代わりに、とと一緒にとfuture06の両方を持ちたいと思います。BooksVideorecordidproductname

出力を次のように表示することはできますか?

RecordID   ProductName  Books   Video
4

2 に答える 2

0
select
recordid, productname,
case when future06 like '%418%' then future06 else null end as Books,
case when future06 like '%421%' then future06 else null end as Video
from schema.dbo.table1


select
recordid, productname,
COUNT(case when future06 like '%418%' then 1 else 0 end) as NoOfBooks,
COUNT(case when future06 like '%421%' then 1 else 0 end) as NoOfVideo
from schema.dbo.table1 
group by recordid, productname

select
recordid, productname,
COUNT(case when future06 like '%418%' then 1 else 0 end) as NoOfBooks,
COUNT(case when future06 like '%421%' then 1 else 0 end) as NoOfVideo, 
COUNT(*) as Total 
from schema.dbo.table1 
group by recordid, productname
于 2013-03-27T05:25:39.067 に答える
0

あなたはほとんどそれを持っていました:

select
    RecordID
    , ProductName
    , Books = case when future06 like '%418%' then future06 else null end
    , Video = case when future06 like '%421%' then future06 else null end
from
    schema.dbo.table1
于 2013-03-27T05:26:34.930 に答える