日期:2014-05-17  浏览次数:20395 次

小菜鸟SQL语句问题希望大家帮忙
 先输出产品ID为20的产品 然后在输出其他产品 显示方式产品ID为20的在前面显示其他产品按照排序显示 

 例如:点击类别电脑 先输出所有电脑产品然后输出电脑周边的一些产品如鼠标键盘等。。按照ID大小排序出来
 
 但是电脑显示在最前面
 

------最佳解决方案--------------------
order by case when id=20 then 0 else 1 end,id
------其他解决方案--------------------
declare @参数 nvarchar(20)
exec ('select * from product where classid='+@参数+'  order by case when classid='+@参数+' then 0 else 1 end,classid')

------其他解决方案--------------------
order by case when id=20 then 1 else 2 end,id


------其他解决方案--------------------
引用:
引用:
order by case when id=20 then 1 else 2 end,id

如果是这样怎么写 输出产品Id=20的在前面显示 其他则按照ID大小在后面显示 但是后面显示不要包括ID=20的产品了
你要显示两次ID=20的数据?
------其他解决方案--------------------
如果你指定是20在第一行,那就:
select * from xxx where id=20
union all 
select * 
from xxx

------其他解决方案--------------------
引用:
先输出产品ID为20的产品 然后在输出其他产品 显示方式产品ID为20的在前面显示其他产品按照排序显示 

 例如:点击类别电脑 先输出所有电脑产品然后输出电脑周边的一些产品如鼠标键盘等。。按照ID大小排序出来
 
 但是电脑显示在最前面





"select * from product where classid="&classid&"  order by case when classid="&classid&" then 0 else 1 end,classid"

我这样写的对吗 输出没结果

------其他解决方案--------------------
引用:
order by case when id=20 then 0 else 1 end,id


我这样写的对吗? 输出没结果



"select * from product where classid="&classid&"  order by case when classid="&classid&" then 0 else 1 end,classid"


------其他解决方案--------------------
引用:
declare @参数 nvarchar(20)
exec ('select * from product where classid='+@参数+'  order by case when classid='+@参数+' then 0 else 1 end,classid')


ASP开发 我按照你写的也是没有输出。可能是我太笨了 


<%
 classid = request("classid")
set rsx=server.createobject("adodb.recordset")
sqlx="select * from product where classid='&classid&'  order by case when classid='&classid&' then 0 else 1 end,classid"
rsx.open sqlx,conn,1,1
if not rsx.eof then
  %>

------其他解决方案--------------------
引用:
order by case when id=20 then 1 else 2 end,id