gpt4 book ai didi

mysql - 多个 SQL 计入单个结果集

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

大家好

我正在尝试做一些我认为在 MYSQL 上不可能的事情。

我们有一个非常大的数据库,我们可以从中提取我们创建的产品的生产报告。目前,我们运行多个查询来获取这些结果,然后将数据手动传输到表中,然后将其发送给需要报告的任何人。

有没有更简单的方法来做到这一点。 IE 单个查询。

我运行的查询示例

a. SELECT count(id) from ProductA_T where created between '<date>' and '<date>' and productstatus = "<successful>";
b. SELECT count(id) from ProductB_T where created between '<date>' and '<date>' and productstatus = "<successful>";
c. SELECT count(id) from ProductC_T where created between '<date>' and '<date>' and productstatus = "<successful>";

我正在寻找的结果示例

  1. 产品A 产品B 产品C
  2. 500 500 500

最佳答案

您可以将所有内容放入 Select 子句中,如下所示:

Select
(SELECT count(id) from ProductA_T where created between '<date>' and '<date>' and productstatus = "<successful>") as CountA
(SELECT count(id) from ProductB_T where created between '<date>' and '<date>' and productstatus = "<successful>") as CountB
(SELECT count(id) from ProductC_T where created between '<date>' and '<date>' and productstatus = "<successful>") as CountC

这样你就会有这样的输入:

  • 计数 A 计数 B 计数 C
  • 500 500 500

您稍后可以轻松添加更多计数

关于mysql - 多个 SQL 计入单个结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19369938/

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