开发者

Error with SQL statement when I try to migrate it from mysql to Oracle

开发者 https://www.devze.com 2023-03-28 17:05 出处:网络
I shouldmigratemy database from mysql to oracle, My problem is that my satement don\'t work any more! and I should keep the same format(alias champ1,champ2)

I should migrate my database from mysql to oracle, My problem is that my satement don't work any more! and I should keep the same format(alias champ1,champ2)

this is my SQL Statement:

select count(j.id) as nb, p.pname as champ1,proj.pname as champ2 
from  jiraissue j  
join priority p on (p.id=j.priority)
join project proj on(proj.id=j.project)
join issuestatus iss on (iss.id=j.issuestatus)
join issuetype isst on(isst.id=j.issuetype )
where j.CREATED between '2011-05-18 00:00:00.0' and '2011-06-05 00:0开发者_StackOverflow社区0:00.0'
and iss.pname='Open' 
group by champ1,champ2;

The error:

ORA-00904: "CHAMP2" : identificateur non valide
00904. 00000 -  "%s: invalid identifier"

PS:When I remove groupby and the alias from select and execute also an error appear indicate that the format of the date is invalid

ORA-01861: le littéral ne concorde pas avec le format chaîne de caractères


For a whole host of reasons, most implementations fo SQL do not allow you to GROUP BY something that you have aliased in the SELECT section of your query.

select count(j.id) as nb, p.pname as champ1,proj.pname as champ2 
from  jiraissue j  
join priority p on (p.id=j.priority)
join project proj on(proj.id=j.project)
join issuestatus iss on (iss.id=j.issuestatus)
join issuetype isst on(isst.id=j.issuetype )
where
  j.CREATED between '2011 May 18' and '2011 June 05'
  and iss.pname='Open' 
group by
  p.pname,
  proj.pname
;


EDIT - follow up to comment:

I'm uncertain as to why the above answer doesn't quite help you, maybe you don't want to repeat yourself in the code? (Something you gain by grouping by aliases, and so lose in every other rdbms) If so, the following pattern may help...

SELECT
  COUNT(j_id) AS nb, champ1, champ2
FROM
(
  select j.id AS j_id, p.pname as champ1, proj.pname as champ2
  from  jiraissue j  
  join priority p on (p.id=j.priority)
  join project proj on(proj.id=j.project)
  join issuestatus iss on (iss.id=j.issuestatus)
  join issuetype isst on(isst.id=j.issuetype )
   where
    j.CREATED between '2011 May 18' and '2011 June 05'
    and iss.pname='Open' 
)
  AS data
GROUP BY
  champ1,
  champ2
;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号