0

我有 4 张桌子:

表格1: batch_info with columns batch_id, brew_date, beer_style_name

表 2 brew_fermentation with columns batch_id (FK of batch_info), fermentor_name (FK of fermentor),.:。

表3: fermentor with columns, fermentor_name, tank_volume

表 4: Produced_amount with columns batch_id(FK of batch_info), produced_amount, date_transferred

酿造啤酒时,我们将其输入表 1 和表 2,当啤酒完成发酵后,我们将数据输入表 4 生产量。

我想创建一个看起来像这样的表

Fermentor # |  Batch_ID  |  Tank_Size  |  Date_Brewed  | Beer Style

F10.1           13001         10           2013-01-12      IPA

F20.2           NULL         20             NULL          EMPTY

我有以下 SQL 语句。

但是,它不会仅显示发酵罐表中的所有发酵罐,而只会显示其中当前有东西的发酵罐。我想填充上面的表格。

SELECT brew_fermentation.fermentor_name AS "Fermentor #",
batch_info.batch_id AS "Batch Number", batch_info.beer_style_name AS
"Beer Style", batch_info.date_brewed AS "Date Brewed",
fermentor.tank_volume AS "BBLs"

FROM batch_info, fermentor, brew_fermentation

WHERE batch_info.batch_id = brew_fermentation.batch_id AND
brew_fermentation.fermentor_name=fermentor.fermentor_name AND

batch_info.batch_id NOT IN (SELECT produced_amount.batch_id FROM
produced_amount)

ORDER BY batch_info.date_brewed
4

1 回答 1

0

替换NOT INNOT EXISTS

  ...
WHERE 
  batch_info.batch_id = brew_fermentation.batch_id 
  AND brew_fermentation.fermentor_name=fermentor.fermentor_name 
  AND NOT EXISTS (
    SELECT 1 FROM produced_amount WHERE batch_id = batch_info.batch_id
  )
于 2013-04-23T04:56:44.663 回答