我需要按字母顺序获取book_name
和book_code
订单by book_name
。
我有三张桌子:
表1 :
Books (Independent Table which will have all the books)
表2 :
Authors (Independent Table which will have all the authors)
表3 :
Author_Books(This table will provide the information about which book is which author's primary book.)
注意:一位作者可以拥有多本书。
我的查询输入为 Author_code 。
如果我传递Author_code,我需要获得该主要书籍 作为第一行的作者并且休息表中的所有书籍应按book_name以字母顺序排列
如果我没有将任何输入传递给我的查询,我需要所有的书籍 字母顺序。
我的查询返回作者的默认图书:
SELECT book_CD, book_NAM
from books
where Alpha_NUM_book_CD
= (SELECT Alpha_NUM_book_CD
from Author_Book
JOIN Author
on Author.NUM_Author_CD = Author_Book.NUM_Author_CD
where Author.NUM_Author_CD
= (SELECT NUM_Author_CD
from Author
where ALPHA_3_Author_CD = '')
AND Author_Book.PRIM_book_SW = 'Y'
);
如何编写满足我的案例的查询?
我们正在使用Oracle 11g。
答案 0 :(得分:0)
order by
可以使用多个键。所以,像这样:
order by (case when author.NUM_Author_CD = ? then 1 else 2 end),
book.title