0
クエリによって返されたMySQLテーブルの名前から選択しようとしています。テーブル名はtable_prefix_dateです(例:table_prefix_20160801)。クエリによって返されたテーブルからMySQLを選択します。
select concat('db_name.table_prefix_',a.Date)
from (
select date_format(curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY,'%Y%m%d') as Date
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where date_format(Date,'%Y-%m-%d') between '2016-08-01' and '2016-08-20'
order by 1 asc;
すべてのテーブルが同じ列とインデックスを持っている:
は、私がこのような何かを、すべての日付と対応するテーブル名を取得するには。ただselect * from (queryabove);
を実行すると失敗します。
上記のクエリによって返されたテーブルからデータを取得する方法の実例を教えていただけますか?あなたは、動的SQL文を実行する必要が
この例で使用されている引用符で実行することができませんでした。クエリ全体を二重引用符に変更することによって、クエリは実行されますが、「select * from tablenames」が返されます。 http://sqlfiddle.com/#!9/4523b4/5 –
@AndyThompsonを参照してください。 。 。私は何を考えていたのか分かりません(私はジェット・ラグを原因として主張することができますが)。 'set'は実際には文字列ではなくサブクエリを使うべきです。 –
私は唯一のエラーを取得し、括弧が欠けているように見える/目盛り/引用符の問題? –