WITH AS短语,也叫做子查询部分(subquery factoring)
2013-09-27 09:54
621 查看
可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到。
作为提供数据的部分。
代码例子:
View Code
参考:sql with as 用法
作为提供数据的部分。
代码例子:
with temp as (select ID, Type_Name, Type_ID from T_Base_GoodsType as t where t.Shop_ID = @shop_id and Type_ID = @Goods_TypeID union all select t1.ID, t1.Type_Name, t1.Type_ID from T_Base_GoodsType as t1 inner join temp on t1.ParentType_ID = temp.Type_ID where t1.Shop_ID = @shop_id) select * from (select Stock_Amount, S.StockWarn_Amount, S.All_Amount, G.Goods_ID, G.Goods_Name, G.Goods_Unit, ROW_NUMBER() over(order by Stock_Amount desc) as rowid from T_IM_StockInfo as S inner join T_Base_GoodsInfo AS G on S.Goods_ID = G.Goods_ID inner join temp on temp.Type_ID = G.Goods_TypeID where S.Shop_ID = @shop_id AND G.Shop_ID = @shop_id and G.Goods_TypeID = temp.Type_ID group by S.Stock_Amount, S.All_Amount, G.Goods_ID, G.Goods_Name, G.Goods_Unit, S.StockWarn_Amount HAVING SUM(S.Stock_Amount) < S.StockWarn_Amount) m WHERE rowid between @pageindex and @pagesize
View Code
参考:sql with as 用法
相关文章推荐
- MYSQL --Subquery returns more than 1 row查询结果多于一行
- Recursive Subquery Factoring (Recursive WITH)
- lucene-查询query->PhrasePrefixQuery使用短语缀搜索
- MYSQL --Subquery returns more than 1 row查询结果多于一行
- Subquery returns more than 1 row查询结果多于一行
- Oracle 11g R2 RSF(Recurive Subquery factoring)
- oracle查询报这个错误:single-row subquery returns more than one row
- oracle order by subquery innerview(嵌套子查询中不允许出现order by 语句)
- mysql子查询用limit报错( “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ”)
- MySQL EXPLAIN 独立子查询dependent subquery 优化示例
- CTE和WITH AS短语结合使用提高SQL查询性能
- MYSQL --Subquery returns more than 1 row查询结果多于一行
- 关于关联子查询--correlated subquery
- Oracle 11gR2 RSF(Recurive Subquery factoring)
- MYSQL --Subquery returns more than 1 row查询结果多于一行
- 解决"Subquery returns more than 1 row"sql查询错误
- MySQL SQL优化案例:相关子查询(dependent subquery)优化
- CTE和WITH AS短语结合使用提高SQL查询性能
- The filter pushed in subquery issue in oracle 11G (filter推进子查询)
- WITH Clause : Subquery Factoring