从select创建(查询错误)

时间:2011-09-16 11:08:56

标签: sql oracle oracle10g

create   table1 as  SELECT  from c.Name, Value, Qtr, Value as SUM(Value) 
from User.Pofile a,pet_dsa_qtr_table b,User.Count c,User.Service  d 
WHERE Category = 'PROFESSIONAL' and Item_Name = 'PROF_PKT_RECVD' and    
convert(char(32),d.User_Id) = c.Name and Service_Name_Cd = 2 
and Status = 2 and d.User_Id *= a.User_Id  and c.Period = b.Period 
and Module = 'ACCT_TRADES' and Type in ('EQ','OPTN')
GROUP BY Name, Item_Value,
Qtr HAVING SUM(Value) >= 10000  and Item_Value in ('0', NULL);

上面是我创建的一个查询,作为sybase的等价物。任何人都可以帮我纠正这个查询

1 个答案:

答案 0 :(得分:4)

您的查询中存在一些非常严重的语法不一致,我试图纠正(由于您没有提供表结构,因此猜测)。例如在选择列表中,选择“值”,但在“Item_Value”等组中的GROUP BY组中。

您还需要完全限定您的列,一些您符合条件,一些(如“模块”和“类型”等)您不需要。

您可能还想添加一个存储子句。

以下是我对你想要达到的目标的最好的猜测:

CREATE TABLE table1 
AS  
SELECT c.Name, 
       Item_Value, 
       Qtr, 
       SUM(Value) as "SUM_Value"
  FROM User.Pofile a
       pet_dsa_qtr_table b,
       User.Count c,
       User.Service d  
 WHERE Category = 'PROFESSIONAL' 
   AND Item_Name = 'PROF_PKT_RECVD' 
   AND TO_CHAR(d.User_Id) = c.Name 
   AND Service_Name_Cd = 2  
   AND Status = 2 
   AND d.User_Id = a.User_Id(+)  
   AND c.Period = b.Period  
   AND Module = 'ACCT_TRADES' 
   AND Type in ('EQ','OPTN') 
 GROUP BY c.Name, 
          Item_Value, 
          Qtr 
HAVING (SUM(Value) >= 10000  
   AND NVL(Item_Value, '0') = '0');