0

同じタイプのフィールドを含む約 9 つのテーブルがあります。最初にそれらの 9 つを結合し、その結合された列で一意の値の個別の数を取得したいと思います。これは私がこれまでに試したことですが、役に立ちませんでした。これがこの値を返す最も効率的な方法であるかどうかもわかりませんか?

SELECT COUNT(DISTINCT aircraft_id) FROM 
(
SELECT aircraft_id FROM database.a_message UNION ALL
SELECT aircraft_id FROM database.b_message UNION ALL
SELECT aircraft_id FROM database.c_message UNION ALL
SELECT aircraft_id FROM database.d_message UNION ALL
SELECT aircraft_id FROM database.e_message UNION ALL
SELECT aircraft_id FROM database.f_message UNION ALL
SELECT aircraft_id FROM database.g_message UNION ALL
SELECT aircraft_id FROM database.h_message UNION ALL
SELECT aircraft_id FROM database.i_message
) ;
4

1 に答える 1

0
SELECT DISTINCT aircraft_id,count(aircraft_id) FROM 
(
SELECT aircraft_id FROM database.a_message UNION ALL
SELECT aircraft_id FROM database.b_message UNION ALL
SELECT aircraft_id FROM database.c_message UNION ALL
SELECT aircraft_id FROM database.d_message UNION ALL
SELECT aircraft_id FROM database.e_message UNION ALL
SELECT aircraft_id FROM database.f_message UNION ALL
SELECT aircraft_id FROM database.g_message UNION ALL
SELECT aircraft_id FROM database.h_message UNION ALL
SELECT aircraft_id FROM database.i_message
) group by aircraft_id;

また

select aircraft_id,count(aircraft_id)
(
SELECT DISTINCT aircraft_id FROM 
(
SELECT aircraft_id FROM database.a_message UNION ALL
SELECT aircraft_id FROM database.b_message UNION ALL
SELECT aircraft_id FROM database.c_message UNION ALL
SELECT aircraft_id FROM database.d_message UNION ALL
SELECT aircraft_id FROM database.e_message UNION ALL
SELECT aircraft_id FROM database.f_message UNION ALL
SELECT aircraft_id FROM database.g_message UNION ALL
SELECT aircraft_id FROM database.h_message UNION ALL
SELECT aircraft_id FROM database.i_message
)
) group by aircraft_id;
于 2012-11-05T23:51:04.013 に答える