模块治理常规功能自定义系统的设计与实现(39-终级阶段 综合查询[6])

模块管理常规功能自定义系统的设计与实现(39--终级阶段 综合查询[6])

综合查询(6)--不同基准模块下的条件


        有了基准模块,又产生了一个问题,你设置查询条件的作用对象可能会随着基准模块的不同而改变。举个例子,当你查询“订单明细”的时候,选择了若干个商品作为查询条件,当基准模块是“订单明细”的时候,一切都没问题,满足你选择的商品的条件才会加到结果集中。但是这时候,你把基准模块改成了“订单”,那么这些商品的查询条件就要应用到聚合字段之中。
        来看一下演示:先选择二个模块的条件,客户名称和商品,用来限制查询的范围在此二个条件之下。

模块治理常规功能自定义系统的设计与实现(39-终级阶段 综合查询[6])

        这个查询没啥问题,下面将基准模块改为“订单”:可以看到商品条件将不能统计数字了。

模块治理常规功能自定义系统的设计与实现(39-终级阶段 综合查询[6])

        看起来很简单的操作,不花个三天时间是做不出来的。下面看看sql语句

    select
        //订单信息
        _t6040.tf_ordersId as tf_ordersId ,
        _t6040.tf_ordersNumber as tf_ordersNumber ,
        _t6040.tf_date as tf_date ,
        _t6040.tf_finished as tf_finished ,
        _t6040.tf_remark as tf_remark ,
        ( select					//订单数量求和
            sum(_t6050.tf_number)  
        from
            OrdersDetail _t6050 
        left outer join
            Orders _child_t6040 
                on _child_t6040.tf_ordersId = _t6050.tf_ordersId  
        left outer join
            Product _t6030 
                on _t6030.tf_productId = _t6050.tf_productId  
        where				//附加在订单明细上面的 商品的条件
            _t6030.tf_productId in (
                '1','2','3','4','5','6'
            ) 
            and _child_t6040.tf_ordersId = _t6040.tf_ordersId ) as S__t6050___tf_number ,
        ( select
            sum(_t6050.tf_subtotalPrice)  
        from
            OrdersDetail _t6050 
        left outer join
            Orders _child_t6040 
                on _child_t6040.tf_ordersId = _t6050.tf_ordersId  
        left outer join
            Product _t6030 
                on _t6030.tf_productId = _t6050.tf_productId  
        where
            _t6030.tf_productId in (
                '1','2','3','4','5','6'
            ) 
            and _child_t6040.tf_ordersId = _t6040.tf_ordersId ) as S__t6050___tf_subtotalPrice 

    from
        Orders _t6040 					//订单表
    left outer join
        Customer _t6010 				//客户表
            on _t6010.tf_customerId = _t6040.tf_customerId  
    where
    		// 附加在订单之上的 客户条件
        _t6010.tf_customerId in (
            '1','2','3','4','5','6','7','8'
        )

        看起来还不算太难,因为这里只选择了2张表的字段,如果选择了10张表,20张表呢?一直跟着我的博客看的,可以想一想这个问题,一个条件可以加在基准模块之上,加在聚合字段之上,还会出现有什么情况?
        还会有什么情况,当然是选了一个无用的条件了。

模块治理常规功能自定义系统的设计与实现(39-终级阶段 综合查询[6])