高难度问题----这个SQL怎么写?

java_xzy 2004-08-03 10:47:05
select Product_No,Product_Id,Product_Name,Class_1,Class_2,Product_Intro,Product_Show,P_NewPrice,P_OldPrice,P_Pic,P_Full_Pic,RegTime,Look_Count,p_flag,sum(px1),sum(px2),sum(px3),sum(px4),sum(px5) from view_103730382500180 group by Product_No,Product_Id,Product_Name,Class_1,Class_2,Product_Intro,Product_Show,P_NewPrice,P_OldPrice,P_Pic,P_Full_Pic,RegTime,Look_Count,p_flag order by sum(px5) desc,sum(px1) desc,sum(px3) desc,sum(px4) desc,RegTime desc

本来是ACCESS下运行的。 现在转到SQLSERVER 执行却报告
服务器: 消息 306,级别 16,状态 2,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
服务器: 消息 306,级别 16,状态 1,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
服务器: 消息 306,级别 16,状态 1,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
服务器: 消息 306,级别 16,状态 1,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。
服务器: 消息 306,级别 16,状态 1,行 1
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符。


那个视图的写法是:
CREATE VIEW view_103730382500180 AS (select *,(px1 + px2 + px3 + px4) as px5 from (select *,case when charindex('去印',Product_Name)>0 then 90 else 0 end as px1,case when charindex('去印',class_1)>0 or charindex('去印',class_2)>0 then 2 else 0 end as px2,case when charindex('去印',Product_Intro)>0 then 20 else 0 end as px3,case when charindex('去印',product_show)>0 then 10 else 0 end as px4 from Product where (Product_Name like '%去印%' or class_1 like '%去印%' or class_2 like '%去印%' or Product_Intro like '%去印%' or product_show like '%去印%') and shopid=1 and isnull(p_flag,0)<>5) as tableA )UNION all(select *,(px1 + px2 + px3 + px4) as px5 from (select *,case when charindex('去',Product_Name)>0 then 4 else 0 end as px1,case when charindex('去',class_1)>0 or charindex('去',class_2)>0 then 1 else 0 end as px2,case when charindex('去',Product_Intro)>0 then 3 else 0 end as px3,case when charindex('去',product_show)>0 then 2 else 0 end as px4 from Product where (Product_Name like '%去%' or class_1 like '%去%' or class_2 like '%去%' or Product_Intro like '%去%' or product_show like '%去%') and shopid=1 and isnull(p_flag,0)<>5) as tableB )UNION all(select *,(px1 + px2 + px3 + px4) as px5 from (select *,case when charindex('印',Product_Name)>0 then 4 else 0 end as px1,case when charindex('印',class_1)>0 or charindex('印',class_2)>0 then 1 else 0 end as px2,case when charindex('印',Product_Intro)>0 then 3 else 0 end as px3,case when charindex('印',product_show)>0 then 2 else 0 end as px4 from Product where (Product_Name like '%印%' or class_1 like '%印%' or class_2 like '%印%' or Product_Intro like '%印%' or product_show like '%印%') and shopid=1 and isnull(p_flag,0)<>5) as tableB )
...全文
161 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunjiujiu 2004-08-03
  • 打赏
  • 举报
回复
你的desc就是排序了啊
java_xzy 2004-08-03
  • 打赏
  • 举报
回复
但是我没有排序text、ntext 和 image 类型的数据 啊
skyboy0720 2004-08-03
  • 打赏
  • 举报
回复
不能比较或排序 text、ntext 和 image 数据类型,除非使用 IS NULL 或 LIKE 运算符
-->
已经写得很详细了嘛!
zorou_fatal 2004-08-03
  • 打赏
  • 举报
回复
可以在order by 或者group by的时候
用cast转一下,转成varchar的
xjy521 2004-08-03
  • 打赏
  • 举报
回复
哈哈哈

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧