sql查询字母首字母

sql query alphabetical initials

我很难理解的问题是:

Write a query to list the number of ingredients starting with initial alphabetical character. Your output should have <= 26 rows and ordered alphabetically.

如有任何帮助,我们将不胜感激!

 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,
    prep Text 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;

我不确定我是否理解你的 table 关系 但这或多或少是您所需要的(许多方法可以为您提供相同的解决方案):

 select * from 
(
select distinct a.ingrDesc , b.recipeTitle 
from  Ingredient a,
    Recipe b
    RecpIngr c
where b.idR = b.idR 
and a.idI = c.idR
)
where rownum <= 26
 Order by ingrDesc