简体   繁体   中英

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

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:00: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
;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM