我有一个非常大的选择,我必须加入两个结果,但我无法找到一种方法使其工作。代码类似于:
(select isnull(sum(fn.tqq),0) from fn where fn.icecream in (1,2,3,4,5,6,7,8,9) and (fn.fdata BETWEEN #2# AND #3#) and fn.usr1 not like '%'+'CHOC'+'%') as Total1,
(select isnull(sum(fn.tqq),0) from fn where fn.icecream in (1,2,3,4,5,6,7,8,9) and (fn.fdata BETWEEN #4# AND #5#) and pn.usr1 not like '%'+'Portes'+'%') as Total2,
事情是,我必须最终加入icream 3和7以及冰淇淋8和9的结果。
答案 0 :(得分:0)
虽然标记为VFP,但该示例SQL听起来不是VFP查询,也不是MS SQL服务器查询。如果有一秒钟我们认为这是一个有效的SQL,那么你可以得到你最初在代码中提出的建议:
Select t1.Total1, t2.Total2 From ;
(Select Nvl(Sum(fn.tqq),0) As Total1 ;
from fn ;
where fn.icecream In (1,2,3,4,5,6,7,8,9) And ;
(fn.fdata Between #2# And #3#) And ;
fn.usr1 Not Like '%'+'CHOC'+'%') t1, ;
(Select Nvl(Sum(fn.tqq),0) As Total2 ;
from fn ;
where fn.icecream In (1,2,3,4,5,6,7,8,9) And ;
(fn.fdata Between #4# And #5#) And ;
fn.usr1 Not Like '%'+'Portes'+'%') t2
或(更多VFP特定查询):
Select ;
Sum(Iif( InList(icecream,1,2,3,4,5,6,7,8,9) And ;
Between(fdata, #2# , #3#) And ;
!('CHOC'$usr1), tqq, 0)) as Total1, ;
Sum(Iif( InList(icecream,1,2,3,4,5,6,7,8,9) And ;
Between(fdata, #4# , #5#) And ;
!('Portes'$usr1), tqq, 0)) as Total2 ;
from fn
然而,阅读你的最后一句话,你真正想要的更令人困惑。如果上述情况不符合您的要求,请向我们提供一些示例数据和您想要达到的结果,以便我们提供更好的数据。
答案 1 :(得分:0)
{{1}}
我想要发生的是,供应商'3'来取代数字'7',数字'8'来取代'9'。我得到重复的结果,当我想要的是数字'3'和'7'的结果为一个(数字'8'和'9'相同)。