Quizzes 1
- 一对多,哪个是FK? The personid in CAR is the foreign key .
- 如果这个attribute只在一个表里出现,就不需要item.color了
GROUP BY select max(sum(saleqty)) from qsale group by itemname (wrong) Nesting functions for ‘group by’ data is not allowed
select count(* ) from qdel group by count(* ) order by splno desc;(wrong) ‘Group by count(* )’ gives a syntax error, because the group by clause needs to target un-grouped attributes (and group them). If the argument of group by was changed to ‘splno’, the query would be correct.
- ‘FROM’ should be followed by the name of a table or query, not of a column
- After ‘or’ there should be an expression, e.g. ‘or itemcolor = ‘white’. Instead, there is only a text string.
Quizzes 2
- well-formed: tell the reader about the role of attributes
- Waston don’t show the FK, 但是还是有点别的要求。
- Table Book copy has two primary keys.(wrong) 每个表只能有一个PK,但是这个PK可以有很多个attribute
- the FKs to the mother tables also need to be part of the PK 就是loan表里的tile, copy和borrower是引自别的表的,LOAN的外键,但是同时也是LOAN主键的一部分
Quizzes 3
- 一个员工可以是很多个部门的头,但是一个部门只能有一个头,员工是多端
- 就是不join还是不行
- <>就是不等于
- ORDER BY 和GROUP BY Give sales in descending order of saleqty. select * from qsale
order by saleqty desc; - COUNT() 和SUM() Give the ==total number of deliveries== per item Count()只是计数行数, SUM()才是计算里面的 select itemname, sum(delqty) from qdel
group by itemname - group by - having
- 就是是Head还是boss的问题
- either or both black and white
- where itemcolor in (‘Black’, ‘White’)
- where itemcolor = ‘Black’ or itemcolor = ‘White’
- select itemname from qitem
where itemcolor = “Black” union select itemname from qitem
where itemcolor = “White”;
文档信息
- 本文作者:Xinyi He
- 本文链接:https://buliangzhang24.github.io/2024/05/01/SQL-Quizzes/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)