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是列下的两个主要产品future06。而不是future06作为第三列,我想同时拥有Booksand和.Videorecordidproductname

生活会让输出看起来像:

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 回答