bitmap sql的写法太麻烦,如何简化

问题描述

这是一个物化视图database.table_tag_view,列是:

    tag_cate String,tag1     String,user_id_bit AggregateFunction(groupBitmap,UInt32)

tag_cate用户属性类型,如城市、年龄、学历、婚姻等; 列 tag_id 表示相应属性的值。

如果要统计满足以下条件的人数,我的sql如下:

condition:city in ('London','Beijing') and age in ('21-30','31-40') and education in ('master','doctor') and marriage ='Y' 

    select bitmapAndCardinality(
    (select bitmapAnd(
    (select bitmapAnd(
    (select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'city' and tag_id in ('London','Beijing')),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'age' and tag_id in ('21-30','31-40'))
    )),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'education' and tag_id in ('master','doctor'))
    )),(select groupBitmapOrState(user_id_bit)
    from database.table_tag_view 
    where tag_cate = 'marriage' and tag_id in ('Y')));

如果我要添加更多的条件,那么我会继续添加很多bitmapAnd语句,整个sql会很长而且不灵活。

这不是我想写的方式,我想写的方式是这样的:

    select bitmapCount(condition A & (condition B | condition C))
    from database.table_tag_view;

这能实现吗? 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)