MySQL-SQL and Relational Algebra queries

发布于 2016-10-26 00:22:13 字数 676 浏览 1180 评论 1

This section asks you to write some queries in Relational Algebra and SQL.Your SQL queries will be graded by running them in MySQL on test cases; queries that return the wrong answer will receive 0 points, i.e. there is no partial credit. In particular, please make sure your query returns the right column(s).

Consider the schema given by the following two SQLCREATEstatements.

CREATE TABLE SuppInfo (suppid INTEGER NOT NULL,
prodid INTEGER NOT NULL,
PRIMARY KEY (suppid, prodid));

CREATE TABLE Purchases (purchaseid INTEGER PRIMARY KEY,
custid INTEGER,
prodid INTEGER,
purchasemethod INTEGER);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虐人心 2017-08-15 00:46:19

relational algebra这么高深的玩意就不做了.

mysql:

题一:
select prodid, group_concat(suppid) from SuppInfo group by prodid;

题二:
select custid from Purchases group by custid having count(distinct purchasemethod)>1;
select custid from Purchases P1 where exists (select 1 from Purchases P2 where P1.purchasemethod <> P2.purchasemethod );

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文