作为计算字段使用子查询
2016-03-04 14:10
211 查看
使用子查询的另一个方法是创建计算字段。
例子:假如需要显示customers表中每个客户的订单总数,而订单与对应的客户ID存储在orders表中。
思路:1,先从customers表中检索客户列表
2,对于检索出的每个客户,统计其在orders表中的订单数目。
语句:
Select cust_name,(Select count(*) From orders
where custermers.cust_id=orders.cust_id AS order)
From customers
Order by cust_name;
例子:假如需要显示customers表中每个客户的订单总数,而订单与对应的客户ID存储在orders表中。
思路:1,先从customers表中检索客户列表
2,对于检索出的每个客户,统计其在orders表中的订单数目。
语句:
Select cust_name,(Select count(*) From orders
where custermers.cust_id=orders.cust_id AS order)
From customers
Order by cust_name;
相关文章推荐
- MAC设置自动关机详细教程
- Nginx:fastcgi_param详解
- 用https访问GIT服务时避免输入用户名、密码的方法
- 前端开发面试题
- device tree 的device node 怎么才能device add to bus???
- 【计算机】DMA原理2
- 使用游标循环插入
- BC23&&hdoj5146&&hdoj5147
- Spring使用Cache、整合Ehcache
- Mybatis与Ibatis比较
- 【jeecg移动开发能力】Jeecg 重磅来袭,强大移动报表配置能力,一次配置七种展现风格
- IBM Rational ClearCase 部署指南
- Elasticsearch学习笔记
- WebBuilder7 在Linux、Tomcat、MySQL下配置注意事项
- ZOJ 1420 Cashier Employment
- java学习笔记-java异常处理机制
- forward与direct的区别
- Windows Server 2008 R2服务器远程连接把上一个连接挤掉
- Linux创建目录【命令】
- Socket编程中的inputstream阻塞问题