?你说的是下面这种子查询么: select a.col1 from a where a.col2 in (select b.col2 from b order by b.col1); 这里是不能用order by,这种情况下的子查询,只是一个集合,不需要order by ;但是这种情况下的子查询可以用order by: select a.col1, b.col2 from a, (select c.col1 from c order by c.col1) b不知道你是需要order by的需求到底是什么样子的,是否可以通过其它的方法解决呢。
1): select @str=@str+Value+';' from ( select Value,[Order] from dbo.SMS_SpecialConfigData data join dbo.SMS_Config co on co.ItemID=data.ConfigID where Time='2008-5-12' and OrgCode='GZ/' order by [Order] )temp2): select @str=@str+Value+';' from ( select Value,[Order] from dbo.SMS_SpecialConfigData data join dbo.SMS_Config co on co.ItemID=data.ConfigID where Time='2008-5-12' and OrgCode='GZ/' )temp order by [Order]第一个出错,第二个又得不出想要的结果。但是这两个好像没什么区别啊?为什么
--2005的话试试 select @str=@str+Value+';' from ( select Value,[Order],row_number()over(order by Order )row_ from dbo.SMS_SpecialConfigData data join dbo.SMS_Config co on co.ItemID=data.ConfigID where Time='2008-5-12' and OrgCode='GZ/' )temp
select a.col1 from a where a.col2 in (select b.col2 from b order by b.col1);
这里是不能用order by,这种情况下的子查询,只是一个集合,不需要order by ;但是这种情况下的子查询可以用order by:
select a.col1, b.col2
from a,
(select c.col1 from c order by c.col1) b不知道你是需要order by的需求到底是什么样子的,是否可以通过其它的方法解决呢。
select @str=@str+Value+';'
from
(
select Value,[Order] from dbo.SMS_SpecialConfigData data
join dbo.SMS_Config co
on co.ItemID=data.ConfigID
where Time='2008-5-12' and OrgCode='GZ/'
order by [Order]
)temp2):
select @str=@str+Value+';'
from
(
select Value,[Order] from dbo.SMS_SpecialConfigData data
join dbo.SMS_Config co
on co.ItemID=data.ConfigID
where Time='2008-5-12' and OrgCode='GZ/'
)temp
order by [Order]第一个出错,第二个又得不出想要的结果。但是这两个好像没什么区别啊?为什么
--2005的话试试
select @str=@str+Value+';'
from
(
select Value,[Order],row_number()over(order by Order )row_ from dbo.SMS_SpecialConfigData data
join dbo.SMS_Config co
on co.ItemID=data.ConfigID
where Time='2008-5-12' and OrgCode='GZ/'
)temp