我使用聚合函数编写了几个查询,因为我无法使用winRDBI检查它们,我想问我是否正确使用它们?
以下是数据库架构:
QByteArray
我认为没有必要,但这里是我正在使用的实际数据库的PDF:Database PDF
以下是具有相应答案的查询(所有不使用聚合函数的语句都以winRDBI表示法编写):
1)列出'Henry Downtown'分行所有书籍的平均价格。
Author - (authorNum/numeric, authorLast/char, authorFirst/char) PK: authorNum
Book - (bookCode/char, title/char, publisherCode/char, type/char,
price/numeric, paperback/char) PK: bookCode
Branch - (branchNum/numeric, branchName/char, branchLocation/char, numEmployees/numeric) PK: branchNum
Inventory - (bookCode/char, branchNum/numeric, onHand/numeric) PK: bookCode
Publisher - (publisherCode/char, publisherName/char, city/char) PK: publisherCode
Wrote - (bookCode/char, authorNum/numeric, sequence/numeric) PK: bookCode,authorNum
Sequence refers to the sequence in which this author appears on the
cover – first author, second author, etc.
Copy - (bookCode/char, branchNum/numeric, copyNum/numeric,
quality/char, price/numeric) PK: bookCode, branchNum, copyNum
关系表branch_names := copy njoin (project branchNum, branchName (branch));
in_Henry_Downtown := project bookCode, copyNum, price, branchName (select
(branchName = 'Henry Downtown') (branch_names));
ans1 := bookCode g avg(price) (in_Henry_Book);
的摘录:in_Henry_Downtown
2)对于亨利书籍拥有的每本书,输出书籍代码,所有分支机构可以集体提供的总份数,以及该书副本的平均价格。
in_Henry_Downtown
关系表in_stock1 := (project bookCode (book)) njoin (project bookCode, branchNum (inventory));
copies := in_stock1 njoin (project bookCode, branchNum, copyNum, price (copy));
ans2 := bookCode g count(branchNum, copyNum), avg(price) (copies);
的摘录:copies
这是我最不确定的。我试图统计所有分支的书籍副本。因此,对于书籍代码'0200',计数应为4,b / c分支#1具有本书的副本#1和副本#2,而分支#2具有本书的副本#1和副本#2。我的过程是因为branchNum和copyNum对于特定bookCode的每个记录都是唯一的,所以我可以将这些属性用于我的count函数。
3)对于每个出版商,列出出版商的名称,出版的书籍数量以及这些书籍的平均基本价格(书籍关系包含书籍的基本价格)。
copies
关系表publisher_books := (project publisherCode, publisherName (publisher))
njoin (project bookCode, publisherCode,price (book));
ans3 := publisherName g count(bookCode), avg(price) (publisher_books);
的摘录:publisher_books
任何帮助将不胜感激!谢谢!