我必须一起显示来自两个不同查询的数据。
查询一:
select count(DISTINCT(nickname)) users_got_a_card from capture_captive where `number_successed`>0;
查询 2:
select count(DISTINCT(`nickname`)) users_shown_captive from `capture_captive`;
我想同时显示这两个查询的数据。
根据您的需要,您可以在
每列中执行以下操作:
select ( select count(DISTINCT(nickname)) users_got_a_card from capture_captive where 'number_successed'>0) as column1,
(select count(DISTINCT(`nickname`)) users_shown_captive from 'capture_captive')as column2
或每行:
select count(DISTINCT(nickname)) users_got_a_card from capture_captive where number_successed>0
UNION ALL
select count(DISTINCT(nickname)) users_shown_captive from capture_captive
如果您希望它们作为单行的两列,您可以尝试
SELECT
(
SELECT COUNT(DISTINCT(nickname))
FROM capture_captive
WHERE `number_successed`> 0
) users_got_a_card,
(
SELECT COUNT(DISTINCT(`nickname`))
FROM `capture_captive`
) users_shown_captive
或者
SELECT users_got_a_card, users_shown_capt
FROM
(
SELECT COUNT(DISTINCT(nickname)) users_got_a_card
FROM capture_captive
WHERE `number_successed`> 0
) a CROSS JOIN
(
SELECT COUNT(DISTINCT(`nickname`)) users_shown_capt
FROM `capture_captive`
) b
或者
SELECT COUNT(DISTINCT(IF(`number_successed` > 0, `nickname`, NULL))) users_got_a_card,
COUNT(DISTINCT(`nickname`)) users_shown_capt
FROM `capture_captive`
这是SQLFiddle演示
select count(DISTINCT(case when `number_successed`>0
then `nickname` end)) users_got_a_card,
count(DISTINCT(nickname)) users_shown_captive
from capture_captive
这很简单。
首先,从第一个查询通常的方式获取结果并将其存储在一个名为 的变量中$var1
,
接下来,从第二个查询通常的方式获取结果并将其存储在一个名为 的变量$var2
中,
最后,创建一个代码以将它们一起显示:
echo $var1," ",$var2;
就如此容易。