横向输出:
SELECT
t1.*,
tb_name1.val AS tb_name1_val
FROM
tb_name1
RIGHT JOIN (
(
SELECT
tb_name2.datatime AS datatime,
tb_name2.val AS tb_name2_val,
tb_name3.val AS tb_name3_val
FROM
tb_name2
RIGHT JOIN tb_name2 ON tb_name2.datatime = tb_name2.datatime
) t1
) ON tb_name1.datatime = t1.datatime
WHERE
DATE_FORMAT( t1.datatime, '%Y-%d %H:%i' ) = '2019-16 22:15'
纵向输出:
select datatime ,
val ,'tb_name1' as tbname
from tb_name1 WHERE
DATE_FORMAT( datatime, '%Y-%d %H:%i' ) = '2019-16 22:15'
union all
select datatime ,
val ,'tb_name2'
from tb_name2 WHERE
DATE_FORMAT( datatime, '%Y-%d %H:%i' ) = '2019-16 22:15'
union all
select datatime ,
val ,'tb_name3'
from tb_name3 WHERE
DATE_FORMAT( datatime, '%Y-%d %H:%i' ) = '2019-16 22:15'