2015-04-12 77 views
0

我努力理解的问题是:SQL查询字母缩写

编写一个查询,列出成分的开始与初始字母字符数。你的输出应该有< = 26行并按字母顺序排列。

任何帮助将不胜感激!

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; 
+0

你必须给我们为您的家庭工作提供帮助的课程学分。 – APC

回答

0

我不知道如果我得到你的表realation权 但是这或多或少是你所需要的(很多方法可以给你同样的解决方案):

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 
+0

该解决方案缺少ORDER BY子句,因此不能保证“按字母顺序排列”。 – APC