MySQL query does not work on Oracle 11g


 
Thread Tools Search this Thread
Top Forums Programming MySQL query does not work on Oracle 11g
# 1  
Old 01-19-2015
MySQL query does not work on Oracle 11g

Dear community,
I have to make a "simple" query on ORACLE 11g DB who will output ONLY numbers in field1 who exceeded a specific threshold.
In other words, assuming I have the following data in database.
Code:
FIELD1               FIELD2                FIELD3
=========            ==============        ==============
3291234567           333991123456789       1234
3277654321           333011123456789       9876
3481234567           333101123456789       1234
3291234567           333991123456789       1234
3291234567           333011123456789       1234
3277654321           333015123456789       9876
3277654321           333103123456789       9876
3277654321           333201123456789       9876
3481234567           333112123456789       1234

I want to output only number in field1 with occurrences >= 3, so the query output will be:
Code:
FIELD1        FIELD2              FIELD3
=========     ==============      ============
3277654321    333011123456789     9876
3277654321    333015123456789     9876
3277654321    333103123456789     9876
3277654321    333201123456789     9876
3291234567    333991123456789     1234
3291234567    333991123456789     1234
3291234567    333011123456789     1234

Doesn't matter the output order, the important thing is that only occurrences >= 3 based on FIELD1.

Now, this works perfect on MySQL:
Code:
     SELECT  A.FIELD1,  A.FIELD2 , A.FIELD3
        FROM 
        table A 
        INNER JOIN
        (
         SELECT FIELD1, COUNT (1) 
         FROM table
         GROUP BY FIELD1
         HAVING COUNT (1) >= 3
       ) AS B
       ON A.FIELD1 = B.FIELD1

But on ORACLE 11g I got:
Code:
       ) AS B
         *
ERROR at line 10:
ORA-00905: missing keyword

Please help!
Thanks
Lucas
# 2  
Old 01-19-2015
Code:
SQL> create table junk
  2     (field1  number,
  3      field2  number,
  4      field3  number )
  5  /

Table created.

SQL>
SQL> insert into junk values ( 3291234567, 333991123456789, 1234 );

1 row created.

SQL> insert into junk values ( 3277654321, 333011123456789, 9876 );

1 row created.

SQL> insert into junk values ( 3481234567, 333101123456789, 1234 );

1 row created.

SQL> insert into junk values ( 3291234567, 333991123456789, 1234 );

1 row created.

SQL> insert into junk values ( 3291234567, 333011123456789, 1234 );

1 row created.

SQL> insert into junk values ( 3277654321, 333015123456789, 9876 );

1 row created.

SQL> insert into junk values ( 3277654321, 333103123456789, 9876 );

1 row created.

SQL> insert into junk values ( 3277654321, 333201123456789, 9876 );

1 row created.

SQL> insert into junk values ( 3481234567, 333112123456789, 1234 );

1 row created.

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> with w_grouped as (
      select field1, field2, field3,
             count(*) over (partition by field1) field1_cnt
        from junk A
      )
select field1, field2, field3
  from w_grouped
 where field1_cnt >= 3
/
  2    3    4    5    6    7    8    9
    FIELD1     FIELD2     FIELD3
---------- ---------- ----------
3277654321 3.3302E+14       9876
3277654321 3.3310E+14       9876
3277654321 3.3320E+14       9876
3277654321 3.3301E+14       9876
3291234567 3.3399E+14       1234
3291234567 3.3399E+14       1234
3291234567 3.3301E+14       1234

7 rows selected.

This User Gave Thanks to Ditto For This Post:
# 3  
Old 01-20-2015
Well, first of all thanks for reply, this is a very interesting approach, totally new for me.
Anyway, I got the following error:
Code:
  from w_grouped
       *
ERROR at line 7:
ORA-01652: unable to extend temp segment by 640 in tablespace TEMP

Maybe due to a large ammount of data in DB?
# 4  
Old 01-20-2015
Quote:
Originally Posted by Lord Spectre
Well, first of all thanks for reply, this is a very interesting approach, totally new for me.
Anyway, I got the following error:
Code:
  from w_grouped
       *
ERROR at line 7:
ORA-01652: unable to extend temp segment by 640 in tablespace TEMP

Maybe due to a large ammount of data in DB?
Increase the size of your TEMP tablespace - it's not big enough ..
This User Gave Thanks to Ditto For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Switching user to oracle to connect Oracle 11g DB with 'sysdba'

I need to connect my Oracle 11g DB from shell script with 'sysdba' permissions. To do this I have to switch user from 'root' to 'oracle'. I've tried the following with no success. su - oracle -c "<< EOF1 sqlplus -s "/ as sysdba" << EOF2 whenever sqlerror exit sql.sqlcode;... (2 Replies)
Discussion started by: NetBear
2 Replies

2. Solaris

How to install Oracle 11g on Solaris 10

I want to install Oracle 11 on solaris 10. Can help me to find good tutorial about this? Thanks Very Much (2 Replies)
Discussion started by: moslemovic
2 Replies
Login or Register to Ask a Question