SQL CASE WHEN:是否有限制(字符数)?

SQL CASE WHEN: is there a limit ( in number of characters )?

我正在使用 case when 语句将位置(起始和目的地纬度、经度)分组为 3 个区域。

运行 每个区域 1 次查询工作正常。

只需将所有区域捆绑在一个查询中,结果为空。

select    period
        , case 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_1__5739_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_1__5739_characters> ) = True )
          then 'Region 1'
          end as region
        , sum(<metrics>)
from source_table
where <conditions>
group by period, starting_lng, starting_lat, dest_lng, dest_lat
select    period
        , case 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_2__2471_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_2__2471_characters> ) = True ) 
          then 'Region 2'
          end as region
        , sum(<metrics>)
from source_table
where <conditions>
group by period, starting_lng, starting_lat, dest_lng, dest_lat
select    period
        , case 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_3__3039_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_3__3039_characters> ) = True )
          then 'Region 3'
          end as region
        , sum(<metrics>)
from source_table
where <conditions>
group by period, starting_lng, starting_lat, dest_lng, dest_lat

上面的 3 个查询工作正常。以下结果为空:

select    period
        , case 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_1__5739_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_1__5739_characters> ) = True )
          then 'Region 1'
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_2__2471_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_2__2471_characters> ) = True ) 
          then 'Region 2' 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_3__3079_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_3__3079_characters> ) = True )
          then 'Region 3'
          end as region
        , sum(<metrics>)
from source_table
where <conditions>
group by period, starting_lng, starting_lat, dest_lng, dest_lat

观察到坐标串很长是促使我尝试分离区域的原因。

(2 x 5,739 + 2 x 2,417 + 2 x 3,079 ) = 22,578


我希望你的想法是:


这应该有效:

select    period
        , case 
          when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_1__5739_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_1__5739_characters> ) = True )
          then 'True' else 'False' end as region1,
          case  when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_2__2471_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_2__2471_characters> ) = True ) 
          then 'True' else 'False' end as region2, 
          case  when ( in_polygon("polygon", starting_lng, starting_lat, <coordinates_3__3079_characters> ) = True
            or   in_polygon("polygon",     dest_lng,     dest_lat, <coordinates_3__3079_characters> ) = True )
          then 'True' else 'False' end as region3,    
        , sum(<metrics>)
from source_table
where <conditions>
group by period, starting_lng, starting_lat, dest_lng, dest_lat