在单独的列上进行多个mysql查询

时间:2018-01-13 23:58:28

标签: mysql sql

如何在单独的列上显示多个mysql查询的输出,下面的代码不起作用并包含3个查询,但是我可以让它在2个查询中工作,见下文

包含3个子查询的mysql查询:

Select (
SELECT (
        SELECT count(s2.centerpoint_stream_stable)
        FROM status_log s2
        WHERE s2.centerpoint_stream_stable = 'Disconnected/ Reconnected to Stream'
        AND s2.date > date_sub(NOW(), INTERVAL 1 minute)  
        ) AS centerpoint_stream_no_disconnects,

count(centerpoint_stream_stable) from status_log where  centerpoint_stream_stable = 'Disconnected/ Reconnected to Stream' and  date > date_sub(now(), interval 6 hour) ) AS a,b,       



s.date, s.website_online, s.icecast_source_online, s.icecast_source_ip,
s.icecast_no_listeners, s.centerpoint_online, s.centerpoint_connection,
s.centerpoint_stream_stable, s.centerpoint_stream_status,  s.horsleypark_online,
s.horsleypark_connection, s.horsleypark_stream_stable, s.horsleypark_stream_status,
s.local_primary_internet_online, s.local_primary_internet_ping,
s.local_primary_instreamer_online, s.local_secondary_internet_online,
s.local_secondary_internet_ping, s.local_secondary_instreamer_online, s.system_ok
FROM status_log s
WHERE id = (select max(id) from status_log)

mysql查询2(工作):

SELECT (
        SELECT count(s2.centerpoint_stream_stable)
        FROM status_log s2
        WHERE s2.centerpoint_stream_stable = 'Disconnected/ Reconnected to Stream'
        AND s2.date > date_sub(NOW(), INTERVAL 1 minute)  
        ) AS centerpoint_stream_no_disconnects,


s.date, s.website_online, s.icecast_source_online, s.icecast_source_ip,
s.icecast_no_listeners, s.centerpoint_online, s.centerpoint_connection,
s.centerpoint_stream_stable, s.centerpoint_stream_status,  s.horsleypark_online,
s.horsleypark_connection, s.horsleypark_stream_stable, s.horsleypark_stream_status,
s.local_primary_internet_online, s.local_primary_internet_ping,
s.local_primary_instreamer_online, s.local_secondary_internet_online,
s.local_secondary_internet_ping, s.local_secondary_instreamer_online, s.system_ok
FROM status_log s
WHERE id = (select max(id) from status_log)

输出

+-----------------------------------+---------------------+----------------+-----------------------+-------------------+----------------------+--------------------+------------------------+---------------------------+---------------------------+--------------------+------------------------+---------------------------+---------------------------+-------------------------------+-----------------------------+---------------------------------+---------------------------------+-------------------------------+-----------------------------------+-----------+
| centerpoint_stream_no_disconnects | date                | website_online | icecast_source_online | icecast_source_ip | icecast_no_listeners | centerpoint_online | centerpoint_connection | centerpoint_stream_stable | centerpoint_stream_status | horsleypark_online | horsleypark_connection | horsleypark_stream_stable | horsleypark_stream_status | local_primary_internet_online | local_primary_internet_ping | local_primary_instreamer_online | local_secondary_internet_online | local_secondary_internet_ping | local_secondary_instreamer_online | system_ok |
+-----------------------------------+---------------------+----------------+-----------------------+-------------------+----------------------+--------------------+------------------------+---------------------------+---------------------------+--------------------+------------------------+---------------------------+---------------------------+-------------------------------+-----------------------------+---------------------------------+---------------------------------+-------------------------------+-----------------------------------+-----------+
|                                 0 | 2018-01-14 10:54:40 | Online         | Online                | 60.241.175.9      | 21                   | Online             | Main                   | system ok                 | PLAYING                   | Online             | Main                   | system ok                 | PLAYING                   | Online                        | 26.556                      | Online                          | Online                          | 22.625                        | Online                            | Online    |
+-----------------------------------+---------------------+----------------+-----------------------+-------------------+----------------------+--------------------+------------------------+---------------------------+---------------------------+--------------------+------------------------+---------------------------+---------------------------+-------------------------------+-----------------------------+---------------------------------+---------------------------------+-------------------------------+-----------------------------------+-----------+

1 个答案:

答案 0 :(得分:0)

select * from
    (select count(centerpoint_stream_stable) from status_log where  centerpoint_stream_stable = 'Disconnected/ Reconnected to Stream' and  date > date_sub(now(), interval 6 hour)) as T1
    ,
    (select count(centerpoint_stream_stable) from status_log where  centerpoint_stream_stable = 'Disconnected/ Reconnected to Stream' and  date > date_sub(now(), interval 6 hour) ) as T2
    ,
    (select  s.date, s.website_online, s.icecast_source_online, s.icecast_source_ip,
       s.icecast_no_listeners, s.centerpoint_online, s.centerpoint_connection,
       s.centerpoint_stream_stable, s.centerpoint_stream_status,  s.horsleypark_online,
       s.horsleypark_connection, s.horsleypark_stream_stable, s.horsleypark_stream_status,
       s.local_primary_internet_online, s.local_primary_internet_ping,
       s.local_primary_instreamer_online, s.local_secondary_internet_online,
       s.local_secondary_internet_ping, s.local_secondary_instreamer_online, s.system_ok
       FROM status_log s
        WHERE id = (select max(id) from status_log))  as T3