如何在sql中编写案例?

编程入门 行业动态 更新时间:2024-10-28 01:25:56
本文介绍了如何在sql中编写案例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

select case when h.VVID<=15 then COUNT(h.fs) end as [<=15], case when h.VVID between 16 and 18 then COUNT(h.fs) end as [16 - 18], case when h.VVID between 19 and 21 then COUNT(h.fs) end as [19 - 21], case when h.VVID between 22 and 24 then COUNT(h.fs) end as [22 - 24], case when h.VVID>=25 then COUNT(h.fs) end as [>=25] from ( select t.fs,sum(t.VVID) VVID,sum(t.VID) VID,sum(t.ID) ID from ( select dr.C_FS_Code fs, case when ds.c_doc_grade='G00001' then COUNT(distinct ds.C_DSC_Code) end as [VVID], case when ds.c_doc_grade='G00002' then COUNT(distinct ds.C_DSC_Code) end as [VID], case when ds.c_doc_grade='G00003' then COUNT(distinct ds.C_DSC_Code) end as [ID] from tbl_dwr dr join tbl_dwr_details ds on ds.N_Srno=dr.N_Srno join Tbl_FS_Mst fs on fs.C_Code=dr.C_FS_Code join Tbl_Doc_Stock_Chem_Add_Mst sd on sd.C_Code=ds.C_DSC_Code where MONTH(dr.D_Date_Report) in (3,4) and YEAR(dr.D_Date_Report)=2015 and fs.N_Type=1 --and dr.C_FS_Code='MSR001' group by dr.C_FS_Code,ds.c_doc_grade )t group by t.fs order by t.fs )h

执行此查询后会收到如下错误 消息1033,级别15,状态1,行34 ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效,除非TOP或FOR XML也是指定的。 请给出解决方案...

after executing this query am getting error like in below Msg 1033, Level 15, State 1, Line 34 The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. please give solution for this...

推荐答案

错误应该是很清楚。您在派生表中有一个ORDER BY语句(嵌套查询)。你有ORDER BY t.fs,但它在h派生表中。 要么删除顺序,要把它放在外面,之后)h或者添加SELECT前100名案例...... The error should be pretty clear. You have an ORDER BY statement in your derived table (nested query). You have ORDER BY t.fs but that is inside the h derived table. Either remove the order by and put it on the outside, after )h or add SELECT TOP 100 PERCENT Case...

更多推荐

如何在sql中编写案例?

本文发布于:2023-07-22 10:25:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:案例   如何在   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!