问题
问答题
一个商品销售数据库中包含三个基本表:
客户表:table_Client(CNO,Cname,Csex,Cbirthday)
商品表:table_Goods(GNO,Gname,Gunit,Gprice)
购物表:table_CG(CNO,GNO,CGquantity)
用SQL语句完成下列各题。
(1)查询购买了商品的客户号及姓名。
(2)查询1978年出生的客户号及姓名。
(3)查询购买了三种以上商品的客户号及客户姓名。
答案
参考答案:
(1)select CNO,Cname
from table_Client
where CNO in
(select distinct CNO
from table_CG)
(2)select CNO,Cname
from table_Client
where Cbirthday=‘AIGH’
(3)select CNO,Cname
from table_Client
where CNO in
(select CNO
from table_CG
group by CNO
having count(*)>C)