基本上我一直在研究一个 SQL 问题,该问题要求显示每种成分及其包含的食谱总数。它还必须只包括出现超过 10 次的成分以及成分流行度的降序和升序的ingrdesc
。
表格如下:
CREATE TABLE Ingredient
(
idI NUMBER constraint pk_Ingredient PRIMARY KEY ,
ingrDesc VARCHAR2(100) constraint nn1Ingredient not null
);
CREATE TABLE Recipe
(
idR NUMBER constraint pk_recipe PRIMARY KEY ,
recipeTitle VARCHAR2(200) constraint nn1Recipe not null,
prepText VARCHAR2(4000),
cuisineType VARCHAR2(50),
mealType VARCHAR2(30) DEFAULT NULL,
CONSTRAINT ch_mealType CHECK (mealType IN ('starter', 'main', 'dessert', null))
);
CREATE TABLE RecpIngr
(
idR NUMBER ,
hidI NUMBER ,
CONSTRAINT pk_RecpIngr PRIMARY KEY (idR, idI),
CONSTRAINT fk1RecpIngr_recipe foreign key(idR) references Recipe,
CONSTRAINT fk2RecpIngr_ingredient foreign key(idI) references Ingredient
)
organization index;
到目前为止,我有这个查询:
SELECT ingrDesc,
COUNT (idR) As num_of_recipes
FROM RespIngr
WHERE num_of_recipes <10
ORDER BY num_of_recipes DES, ingrDes ASC;