以下任务的 SQL 语句是什么:
What is the SQL statement for the following task:
列出出版平装书的出版商以及每个出版商出版的平装书数量。
我在计算每个出版商的平装本时遇到了困难。任何帮助都感激不尽。谢谢!
亨利图书 Table 架构
**author**
authorNum INT PRIMARY KEY
authorLast VARCHAR(12),
authorFirst VARCHAR(10)
**publisher**
publisherCode CHAR(3) PRIMARY KEY
publisherName VARCHAR(25)
city VARCHAR(20)
**book**
bookCode CHAR(4) PRIMARY KEY
title VARCHAR(40)
publisherCode CHAR(3)
bookType CHAR(3)
paperback ENUM('No', 'Yes')
CONSTRAINT book_fk_publisher
FOREIGN KEY (publisherCode)
REFERENCES publisher(publisherCode)
**branch**
branchNum INT
branchName VARCHAR(50)
branchLocation VARCHAR(50)
**copy**
bookCode CHAR(4)
branchNum INT
copyNum INT PRIMARY KEY
quality ENUM('Excellent', 'Fair', 'Good', 'Poor')
price DECIMAL(8,2)
CONSTRAINT copy_pk
PRIMARY KEY (bookCode, branchNum, copyNum
CONSTRAINT copy_fk_book
FOREIGN KEY (bookCode)
REFERENCES book(bookCode),
CONSTRAINT copy_fk_branch
FOREIGN KEY (branchNum)
REFERENCES branch(branchNum)
**wrote**
bookCode CHAR(4)
authorNum INT
sequence INT
PRIMARY KEY (BookCode, AuthorNum),
CONSTRAINT wrote_fk_book
FOREIGN KEY (bookCode)
REFERENCES book(bookCode),
CONSTRAINT wrote_fk_author
FOREIGN KEY (authorNum)
REFERENCES author(authorNum)
这是我的:
SELECT publisherName, COUNT(paperback) AS "numPaperback"
FROM publisher, book
WHERE paperback = "Yes";
看来你是新来的。所以我会试着引导你完成这个...
将出版商table加入图书table。他们共享一个出版商代码,link 他们在一起。
使用 where
子句按书籍类型过滤加入的 table。你想要平装书。
对出版商代码和名称执行group by
,然后count
图书栏目
这对您有帮助吗?
您必须使用 count(*) 和 Group by 来计算平装书的数量。这就是我编写查询的方式:
SELECT publisherName,count(*) AS "Number of paperbacks" FROM
publisher p INNER JOIN book b WHERE
p.publisherCode=b.publisherCode AND b.paperback="Yes"
GROUP BY publisherName;
列出出版平装书的出版商以及每个出版商出版的平装书数量。 我在计算每个出版商的平装本时遇到了困难。任何帮助都感激不尽。谢谢!
亨利图书 Table 架构
**author**
authorNum INT PRIMARY KEY
authorLast VARCHAR(12),
authorFirst VARCHAR(10)
**publisher**
publisherCode CHAR(3) PRIMARY KEY
publisherName VARCHAR(25)
city VARCHAR(20)
**book**
bookCode CHAR(4) PRIMARY KEY
title VARCHAR(40)
publisherCode CHAR(3)
bookType CHAR(3)
paperback ENUM('No', 'Yes')
CONSTRAINT book_fk_publisher
FOREIGN KEY (publisherCode)
REFERENCES publisher(publisherCode)
**branch**
branchNum INT
branchName VARCHAR(50)
branchLocation VARCHAR(50)
**copy**
bookCode CHAR(4)
branchNum INT
copyNum INT PRIMARY KEY
quality ENUM('Excellent', 'Fair', 'Good', 'Poor')
price DECIMAL(8,2)
CONSTRAINT copy_pk
PRIMARY KEY (bookCode, branchNum, copyNum
CONSTRAINT copy_fk_book
FOREIGN KEY (bookCode)
REFERENCES book(bookCode),
CONSTRAINT copy_fk_branch
FOREIGN KEY (branchNum)
REFERENCES branch(branchNum)
**wrote**
bookCode CHAR(4)
authorNum INT
sequence INT
PRIMARY KEY (BookCode, AuthorNum),
CONSTRAINT wrote_fk_book
FOREIGN KEY (bookCode)
REFERENCES book(bookCode),
CONSTRAINT wrote_fk_author
FOREIGN KEY (authorNum)
REFERENCES author(authorNum)
这是我的:
SELECT publisherName, COUNT(paperback) AS "numPaperback"
FROM publisher, book
WHERE paperback = "Yes";
看来你是新来的。所以我会试着引导你完成这个...
将出版商table加入图书table。他们共享一个出版商代码,link 他们在一起。
使用
where
子句按书籍类型过滤加入的 table。你想要平装书。对出版商代码和名称执行
group by
,然后count
图书栏目
这对您有帮助吗?
您必须使用 count(*) 和 Group by 来计算平装书的数量。这就是我编写查询的方式:
SELECT publisherName,count(*) AS "Number of paperbacks" FROM
publisher p INNER JOIN book b WHERE
p.publisherCode=b.publisherCode AND b.paperback="Yes"
GROUP BY publisherName;