subquery(nested query)可以使用主查询中的FROM列出的表中的列
来源:互联网 发布:好的英语听力软件 编辑:程序博客网 时间:2024/06/02 03:27
In short, a nested query works independentof the enclosing SQL statement and can make use of any of the column valuesfrom the tables listed in the enclosing statement's FROM clause. You can use nested queries to perform multi-table operations without having to JOIN rows in multiple related tables. However, if you need data values from multiple tables, or if you want individual column values and aggregate function values in the same row in the results table, you can nest a subquery with the aggregate function that you need in the SELECT clause of a multi-table query or JOIN.
SELECT trade_date, symbol, shares * price AS 'Total Trade', ( SELECT COUNT(*) FROM trades WHERE trade_date > GETDATE() - 365 AND cust_ID = CID --CID is in Customer not the trades which is the only table in this -- subquery's from clause ) AS 'Count', ( SELECT SUM(price) * SUM(shares) FROM trades WHERE trades.trade_date >= GETDATE() - 365 AND cust_ID = CID ) AS 'Total $ Volume)', CID AS 'Cust ID', TRIM(f_name)+' '+l_name AS 'Customer'FROM EI.CUSTOMERSJOIN EI.TRADESON CID = cust_CIDWHERE shares * price >= 100000AND trade_date >= GETDATE() -365ORDER BY customer;
- subquery(nested query)可以使用主查询中的FROM列出的表中的列
- sqlserver列出当前数据库中的表的行数列数
- 如何在PeopleSoft QUERY的Expressions中使用subquery
- hibernate中的Query查询和criteria查询的区别
- 查询表中的特定列的重复记录
- Lucene 查询中的距离查询(proximity query)
- Android 中数据库查询方法 query() 中的 selectionArgs 的用法
- Android 中数据库查询方法query()中的selectionArgs的用法
- Android 中数据库查询方法 query() 中的 selectionArgs 的用法
- Android 中数据库查询方法 query() 中的 selectionArgs 的用法
- Android 中数据库查询方法 query() 中的 selectionArgs 的用法
- Android 中数据库查询方法query()中的selectionArgs的用法
- 交叉表查询中的多列显示。
- 交叉表查询中的多列显示
- mysql查询表中的列名
- 列出SQL SERVER中的表
- 查询表中的标识列或者Guid列
- Oracle 查询指定表中的列名和列注释
- 前端开发者应该关注的JavaScript学习资源
- 学习钩子(Hook)过程中遇到的一些问题
- 十个jQuery图片画廊插件推荐
- Safari on iOS 支持的4种Meta Tags
- 怎样开启Win7快速启动栏
- subquery(nested query)可以使用主查询中的FROM列出的表中的列
- Android 中LayoutInflater的使用!
- Hibernate中用hql查询部分字段 可解决异常java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
- 深入理解const
- JavaScript数据库 Taffy DB
- 深入理解const char*p,char const*p,char *const p,const char **p,char const**p,char *const*p,char**const p
- X64 Linux 无法从本地字符界面登陆
- Android程序的Unable to instantiate activity ComponentInfo异常
- 10304Optimal Binary Search Tree