Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在多个表中并集_Php_Mysql_Postgresql_Join_Union All - Fatal编程技术网

Php 在多个表中并集

Php 在多个表中并集,php,mysql,postgresql,join,union-all,Php,Mysql,Postgresql,Join,Union All,我需要合并所有多个表。我通过PHP创建了一个查询,并在没有联合所有表的情况下成功运行。但当我合并所有2个表时,似乎查询永远不会在php页面中结束,我也在pgAdmin中测试了相同的结果。我通过shell生成了一个CSV文件,获得了我想要选择的数据,但查询也没有结束。我将感谢你的评论。提前谢谢 这是合并所有多个表的查询。可以合并的表的数量取决于DateRangePicker。因此,每天有一张表,例如:F_-UCell_1_170123,F_-UCell_1_170124,F_-UCell_1_17

我需要合并所有多个表。我通过PHP创建了一个查询,并在没有联合所有表的情况下成功运行。但当我合并所有2个表时,似乎查询永远不会在php页面中结束,我也在pgAdmin中测试了相同的结果。我通过shell生成了一个CSV文件,获得了我想要选择的数据,但查询也没有结束。我将感谢你的评论。提前谢谢

这是合并所有多个表的查询。可以合并的表的数量取决于DateRangePicker。因此,每天有一张表,例如:F_-UCell_1_170123,F_-UCell_1_170124,F_-UCell_1_170125,F_-UCell_1_170126,等等

SELECT 
to_date(T1.day::text,'YYYYMMDD'), 
T1.hour, 
cellname, 
Item67204837, Item73393830, ... , (199 columns listed in 7 tables listed below)

FROM ( 

SELECT 
day, 
hour, 
Cellkey, 
Item67204837, Item67199736 
FROM omstar_1486079935913_xsau.F_UCell_1_170123 

UNION ALL 

SELECT 
day, 
hour, 
Cellkey, 
Item67204837, Item67199736 
FROM omstar_1486079935913_xsau.F_UCell_1_170124) 

AS T1 

INNER JOIN ( 

SELECT 
day, 
hour, 
Cellkey, 
Item67183903, Item67180586, Item67183900, Item67180589, Item67180588, Item67180590, Item67183901, Item67180587, Item67183913, Item67183912, Item67180585 
FROM omstar_1486079935913_xsau.F_UCell_2_170123 

UNION ALL 
SELECT 
day, 
hour, 
Cellkey, 
Item67183903, Item67180586, Item67183900, Item67180589, Item67180588, Item67180590, Item67183901, Item67180587, Item67183913, Item67183912, Item67180585 
FROM omstar_1486079935913_xsau.F_UCell_2_170124) 

AS T2 ON 
T1.day = T2.day AND 
T1.hour = T2.hour AND 
T1.Cellkey = T2.Cellkey 

INNER JOIN (

SELECT 
day, 
hour, 
Cellkey, 
Item73394021, Item67190477, Item73394022, Item67189750, Item67190411, Item67189749, Item73425007, Item67189756, Item67189757, Item73425013, Item73394018, Item67193405, Item67189754, Item67190476, Item67192661, Item67193406, Item67192660, Item73425009, Item67189755, Item73426857, Item67190412, Item73425012, Item73426856, Item73425008, Item73423107 
FROM omstar_1486079935913_xsau.F_UCell_3_170123 

UNION ALL 
SELECT day, hour, Cellkey, Item73394021, Item67190477, Item73394022, Item67189750, Item67190411, Item67189749, Item73425007, Item67189756, Item67189757, Item73425013, Item73394018, Item67193405, Item67189754, Item67190476, Item67192661, Item67193406, Item67192660, Item73425009, Item67189755, Item73426857, Item67190412, Item73425012, Item73426856, Item73425008, Item73423107 
FROM omstar_1486079935913_xsau.F_UCell_3_170124) 

AS T3 ON 
T1.day = T3.day AND 
T1.hour = T3.hour AND 
T1.Cellkey = T3.Cellkey 

INNER JOIN ( 

SELECT day, hour, Cellkey, Item67193538, Item67190406, Item67193542, Item67179830, Item67192612, Item67193613, Item67190506, Item67179858, Item67193611, Item73403809, Item73424888, Item67179825, Item67193543, Item67189494, Item67189496, Item67193539, Item67193540, Item67180083, Item67180081, Item67190457, Item73424884, Item67190840, Item73393835, Item67180078, Item67189568, Item67179967, Item73393837, Item67180077, Item67180079, Item67193537, Item67190505, Item67189557, Item73424885, Item67180067, Item73426209, Item73394298, Item73423519, Item67190461, Item67192613, Item67180082, Item67179777, Item67190409, Item67203416, Item67179780, Item67180074, Item67180069, Item67179930, Item67189572, Item67180076, Item67190841, Item67190408, Item73424887, Item67193541, Item73393836, Item67193612, Item73424889, Item67180080, Item67192610, Item67192611, Item67193614, Item67190407, Item67179827, Item73424886, Item67180068, Item67193536, Item67179864, Item67179922, Item67179925, Item67179778, Item67179926, Item67179781, Item67179927, Item67179826, Item67179921, Item67179928, Item67179924, Item67179828, Item67179923, Item67179779, 
FROM omstar_1486079935913_xsau.F_UCell_4_170123 

UNION ALL 

SELECT day, hour, Cellkey, Item67193538, Item67190406, Item67193542, Item67179830, Item67192612, Item67193613, Item67190506, Item67179858, Item67193611, Item73403809, Item73424888, Item67179825, Item67193543, Item67189494, Item67189496, Item67193539, Item67193540, Item67180083, Item67180081, Item67190457, Item73424884, Item67190840, Item73393835, Item67180078, Item67189568, Item67179967, Item73393837, Item67180077, Item67180079, Item67193537, Item67190505, Item67189557, Item73424885, Item67180067, Item73426209, Item73394298, Item73423519, Item67190461, Item67192613, Item67180082, Item67179777, Item67190409, Item67203416, Item67179780, Item67180074, Item67180069, Item67179930, Item67189572, Item67180076, Item67190841, Item67190408, Item73424887, Item67193541, Item73393836, Item67193612, Item73424889, Item67180080, Item67192610, Item67192611, Item67193614, Item67190407, Item67179827, Item73424886, Item67180068, Item67193536, Item67179864, Item67179922, Item67179925, Item67179778, Item67179926, Item67179781, Item67179927, Item67179826, Item67179921, Item67179928, Item67179924, Item67179828, Item67179923, Item67179779, Item67179782 
FROM omstar_1486079935913_xsau.F_UCell_4_170124) 

AS T4 ON 
T1.day = T4.day AND 
T1.hour = T4.hour AND 
T1.Cellkey = T4.Cellkey 

INNER JOIN ( 

SELECT 
day, 
hour, 
Cellkey, 
Item67199780, Item73423508, Item67190405, Item73423488, Item73423498, Item67179331, Item67199680, Item67199619, Item67179527, Item67179462, Item73423506, Item67190586, Item67204827, Item73423510, Item67192609, Item67190401, Item67179465, Item67180641, Item67179459, Item67179336, Item67179464, Item73423490, Item67193609, Item73423502, Item73410511, Item67179338, Item73423486, Item67190404, Item67179457, Item67193610, Item67179299, Item73423504, Item67199625, Item67199623, Item67179332, Item67199556, Item73423494, Item67199621, Item73423496, Item67199624, Item67179466, Item67179460, Item67180642, Item67190621, Item67179329, Item67199620, Item73423492, Item67204826, Item67179337, Item67199682, Item73425032, Item67179334, Item67199622, Item67180648, Item67192608, Item67179525, Item73410510, Item67179524 
FROM omstar_1486079935913_xsau.F_UCell_5_170123 

UNION ALL 

SELECT 
day, 
hour, 
Cellkey, 
Item67199780, Item73423508, Item67190405, Item73423488, Item73423498, Item67179331, Item67199680, Item67199619, Item67179527, Item67179462, Item73423506, Item67190586, Item67204827, Item73423510, Item67192609, Item67190401, Item67179465, Item67180641, Item67179459, Item67179336, Item67179464, Item73423490, Item67193609, Item73423502, Item73410511, Item67179338, Item73423486, Item67190404, Item67179457, Item67193610, Item67179299, Item73423504, Item67199625, Item67199623, Item67179332, Item67199556, Item73423494, Item67199621, Item73423496, Item67199624, Item67179466, Item67179460, Item67180642, Item67190621, Item67179329, Item67199620, Item73423492, Item67204826, Item67179337, Item67199682, Item73425032, Item67179334, Item67199622, Item67180648, Item67192608, Item67179525, Item73410510, Item67179524 
FROM omstar_1486079935913_xsau.F_UCell_5_170124) 

AS T5 ON 
T1.day = T5.day AND 
T1.hour = T5.hour AND 
T1.Cellkey = T5.Cellkey 

INNER JOIN ( 

SELECT 
day, 
hour, 
Cellkey, 
Item67180483, Item67180498, Item67180508, Item67192689, Item67180484, Item67180491, Item67180490, Item67180509, Item67180499 
FROM omstar_1486079935913_xsau.F_UCell_6_170123 

UNION ALL 

SELECT 
day, 
hour, 
Cellkey, 
Item67180483, Item67180498, Item67180508, Item67192689, Item67180484, Item67180491, Item67180490, Item67180509, Item67180499 
FROM omstar_1486079935913_xsau.F_UCell_6_170124)

AS T6 ON 
T1.day = T6.day AND
T1.hour = T6.hour AND 
T1.Cellkey = T6.Cellkey 

INNER JOIN ( 

SELECT 
day, 
hour, 
Cellkey, 
Item67189840, Item67192114, Item67203850, Item67192486, Item67190567, Item67192115, Item67192487, Item67190704, Item73403763, Item73393832, Item73403761, Item67190705, Item67202932, Item73393830 
FROM omstar_1486079935913_xsau.F_UCell_8_170123 

UNION ALL 

SELECT 
day, 
hour, 
Cellkey, 
Item67189840, Item67192114, Item67203850, Item67192486, Item67190567, Item67192115, Item67192487, Item67190704, Item73403763, Item73393832, Item73403761, Item67190705, Item67202932, Item73393830 
FROM omstar_1486079935913_xsau.F_UCell_8_170124) 

AS T7 ON 
T1.day = T7.day AND 
T1.hour = T7.hour AND 
T1.Cellkey = T7.Cellkey 

INNER JOIN 

omstar_1486079935913_xsau.d_ucell as Tn on T1.cellkey = Tn.cellkey 

WHERE Cellname IN ('U06CZPA' ) ORDER BY T1.day, T1.hour;

列分布在F_-UCell_1或F_-UCell_2或。。。或F_-UCell_6或F_-UCell_8缺少F___7(共有7个表通过
内部联接
联接)

@alex_edev,我正在测试,只需一列即可正常工作,因此这是一个性能问题。同样,我在同一个局域网中有不同的服务器(一个用于网页,另一个用于数据库服务器)。所有列的结果约为150MB,因此可能是网络问题。
@Ben H,表格的设计是先前设计的,并且已经有数据,因此重新设计表格不是一个选项。

所有ItemXXXXXXXX字段都是我想在first select中选择的字段。它们分布在表F_ÈUCell中,以完成要选择的203列。在您的示例中,
Item67179782
没有对。如果查询中的列数相同,则会出现错误,因为
UNION
要求两个联合表中的列数相同。”似乎查询永远不会在php页面中结束”-可能您的php代码可以澄清问题。php文件打印我粘贴的查询,所有列匹配每个UNION all,并且没有错误。当在php中执行行pg_查询时,它永远不会结束以继续它们的代码。。。我没有可用的PHP文件。我会粘贴ASAPU你应该考虑一个不同的数据结构!想法:将您的表设计为类型:
创建类型F_UCell(day int、hour int、Cellkey int、Items int[])并为这些单元格创建一个表。@Beaver那么您是否尝试过对相同结构的简单表进行查询?如果您确信SQL和PHP中没有错误,那么对查询中的每个表进行模拟(具有相同的结构,但只有很少的行,例如每个表中有3-5行)并对它们进行查询是有意义的。它将帮助您了解您是否正在处理性能问题。