求职 写出查询所有客户及其对应的客户类型的 SQL

沐沐 · 2018年05月24日 · 最后由 沐沐 回复于 2018年05月26日 · 2631 次阅读

各位伙伴帮忙指导指导给出正确答案,感激不尽
客户表 cts
客户 ID 客户 (user) 其他信息 (other) 客户类型 ID(ctsType ID)
1 张三 aa 001
2 李四 bb 002
3 王二 cc 003
4 刘一 dd 004

客户类型表 ctstype
客户类型 ID(ctsType ID) 客户类型
001 金钻客户
002 黄钻客户
003 普通客户

1.写出查询所有客户及其对应的客户类型的 SQL 语句

2.写出查询结果

自己做的结果:

  1. select a.* ,b.* from cts a, ctstype b where a.ctsType ID=b..ctsType ID

2.

客户 ID 客户 (user) 其他信息 (other) 客户类型 ((ctsType ID)
1 张三 aa 001 金钻客户
2 李四 bb 002 黄钻客户
3 王二 cc 003 普通客户

共收到 10 条回复 时间 点赞

1、select cts.name, ctstype.客户类型
from cts
left join ctstype
on cts.ctsType ID=ctstype.ctsType ID
上面这个语句我还没测试过。。(未经测试的代码都应该质疑)

2、结果应该是
1 张三 金钻客户
2 李四 黄钻客户
3 王二 普通客户
4 刘一

你也可以自己建一张表测试一下😂

select cts.,ctstype. from ctstype left join cts on cts.ctsType ID=ctstype..ctsType ID ,查询的 * 没显示

匿名 #5 · 2018年05月25日

卧槽 怎么这么熟悉 的题目?你到我这面试了?

真的假的,有这么巧的事啊


这样?

Ikaros灬 回复

沐沐 回复

😂 测试了一下好像不是这样的,这个查询结果如同:
select s.user, s.ctsType ID ,c.ctsType ID from cts s, ctstype c where s.ctsType ID=c.ctsType ID;语句的查询结果

诸葛流年 回复

受教了,图片中 * 不能这么表示,要把所有字段敲出来

😒 很遗憾,没能和你成为同事

沐沐 #10 · 2018年05月26日 Author
Jagga 回复

对的,谢谢你提供了正确答案

沐沐 关闭了讨论 05月28日 17:09
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册