分组由3个连接组成

时间:2017-01-20 21:23:50

标签: sql oracle

我正在努力解决这个问题,我希望从3个表中获取值

 SELECT  
  table1.cedtra as cedtra,
  table1.priape as priapetra,
  table1.segape as segapetra,
  table1.prinom as prinomtra,
  table1.segnom as segnomtra,
  table2.cedcon as cedcon,
  table2.ben as ben,
  table3.priape as priapeben,
  table3.segape as segapeben,
  table3.prinom as prinomben,
  table3.segnom as segnomben,
  table3.fecnac as fecnac,
  count(table1.cedtra) as numero 
  FROM table2, table1, table3 
  WHERE table2.id = table1.id 
  and table2.ben = table3.ben 
  and table2.doc = '12345' 
  and table2.codcit = '12345' 
  group by table1.cedtra, table2.ben, table1.cedtra, table1.priape, table1.segape, table1.prinom, table1.segnom, table3.priape, table3.segape, table3.prinom, table3.segnom, table3.fecnac 
  having count(table1.cedtra) > 3

我按照我选择的字段进行分组,减少计数为numero但是这给我带来了这个错误:

  

ORA-00979:不是表达式GROUP BY

我尝试使用别名,但我得到了相同的结果。

任何建议都是有意义的!

2 个答案:

答案 0 :(得分:2)

不 - 您不是按table2.cedcon分组,而是select分组。

不要尝试使用SELECT子句中的列别名进行分组 - 在SELECT之前处理group by。

也无需在GROUP BY中两次显示相同的列。

答案 1 :(得分:1)

尝试从您的选择列表中删除table1.cedtra as cedtra,然后通过

从您的论坛中删除table1.cedtra