如何从Caliber数据库查询?

时间:2013-02-06 06:41:18

标签: tsql calibre

如您所知calibre有一个名为metadata.db的数据库,由SQLite构成, 我想通过这些专栏来查询所有书籍:

bookId  Title   Date    Size    Rating  Tags    Publisher   PublishedDate   Author  Cover           
------  -----   ----    ----    ------  ----    ---------   -------------   ------  -----

但是,该数据库包含以下表格:

Books Table
-----------
Name
id
title
sort
timestamp
pubdate
series_index
author_sort
isbn
lccn
path
flags
uuid
has_cover
last_modified


Authors Table
-------------
Name
id
name
sort
link


Publishers Table
----------------
Name
id
name
sort

它们之间没有关系,我怎样才能得到我的查询?

1 个答案:

答案 0 :(得分:5)

SELECT id, title,
               (SELECT name FROM books_authors_link AS bal JOIN authors ON(author = authors.id) WHERE book = books.id) authors,
               (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
               (SELECT rating FROM ratings WHERE ratings.id IN (SELECT rating from books_ratings_link WHERE book=books.id)) rating,
               (SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size,
               (SELECT name FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags,
               (SELECT format FROM data WHERE data.book=books.id) formats,
               isbn,
               path,
               pubdate
        FROM books