sql的union使用问题
麻烦大虾看一下代码,,运行union 报错是怎么回事啊
insert into caogen(id,no,tittle,author,contents)
select top 158 * from _TangSi
where Author not in( select Author from huangjia)and Author<>'无名氏' order by NEWID()
union
select * from _TangSi where Author='无名氏'
[解决办法]
分成两句... 要不你说说报错是啥吧。
[解决办法]
order by NEWID() 不能加order by 改下就可以了
insert into caogen(id,no,tittle,author,contents)
select * from (select top 158 * from _TangSi
where Author not in( select Author from huangjia)and Author<>'无名氏' order by NEWID() ) a
union
select * from _TangSi where Author='无名氏'
insert into caogen(id,no,tittle,author,contents)
select * from (select top 158 * from _TangSi
where Author not in( select Author from huangjia)and Author<>'无名氏' union
select * from _TangSi where Author='无名氏')as t order by NEWID()
with cte
as
(
select top 158 * from _TangSi
where Author not in( select Author from huangjia)and Author<>'无名氏' order by NEWID()
)
insert into caogen(id,no,tittle,author,contents)
select * from cte
union
select * from _TangSi where Author='无名氏'
select * from (select top 158 * from _TangSi
where Author not in( select Author from huangjia)and Author<>'无名氏' union
select * from _TangSi where Author='无名氏')as t order by NEWID()