0

在我的 sql 表中,我有一些数据如下,

ItamName
-----
Småsenter (Sandvika Småsenter)
Brilleland
Game
Name It

我写了如下查询,

SELECT 
(Select I.ItamName from  ItemMaster I where I.ItemId=A.ItemName and I.LanguageId='no' 
and I.SiteId='sandvikas') as elementname,
sum(clicks) as click from Analytics A
where ItemType='Shop' and DateOfEvent >='2013-10-01' and DateOfEvent<='2013-10-31' 
and SiteName='sandvikas'
group by ItemName order by click desc, ItemName Asc  FOR XML RAW('Table'),ROOT('NewDataSet')

这给了我输出

<NewDataSet>
  <Table elementname="Brilleland" click="2" />
  <Table elementname="Name It" click="2" />
  <Table elementname="Småsenter (Sandvika Småsenter)" click="1" />
  <Table elementname="Game" click="1" />
</NewDataSet>

数据中也有一些特殊字符。我希望我的 xml 数据按字母顺序排列如下,

<NewDataSet>
  <Table elementname="Brilleland" click="2" />
<Table elementname="Game" click="1" />
  <Table elementname="Name It" click="2" />
  <Table elementname="Småsenter (Sandvika Småsenter)" click="1" />
</NewDataSet>

问候桑吉塔

4

1 回答 1

2

如查询中所述,您的 ORDER BY 将首先按单击排序,然后按 ItemName。如果您希望它反转,请反转 ORDER BY:

ORDER BY ItemName ASC, click DESC

于 2013-10-31T14:34:03.053 回答