gpt4 book ai didi

mysql - 对不同列进行多个 mysql 查询

转载 作者:行者123 更新时间:2023-11-29 18:02:14 25 4
gpt4 key购买 nike

如何在不同的列上显示多个 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 |
+-----------------------------------+---------------------+----------------+-----------------------+-------------------+----------------------+--------------------+------------------------+---------------------------+---------------------------+--------------------+------------------------+---------------------------+---------------------------+-------------------------------+-----------------------------+---------------------------------+---------------------------------+-------------------------------+-----------------------------------+-----------+

最佳答案

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

关于mysql - 对不同列进行多个 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48245456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com