-1

テーブルが2つありましたが、

  1. 最初 - 個々の在庫 - 各在庫 - 各行 - 製品 ID は FK です。
  2. 2 番目 - 製品 - 各製品 - 各行。数量欄があります。

当然、在庫テーブルの在庫数は製品テーブルの数量と同じです。不一致を見つけたいです。

そして、私は以下のようにクエリを書きました、

select a.stockid from stock a , product b where a.productid = b.productid and sum(a.quantity)<> b.quantity with ur.

しかし、エラーがスローされます。適切なplzでの機能の使用。

これを解決する他の方法はありますか?

同時に印刷する方法はありますb.quantitysum(a.quantity)a.stockid

4

1 に答える 1

1

次のクエリが必要だと思います。

select s.stockid, p.productid, p.quantity
from stock s join
     product p
     on p.productid = s.productid
group by p.productid, p.quantity 
having sum(s.quantity) <> p.quantity;

節ではなく、節を使用しhavingて集計結果を比較しwhereます。

于 2013-09-18T11:21:54.340 に答える