如何加入选择与自己?

时间:2013-02-12 11:13:23

标签: mysql

  1. 与自己连接表是没问题的。但我需要加入一个创建的选择。第一个想法:使用临时表,但我只能打开一次。这是真的吗?

  2. MySQL是否足够智能,只计算一次具有相同术语的子选择? 例如:

    join (select * from asdf where term) as one
    join (select * from asdf where term) as two
    ...
    join (select * from asdf where term) as ten
    
  3. 通常如何解决?

1 个答案:

答案 0 :(得分:2)

您可以多次加入临时表

    select * into #temp from asdf where term
    ...
    join #temp as one
    join #temp as two
    ...
    join #temp as ten