3

以下の表から:

  • store(store_id, ...) {1 ..., 2 ...} 2店舗
  • フィルム(フィルム_id, ...)
  • 在庫(inventory_id, film_id, store_id)
  • レンタル(レンタル ID、レンタル日付、在庫 ID、返却日付、...)
  • カテゴリ (category_id、名前)
  • film_category(フィルム_id, カテゴリ_id)
  • フィルム(フィルムID、レンタル期間、レンタル料金、...)
  • 顧客 (customer_id、store_id、...)

次のようなテーブルでクエリ結果を取得できますか?

CategoryName | "Store 1: avaliable items" | "Store 1: unavaliable items" | "Store 2: avaliable items" | "Store 2: unavaliable items"

結果テーブルのストア フィールドは、同じ列ではなく別の列にあることに注意してください。

結果クエリを探しているのではなく、ストア 1、ストア 2 を並べて作成する方法を探しています。

ケース SQL ステートメントはここで役立ちますか?

4

1 に答える 1

0

次の形式でデータを取得します(複数の選択を結合する必要がある場合があります)

category item             count
-------- ---------        -----
cat 1    store1-avail     a1
cat 1    store1-unavail   b1
cat 1    store2-avail     c1
cat 1    store2-unavail   d1
cat 2    store1-avail     a2
cat 2    store1-unavail   b2

次に、ピボット機能を使用して、目的のレイアウトに変換します

category  store1-avail store1-unavail store2-avail ...
--------- ------------ -------------- ------------
cat 1     a1           b1             c1
cat 2     a2           b2             c2
...
于 2012-11-03T22:38:49.797 に答える