group by 出现一个奇怪的问题
代码如下:
select p.billno,p.fitemid ,sum(p.fqty) as fqty from (
select '1' as ftype,t.fbillno as billno,t1.fitemid,sum(t1.fqty) as fqty from icstockbill t left join icstockbillentry t1 on t1.finterid=t.finterid
inner join (select distinct left(fbillno,CHARINDEX('退',fbillno)-1) as fbillno from SEOutStock where fbillno like '%退%' and fdate>='2008-01-01' and fdate<='2013-12-31' and fcancellation=0 and fstatus>=1 group by fbillno) o on o.fbillno = t.fbillno
where t.fdate>='2008-01-01' and t.fdate<='2013-12-31' and ftrantype=21 and frob=1 and fcancellation=0 and fstatus>=1 group by t.fbillno,t1.fitemid
union
select '2' as ftype,left(tp.fbillno,CHARINDEX('退',tp.fbillno)-1) as billno,tp1.fitemid,sum(tp1.fqty) as fqty from icstockbill tp left join icstockbillentry tp1 on tp1.finterid=tp.finterid
where tp.fbillno like '%退%' and tp.fdate>='2008-01-01' and tp.fdate<='2013-12-31' and ftrantype=21 and fcancellation=0 and fstatus>=1 group by tp.fbillno,tp1.fitemid
union
select '3' as ftype,tt1.fsourcebillno as billno,fitemid,sum(fqty) as fqty from icstockbill tt left join icstockbillentry tt1 on tt1.finterid=tt.finterid
inner join (select distinct left(fbillno,CHARINDEX('退',fbillno)-1) as fbillno from SEOutStock where fbillno like '%退%' and fdate>='2008-01-01' and fdate<='2013-12-31' and fcancellation=0 and fstatus>=1 group by fbillno) o1 on o1.fbillno = tt1.fsourcebillno
where tt.fdate>='2008-01-01' and tt.fdate<='2013-12-31' and ftrantype=21 and frob=-1 and fcancellation=0 and fstatus>=1 group by tt1.fsourcebillno,tt1.fitemid
) p group by p.billno,p.fitemid
相关推荐
木瓜:奇怪的机器人
木瓜 奇怪的机器人
随便做的奇怪的东西-少儿编程scratch项目源代码文件案例素材.zip
随便做的奇怪的东西-少儿编程scratch项目源代码文件案例素材.zip
JTAG模式下Vivado SDK全速运行时的奇怪报错
下载elf完毕后,弹出如图1所示的消息框,提示软件运行出现问题。软件运行结果却是OK的,比如我这里VGA接口就能够正常显示图片,如图2所示。此外,在Debug模式下,也不会报该错误。
浅谈MySQL排序原理与案例分析
前言 排序是数据库中的一个基本功能,MySQL也不例外。用户通过Order by语句即能达到将指定的结果集排序的目的,其实不仅仅是Order by语句,Group by语句,Distinct语句都会隐含使用排序。本文首先会简单介绍SQL如何利用索引避免排序代价,然后会介绍MySQL实现排序的内部原理,并介绍与排序相关的参数,最后会给出几个“奇怪”排序例子,来谈谈排序一致性问题,并说明产生现象的本质原因。 1.排序优化与索引使用 为了优化SQL语句的排序性能,最好的情况是避免排序,合理利用索引是一个不错的方法。因为索引本身也是有序的,如果在需要排序的字段上面建立了合适的索引,那么就可以跳过排
关于Laravel Route重定向的一个注意点
发现问题 最近在做项目发现一个奇怪的现象,我的路由配置里有如下配置: Route::group(array('prefix'=>'admin','before'=>'adminauth'),function(){ // 管理员登录 Route::get('/',function(){ return Redirect::to('admin/login'); }); Route::get('login','UserController@adminLogin'); } 目的是无论用户输入”admin”,还是”admin/login”都能跳转到登录界面。然而现实情况是输入”admin”之后


疑难问题
