zoepenn
zoepenn
2017-11-19 07:34

如何在SQL查询中进行交并操作?

  • 数据库
  • sql

比如我现在有这么一个数据库,我要从中选出season为fall的(recipeName, isKosher),isKosher是当所有ingredient的is_kosher都为true才为true, 否则为false.
我现在不懂的是,如何在SQL查询中进行isKosher的交并判断?

 CREATE TABLE ingredient (
  code          CHAR(8) PRIMARY KEY,
  name          VARCHAR(127) UNIQUE,
  is_kosher     BOOLEAN
);
CREATE TABLE recipe (
  name         VARCHAR(63) PRIMARY KEY,
  instructions TEXT,
  servings     INT,
  course       VARCHAR(15),
  season       VARCHAR(15)
);
CREATE TABLE recipe_ingredient (
  ingredient CHAR(8) REFERENCES ingredient ON UPDATE CASCADE ON DELETE SET NULL,
  recipe     VARCHAR(63) REFERENCES recipe ON UPDATE CASCADE ON DELETE CASCADE,
  amount     FLOAT
);

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答