题目描述:
问题:
1) 查找客户号“88888888”的2009全年的存款流水,按日期升序排列
SELECT Did
FROM Deposit
WHERE Cid = ‘88888888’
AND TradeDate
BETWEEN 20090101 AND 20091231
ORDER BY TradeDate ASC;
2) 针对上面的查询要求,为Deposit表创建一个索引idx_Deposit
Create index inx_Deposit on Deposit;
3) 输出整个银行2009年全年各网点名称及对应的存款总额。
SELECT DName, SUM(Amount)
FROM Deposit, Dept
WHERE Deposit.DeptId = Dept.DeptId
AND TradeDate
BETWEEN 20090101 AND 20091231
GROUP BY DeptId;
4) 列出曾经有多笔(2笔或者大于2笔)存款的客户号。
SELECT Cid
FROM Customer c, Deposit d
WHERE c.Cid = d.Cid
GROUP BY d.Did
HAVING COUNT(*) >= 2
注:COUNT(*)返回的是在给定的选择中被选的行数
5) 列出客户信息表中没有存款交易的客户,输出客户号和客户姓名。
SELECT Cid, CName
FROM Customer
WHERE (SELECT Cid
FROM Customer c, Deposit d
WHERE c.Cid = d.Cid
AND d.Amount = ‘0’);