SQL数据库中,创建一个视图,怎么把前面原始表中的数据呈现出后面的格式呢? 20
3个回答
展开全部
把tableName换成你的表名。数据库必须是sql2005或以上版本。
下面见证神一样的SQL:
SELECT
(
select stb from (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName) as c where c.id = (
select MAX(b.id)
from (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName) as b
where b.id< aa.id and SUBSTRING(stb,0,2)='#')
) as 客户编号 ,aa.stb as 货号
FROM (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName)as aa
where substring(stb,0,2) <> '#'
下面见证神一样的SQL:
SELECT
(
select stb from (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName) as c where c.id = (
select MAX(b.id)
from (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName) as b
where b.id< aa.id and SUBSTRING(stb,0,2)='#')
) as 客户编号 ,aa.stb as 货号
FROM (SELECT ROW_NUMBER() over(order by getdate()) as id,* FROM tableName)as aa
where substring(stb,0,2) <> '#'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |