`
jianchen
  • 浏览: 334078 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Filter and Case when

    博客分类:
  • BI
阅读更多

      在项目实施过程中,为了满足报表接口人的需求,我尝试将整个EXCEL表格上的指标都制作出来。这些指标可以利用维度的条件限制进行计算得到。刚开始在利用Filter对几个指标数据进行条件限制没什么问题,比如订单来源这个维度限制为集市,想计算集市的全网退款量。不过随着指标一项项增加,用到的维度条件就不同了。为了计算"小二完结量",我增加了“处理人”这个维度,在表达式里用的也是filter,不过再次查看数据时发现,之前制作的一个指标的数据出现了问题,值变的很小。查看SQL发现在where子句中,将"订单来源"和"处理人"的条件进行了交叉限制。本来这个“小二完结量”在模型里我就用了Filter进行过滤,排除了系统完结。然后在“回复”的“条件”中再次进行filter限制了组别。这样导致在where子句中产生了很多的交叉条件限制。导致数据计算出现了问题。后来我尝试将所有的条件都用case when来写,这样数据就没有问题了。(全表关联当然没有问题了),不过就是速度慢。

 

事后查了下资料,了解了下filter和case when的区别:

 

case when中的条件不会再where子句中,而filter则会将条件限制到where子句中,这样就会减少结果集,从而提升了性能。case when语句相当于全表关联,然后进行筛选,从性能上考虑推荐使用Filter,不过我这种情况,按理说,OBIEE产生的sql是或者的关系,不应该对另外的度量产生影响啊?

 

具体Filter的介绍如下:

 

FILTER(measure_expr USING boolean_expr)

 

The following is a simple example of the FILTER function:

 

SELECT year, 
FILTER(sales USING product = 'coke'),
FILTER(sales USING product = 'pepsi')
FROM logBeverages

 

After navigation, this query is executed as follows:

 

SELECT year, 
SUM(CASE WHEN product = 'coke' THEN sales), 
SUM(CASE WHEN product = 'pepsi' THEN sales)
FROM physBeverages
WHERE product = 'coke' OR product = 'pepsi'
GROUP BY year

 

 FILTER(x USING y),不过Filter的使用要注意的有:

1,y部分必须是一个布尔表达式

2,如果y部分包含度量,则会报错

3,Filter被用于外部查询块则会报错。

4,在X部分不能包含显式的聚集。比如Filter(count(x),y)则是不被允许的。

分享到:
评论

相关推荐

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    When the filter is done initializing, the VsGui controls become active and report the filter information (serial number, wavelength range, etc). e) VsGui added filter status item to Configure dialog...

    经典小巧的表格组件 EhLib4.14

     property ) and work with this data: sort, filter, edit.  Has an interface to get the list of all values of the field,  ignoring local filter. TDBGridEh uses this property for  automatic building...

    I2Localization2.8.6_f2

    Intuitive inspectors allow you Preview, Edit, Categorize, Create, Parse and Filter even large sources. Compile Time Checking Bake translations into script constants to avoid Typos when accessing them...

    I2 Localization2.6.6b1

    Intuitive inspectors allow you Preview, Edit, Categorize, Create, Parse and Filter even large sources. Compile Time Checking Bake translations into script constants to avoid Typos when accessing them...

    Troubleshooting.with.the.Windows.Sysinternals.Tools.2nd.Edition

    Use Process Monitor to capture low-level system events, and quickly filter the output to narrow down root causes List, categorize, and manage software that starts when you start or sign in to your ...

    CE中文版-启点CE过NP中文.exe

    Mainly minor improvements and some small bugfixes, but also a new 'ultimap like' feature called Code Filter for which you don't need any special hardware for. (Just an extensive list of addresses) ...

    myBase Desktop 6.1.1 11/1/2012 绿色 完美破解版

    Fixed: a bug in the RTF text filter, that may affect index data and search results, primarily for those text having the number/bullet style; Fixed: a bug in the RTF2HTML converter, that may cause the ...

    EhLib-delphi

     property ) and work with this data: sort, filter, edit.  Has an interface to get the list of all values of the field,  ignoring local filter. TDBGridEh uses this property for  automatic building...

    cisco_router_performance_field_guide.zip

    When I started this project, I had two requirements and I strived throughout the book to balance both of them. My first requirement comes from being an instructor and consultant for 10 years now. In...

    Machine.Learning.Projects.for.NET.Developers.1430267674

    Use F#’s powerful type providers to interface with external resources (in this case, data analysis tools from the R programming language) Transform your data into informative features, and use them ...

    VA_X_Setup2043

    VS2012+: Fix for failure of native visualizers (natvis) to load after initial debug session when native edit and continue is disabled. (case=83528) VS2010+: Fix failure of checkbox click in filter ...

    AD630锁相放大资料

    When used as a synchronous demodulator in a lock-in amplifier configuration, it can recover a small signal from 100 dB of interfering noise (see Lock-In Amplifier Applications section). Although ...

    计算机视觉(英文版)

    18.2 Linear Dynamic Models and the Kalman Filter 492 18.2.1 Linear Dynamic Models 492 18.2.2 Kalman Filtering 497 18.2.3 The Kalman Filter for a 1D State Vector 497 18.2.4 The Kalman Update Equations ...

    plsqldev14.0.0.1961x32多语言版+sn.rar

    The new viewer allows you to ignore differences in case and white space as usual, but it can also ignore differences in comments. Program Window enhancements The Program Window now highlights ...

    plsqldev14.0.0.1961x64多语言版+sn.rar

    The new viewer allows you to ignore differences in case and white space as usual, but it can also ignore differences in comments. Program Window enhancements The Program Window now highlights ...

    Delphi7.1 Update

    TClientDataSet does not order correctly on a TLargeIntField when used in an index or in the IndexFieldNames property (Quality Central 1050 & 2626) * TAggregateField returns an incorrect value after a ...

    iOS 人机交互指南(iOS Human Interface Guidelines)

    3. Filter the Feature List Through the Audience Definition 26 4. Don’t Stop There 26 Design the App for the Device 27 Embrace iOS UI Paradigms 27 Ensure that Universal Apps Run Well on Both iPhone ...

    微软内部资料-SQL性能优化5

    The trees are managed, and branches are grafted as necessary, so that navigating down the tree to find a value and locate a specific record takes only a few page accesses. Because the trees are ...

    Introduction.to.Android.Application.Development(4th,2013.12) pdf

    Application Using an Intent Filter 130 Configuring Other Intent Filters 130 Registering Other Application Components 131 Working with Permissions 131 Registering Permissions Your Application Requires...

    EHLib 6.3.171〖D7~XE5〗

    + In the Filter Drop-down lists of the DBGridEh it is allowed to selected several values quickly by pressing and dragging the pressed mouse. + In DBGridEh. If gioShowRowselCheckboxesEh value is in ...

Global site tag (gtag.js) - Google Analytics