Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5个月前关闭。
                                                                                            
                
        
我想从表中选择两列。在这2个选定的列上,我要进行自我连接(交叉)。

我尝试了一些查询,但它给了我错误:
table1 does not exists

select a.day day
     , b.id as id table1 a
 cross
  join table1 b
 where a.id <> b.id
   and table1 in (select id
                          , `day`
                       from original_table
                      where `day` = '2019-08-01');


预期的结果是ID的交叉连接。

最佳答案

您缺少from子句,并且In的条件不正确

    select a.day as day,b.id as id
    from table1 a cross join table1 b where a.id <> b.id
    and (a.id,a.day) in (select id,day from original_table where `day` = '2019-08-01');

10-08 09:47