gpt4 book ai didi

php - 如何将这两个查询合并为一个?

转载 作者:行者123 更新时间:2023-11-29 01:33:16 24 4
gpt4 key购买 nike

$a = mysql_query("SELECT COUNT(*) as `count_1` FROM `table_1` WHERE `this_1` = '1'");
$b = mysql_fetch_assoc($a);

$c = mysql_query("SELECT COUNT(*) as `count_2` FROM `table_1` WHERE `this_2` = '1'");
$d = mysql_fetch_assoc($c);

最佳答案

使用 UNION ALL 使其成为单个查询:

SELECT COUNT(*) as count_1 FROM table_1 WHERE this_1 = '1'UNION ALLSELECT COUNT(*) as count_2 FROM table_1 WHERE this_2 = '1'

So that would result in

$a = mysql_query("...the complete query from above...");

关于php - 如何将这两个查询合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010745/

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