Foxpro VS SQL 逻辑 [英] Foxpro VS SQL Logic
问题描述
我想不出更好的标题.如果您有任何建议,请随时编辑我的帖子标题.
I couldn't think of a better title. If you have any suggestions, feel free to edit the title of my post.
我有一个看起来像这样的 foxpro 查询:
I have a foxpro query that looks like this:
Sele
a.plan_enddt as enddt, a.plrevno, a.keyfld, "PLAN " as source ;
from a_plan a inner join c_temp1a_pre b ;
on a.keyfld=b.keyfld and a.plrevno=b.plrevno ;
into cursor c_temp1a ;
group by a.keyfld ;
where a.plan_enddt>=date1 ;
我想做的是从 foxpro 转换成 T-SQL.
What I am trying to do is translate from foxpro into T-SQL.
这个 foxpro 语句会不会因为在 group by 中只列出了 1 列而失败?
Wouldn't this foxpro statement fail because only 1 column is listed in the group by?
我不是在寻找修复我的 foxpro 语句的解决方案
I am not looking for a solution to fixing my foxpro statement
在 TSQL 中,如果 select 语句中有多个列,则不能只按 1 列分组,即使您没有使用聚合函数.
In TSQL, you can't just group by 1 column if you have multiple in the select statement, even if you aren't using an aggregate function.
在 Foxpro 中也是这样吗?
Is this also true in Foxpro?
推荐答案
在 Foxpro(Visual Foxpro 8 及更早版本)中接受这种无效的 group by 子句似乎是一个错误.select 中列出的所有不是聚合值的字段也应该是 group by 字段的一部分.
It looks as bug in Foxpro (Visual Foxpro 8 and earlier) to accept such invalid group by clause. All fields listed in select that are not aggregate values should be also part of group by fields.
像这样:
选择min(a.plan_enddt) 作为 enddt, min(a.plrevno) 作为 plrevno, a.keyfld, "PLAN " 作为源从 a_plan a 内连接 c_temp1a_pre ba.keyfld=b.keyfld 和 a.plrevno=b.plrevno进入游标 c_temp1a按 a.keyfld 分组其中 a.plan_enddt>=date1 ;
或者这个:
选择a.plan_enddt 作为 enddt,a.plrevno,a.keyfld,PLAN"作为源从 a_plan a 内连接 c_temp1a_pre ba.keyfld=b.keyfld 和 a.plrevno=b.plrevno进入游标 c_temp1a分组 a.keyfld, a.plan_enddt, a.plrevno其中 a.plan_enddt>=date1 ;
但在这种情况下,您可以获得多个记录,按几个字段分组.
But in this case you can get more than one record, there is group by few fields.
这篇关于Foxpro VS SQL 逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!