当前位置: 数据库>sqlserver
sql union查询与排序的例子
来源: 互联网 发布时间:2014-08-29
本文导语: 本节主要内容: 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,bi...
本节主要内容:
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
(
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,'.cn','')
update linkarticle set contents=replace(CONVERT(varchar(8000), Contents),'.cn','')
update linkarticle set contents=replace(CONVERT(varchar(8000), Contents),'.cn','')