Snowflake: Unsupported subquery for DISTINCT - Column order matters?

前端 未结 2 1432
鱼传尺愫
鱼传尺愫 2021-01-16 00:16

I have two related tables (unnecessary columns not listed):

LOCATION

VENUE_ID - NUMBER(38,0)

VISIT

         


        
相关标签:
2条回答
  • 2021-01-16 00:37

    The answer is a little cryptic, but what happens is this:

    You are asking for ONE value and you need to guarantee that only ONE value is returned by your subquery. A distinct clause cannot guarantee that. In some databases that will work as long as the data returns one row, but the moment you get two rows then the database will throw an error.

    Snowflake is strict on its subquery analysis. So you need to use a subquery that is guarantee to return always one value, for example select sum(..), select count(..)

    0 讨论(0)
  • 2021-01-16 00:43

    I think you're making this more complex than this needs to be. Below should be all you need:

    SELECT l.venue_id
      , count(distinct v.device_id)
    FROM location l
    LEFT JOIN visit v
     on l.venue_id = v.venue_id
    GROUP BY l.venue_id
    
    0 讨论(0)
提交回复
热议问题