本节主要内容:
union查询与排序
sql代码:
复制代码 代码示例:
declare @mytable table
(
productId int,
bigClassId int,
aField int
) --
insert into @mytable
select top 10 productid,bigClassid,count(id)+sum(supportNum) as aField from tbcomments
group by productid,bigclassid order by aField desc
(select t.name,p.aField from tbTravel_Info t,@mytable as p where t.id=p.productid
union
select i.name,p.aField from tbAccident_Info i,@mytable as p where i.id=p.productid )
order by afield
附,replace替换text类型数据的例子。
replace函数处理text类型的数据,如下:
复制代码 代码示例:
update prolink set aimurl=replace(aimurl,'jb200.com.cn','jb200.com')
update linkarticle set contents=replace(CONVERT(varchar(8000), Contents),'jb200.com.cn','jb200.com')