0

みなさんおかえりなさい

MYSQL では不可能だと思うことをしようとしています。

作成した製品の生産レポートを引き出す非常に大きなデータベースがあります。現時点では、複数のクエリを実行してこれらの結果を取得し、データをテーブルに手動で転送してから、レポートが必要な人にデータを送信しています。

これを行う簡単な方法はありますか。つまり、単一のクエリです。

私が実行するクエリの例

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
4

3 に答える 3

-1

ストアドプロシージャを使用する必要があると思います

Create StoredProcedure SP_Name_1
As
Beign
Declare @id1 int,@id2 int,@id3 int;
SELECT @id1 = count(id) from ProductA_T where created between '<date>' and '<date>' and productstatus = "<successful>";
SELECT @id2 = count(id) from ProductB_T where created between '<date>' and '<date>' and productstatus = "<successful>";
SELECT @id2 = count(id) from ProductC_T where created between '<date>' and '<date>' and productstatus = "<successful>";

select  @id1 as ProductA ,@id2 as ProductB ,@id3 as ProductC
End

ありがとう、タハ

于 2013-10-14T22:02:55.560 に答える