SQL query does not work coccrectly

The table contains the list of months and years.
When I write
SOME MONTHS, YEAR FROM MONTH_DETAILS ORDER BY DESC, YEAR DESC;
It works correctly and returns
MONTH YEAR
7 2009
6 2009
5 2009
4 2009
3 2009
2 2009
1 2009
12 2008
11 2008
But when I want to get only the first (month = 7 and year = 2009) and change the query like this
SOME MONTHS, the YEAR OF MONTH_DETAILS WHERE ROWNUM = 1 ORDER BY YEAR DESC, DESC;
It returns
MONTH YEAR
2 2009
.
What is the problem?
The year and month fields are defined as numbers.
SELECT MONTH,YEAR FROM (select * from MONTH_DETAILS ORDER BY YEAR DESC,MONTH DESC) WHERE ROWNUM=1 

first make order and apply the rownum on him...

Ravi Kumar

Tags: Database

Similar Questions

  • SQL query does not work well

    Hello
    I did a small table with 5 rows and want to make a consult sql using rownum

    so I'm running
    select * from mytable where rownum = 1;
    and it gives me the first line but if I change the 1 to a 2 or 3 or 4 or 5, it is said that there's nothing: S

    why?????????????????????

    But if I change to between 1 and 5, he gave me 4 rows: S: S

    why???????????????????

    Try this:

    SELECT *
    FROM (
       SELECT bne.*, rownum myrow
       FROM BAN_EVENTOS_CONFIRMACION bne WHERE ROWNUM <=5)
    WHERE myrow = 2;
    
  • Correlation query does not work

    create the table cust_age_sal (cust_id integer, integer whole age of sal);

    create the table new_cust_age_sal (cust_id integer, integer whole age of sal);

    insert into cust_age_sal values (1,10,100);

    insert into cust_age_sal values (2,20,200);

    insert into cust_age_sal values (3,30,300);

    insert into cust_age_sal values (4,40,400);

    commit;

    insert into new_cust_age_sal values (2,21,201);

    insert into new_cust_age_sal values (3,31,301);

    commit;


    Question

    I want to update cust_age_sal using the customer_id which are present in the new_cust_age_sal;

    I use queries, query1 and query2. Query1 is working and I get results and I want to know what is the problem with query2 and why it does not work

    Query1:

    UPDATE cust_age_sal u

    SET (age, sal) =

    (

    SELECT age, sal

    OF new_cust_age_sal

    WHERE cust_id = u.cust_id

    )

    where u.cust_id in (select cust_id from new_cust_age_sal)

    ---

    query2:

    UPDATE cust_age_sal

    SET (age, sal) =

    (

    SELECT age, sal

    OF new_cust_age_sal

    WHERE cust_id = u.cust_id

    )

    Hello

    2742751 wrote:

    It is except o/p I'm looking

    O/p: except

    I think you want to say "whereas", not "excluded".

    CUST_ID AGE SAL

    ---------------------- ---------------------- ----------------------

    1                      10                     100

    2                      21                     201

    3                      31                     301

    4                      40                     400

    But when I run under query that is show below output even if I use the join on the target table condition. Why is it show empty for CUST_ID = 1 and 4

    UPDATE cust_age_sal u

    SET (age, sal) =

    (

    SELECT age, sal

    OF new_cust_age_sal

    WHERE cust_id = u.cust_id

    )

    CUST_ID AGE SAL

    ---------------------- ---------------------- ----------------------

    1

    2                      21                     201

    3                      31                     301

    4

    A UPDATE instructions without WHERE clause will update with each row in the table.

    In the case of cust_id = 1, what will that do?  Well, what makes the following query?

    SELECT age, sal

    OF new_cust_age_sal

    WHERE cust_id = 1;

    ?  It produces no line.  When you use a subquery in a SET of an UPDATE statement clause (as you do) and the subquery returns no rows, then updated the columns with a NULL value.

    If you don't want to update all rows, but want lines updates which fulfil certain conditions (for example, have a corresponding row in new_cust_age_sal), and then use a WHERE clause in the UPDATE statement, as you did in your first UPDATE statement.

    Instead of an UPDATE statement, you can also use a MERGE statement, like this:

    MERGE INTO dst cust_age_sal

    With the HELP of new_cust_age_sal CBC

    WE (dst.cust_id = src.cust_id)

    WHEN MATCHED THEN UPDATE

    SET dst.age = src.age

    dst.sal = src.sal,

    ;

    In this way, you don't need to repeat what is essentially the same subquery in the GAME and WHERE clauses.

  • Query does not work on my iPad (was: media query question)

    I am a site for mobile/tablet/Office of coding and while my office and the iphone respond to the CSS, my ipad does not work. The changes that I do take the tablet in dreamweaver, but when they go live the ipad does not. Of course, my media query must be incorrect, but I can't understand the question. Any help is very appreciated.

    http://gbetza.mydomain.com/WebService2/test/KathrynFee/2014/profile.html

    Thank you.

    Yes.  It is inevitable because smart phones are getting bigger while tablets are smaller & more.  He's always going to be some crossover.   Think of it this way, when a Tablet is behaving as a mobile device, he takes over the mobile network.  When the shelf behaves more like a desktop computer, you need the layout of office.

    Similarly, a great smartphone in landscape mode is likely to resemble the layout of your tablet.

    See the FluidGrid example below:

    http://ALT-Web.com/FluidGrid/Fluid2.html

    Office = 4-col layout

    Tablet = 2-col layout

    Mobile = 1-col layout

    For purposes of illustration, I added a thick border of gold at the disposal of the Tablet only.

    / * Tablet Layout: 481px to 768px. Inherits the styles of: Mobile layout. */

    @media only screen and (min-width: 481px) and (max-width: 768px) {}

    .gridContainer {width: 92%; border: 16px solid gold}

    }

    Nancy O.

  • WS 2.0 query does not work

    Hi all

    I have a small problem...

    I'm trying to create a query with ws 2.0 but I Don t get a response but the 400 error message.
    The connection works very well and I also get my session ID, but when I try to do a query it always comes with the
    Server returned HTTP response code: 400 for URL: https://secure-ausomxgva.crmondemand.com/Services/Integration/CustomObject5;jsessionid=4e06330622aaf934c2068a7b02766c1c0a5eda9a04782b201b63fba91893bb80.e3iRbxiPbxj0bNaKaxaSa3n0;

    I Don t know why it does not work... my SOAP Message I send to the system looks like this:

    <? XML version = "1.0" encoding = "utf-8"? >
    < xmlns:soap: envelope soap = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance".
    xmlns:WSSE = "http://schemas.xmlsoap.org/ws/2002/xx/secext" container = "http://www.w3.org/2001/XMLSchema".
    SOAP: encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/" >
    < soap: Body >

    < CustomObject5QueryPage_Input xmlns = "urn: crmondemand/ws/ECB/customobject5/10/2004" >
    < ListOfCustomObject5 xmlns = "" urn: / crmondemand/CustomObject5/query/xml "pagesize ="100"recordcountneeded ="true"startrownum ="0">"
    < CustomObject5 searchspec = "[CustomObject5Id] AS ' *'" >
    < CustomObject5Id / >
    < / CustomObject5 >
    < / ListOfCustomObject5 >
    < / CustomObject5QueryPage_Input >

    < / soap: Body >
    < / envelope soap: >

    I programmed in Java. The Soap Action is "document / urn: crmondemand/ws/customobject5/10 / 2004:CustomObject5QueryPage.
    I hope someone can help me or identifies an error...

    If you want more information, just ask. I'm looking for this error several hours now without success...

    Thank you very much in advance!

    You could try changing your SOAPAction header to
    "document / urn: crmondemand/ws/ECB/customobject5/10 / 2004:CustomObject5QueryPage.

    Also, you should be able to recover the additional error information in your application. When I tried a request with the HTTP SOAPAction header that you use, I got the following error message:

    The remote server returned an error: bad request (400).

    The HTTP request did not contain a valid SOAP action header. The value of the header has been "document / urn: crmondemand/ws/customobject5/10 / 2004:CustomObject5QueryPage.

  • my SQL Developer does not work properly! Help

    Hello!!

    My problem here is not like I can't live or work, but it's REALLY annoying, see my SQL Developer does not take any different key of letters and the space bar, I mean, if I use the Enter key, does not alter the line, if I use the return key back isn't clear if I use F5/F9 does not execute the msec! and if the keys don't work!

    any ideas why this is happening? and if yes how do fix this problem?

    There is a well known bug but still not solved, causing this type of behavior, if you are a developer SQL 1.5.X you can work around the problem by loading the accelerators by default:

    Tools-> accelerators-> load Preset-> by default

    If you're on 2.1.X preset may be responsible for

    Tools-> preferences->-> others-> load keyboard accelerators

    2.1 this problem has not been reported so far, so if you are in 1.5.X you can consider upgrading.

  • Shortcut Ctrl-Qoute for Refacturing in the context of SQL-worksheet does not work

    Hello

    the shortcut ctrl-quote in the contextmenu for SQL-worksheet Refacturing does not work on my German keyboard. I am tired of all combinations... functionality works via the context menu, but it's too slow to call him 3 times to get the source code in lower case.

    ... Any help?

    Thanks, Jürgen

    Try redefining it in tools | Preferences | Accelarators.

  • Describe in SQL script does not work as you wish

    Hello

    Could you please help me determine why this script does not work.
    He said that the date is not set.

    Thanks in advance


    set p_day_sh = & data_sh
    set p_rowid_sh = & rowid_sh
    declare
    date of p_day_sh;
    p_rowid_sh varchar2 (18);
    Start

    If & p_day_sh is not null then
    trains t update
    Set t.offdate = to_date ('& p_day_sh ',' DD-MM-YYYY HH24:MI:SS')
    where t.rowid = '& p_rowid_sh';
    commit;
    end if;
    end;

    Hello

    In a command SET, if the string to the right of the = sign contains spaces, then it must be in quotes: in the case otherwise, only the first group of characters, white space will be affected.
    For example:

    define p_day_sh = &data_sh
    

    If & data_sh has this value:

    11-06-2009 06:25:09
    

    then the DEFINE command is

    define p_day_sh = 11-06-2009 06:25:09
    

    and & p_day_sh Gets the value of the part to the workspace:

    11-06-2009
    

    Either eliminate the space, Alex has proposed, or place the chain on the right side of the sign = in double - quote:

    define p_day_sh = "&data_sh"
    

    The double quotes will not change the meaning if & data_sh contains no white space.

  • Query does not work in: interactive report _ APEX

    Hello

    I have two table QB_COLLEGE_DETAILS and QB_STUDENT_DETAILS, in the college details are stored in the QB_COLLEGE_DETAILS table and by studying the details are stored in the QB_STUDENT_DETAILS table. In the primary key table and foreign key in the COLLEGECODE.  Now, I created the interactive report using code below, but does not receive the correct value in the number of student column (see image below).

    SELECT COLLEGENAME, COLLEGECODE, COORDNAME, COORDEMAIL,

    (SELECT count (s.STUDENT_REGISTER_NUMBER) AS STUD_COUNT of QB_COLLEGE_DETAILS c, s QB_STUDENT_DETAILS

    where c.COLLEGECODE = s.COLLEGECODE) "STUDENT_COUNT".

    of QB_COLLEGE_DETAILS;

    Report.JPG

    My requirement is necessary find the number of students at the corresponding College. When I used above mentioned request that total student number appear in all lines.

    could you add your suggestion, I have to do?

    Thank you

    Issac

    ISSAC-Oracle wrote:

    I have two table QB_COLLEGE_DETAILS and QB_STUDENT_DETAILS, in the college details are stored in the QB_COLLEGE_DETAILS table and by studying the details are stored in the QB_STUDENT_DETAILS table. In the primary key table and foreign key in the COLLEGECODE.  Now, I created the interactive report using code below, but does not receive the correct value in the number of student column (see image below).

    SELECT COLLEGENAME, COLLEGECODE, COORDNAME, COORDEMAIL,

    (SELECT count (s.STUDENT_REGISTER_NUMBER) AS STUD_COUNT of QB_COLLEGE_DETAILS c, s QB_STUDENT_DETAILS

    where c.COLLEGECODE = s.COLLEGECODE) "STUDENT_COUNT".

    of QB_COLLEGE_DETAILS;

    My requirement is necessary find the number of students at the corresponding College. When I used above mentioned request that total student number appear in all lines.

    could you add your suggestion, I have to do?

    What you need to do is ask questions properly, providing useful information that allowing the problem can be reproduced, rather than unnecessary screenshots.

    This is the base of SQL. Oracle run internal SQL training courses?

    There is no correlation in your "virtual column" subquery to restrict the number of students for each college. The request must be:

    select
        c.collegename
      , c.collegecode
      , c.coordname
      , c.coordemail
      , (select count(s.student_register_number) as stud_count from qb_student_details s where c.collegecode = s.collegecode) "STUDENT_COUNT"
    from
        qb_college_details c
    

    However, unless there are a large number of colleges to which no students registered, it is likely that it will be more efficient to use an outer join:

    select
        c.collegename
      , c.collegecode
      , c.coordname
      , c.coordemail
      , count(s.student_register_number) student_count
    from
        qb_college_details c
          left outer join qb_student_details s
            on c.collegecode = s.collegecode
    group by
        c.collegename
      , c.collegecode
      , c.coordname
      , c.coordemail
    
  • SQL Query Help (not working not properly)

    Hello everyone,

    I use JDeveloper 12.1.2.0.0. I do a two-way communication using 3 tables, with links between them (and using schema HR).

    In my example, I have something like:

    Departments, employees, and the SalaryByJobs (I created this table where it shows a departmentd id, employee id, salary).

    Whenever I click on one OR more departments, the employees up-to-date table by putting on the table, employees who belong to the selected department and the salaryByjob to put the jobs of the employees selected on the employees table.

    So it's something like this:

    The departments selected-> employees selected-> salarybyjbobs of these employees.

    My query used (in the view) has the following code:

    SELECT Employees.COMMISSION_PCT,

    Employees.DEPARTMENT_ID,

    Employees.EMAIL,

    Employees.EMPLOYEE_ID,

    Employees.FIRST_NAME,

    Employees.HIRE_DATE,

    Employees.JOB_ID,

    Employees.LAST_NAME,

    Employees.MANAGER_ID,

    Employees.PHONE_NUMBER,

    Employees.SALARY

    Employees EMPLOYEES

    WHERE (department_id IN (select * from THE (select cast (in_list(:variavel3) as mytableType) double) a))

    Since I use the links, the employees table does not show anything at the beginning, so I added this to my query used to go: OR nvl(:variavel3,0) = 0

    But now, whenever I try to select multiple lines, it gives me the invalid numbers and I don't understand why...

    It's only one line of code and it is not in the bean.

    Can someone help me?

    PS - The bean will Department by Department, adds the departments with ',' and for each Department, gets employees who belongs to them.

    My best regards,

    Frederico Barracha.

    The expression NVL (: variavel3, 0) = 0 is not correct. The data type of the return value of the NVL function is considered to be equal to the data type of the argument of 1 (that is, the data type of the variable binding: variavel3). You said that this variable contained a list separated by commas to ID, so the data type of the variable is VARCHAR2. As long as you compare the NVL expression of a number, you get 'Invalid number' exception, because Oracle expects a numeric data type on the left side of the comparison operator.

    To avoid the exception "Invalid number", you can modify the expression by using one of the following options:

    : variavel3 IS NULL

    NVL (: variavel3, ' *') = ' *'

    NVL (: variavel3, ' 0') = '0'

    Option 1, so the simplest and clearest.

    Dimitar

  • Query does not work in MySql

    I have a script of calendar that I use to get the numbers in the table and showing them in a calendar. The query works in Access, but not in MySql. What is the problem with the syntax?

    Error: [MySQL] [ODBC 3.51 Driver] [mysqld - 4.0.26 - standard], you have an error in your SQL syntax. Consult the manual for your version of the MySQL server for the right syntax to use near ' (date_added) LIKE dd FROM estar_pledge WHERE date_a

    I'm really confused, if any help on that would be great, thanks.

    Chris

    Mysql documentation:
    Day (date)

    Day() is synonym for DAYOFMONTH(). It is available from MySQL 4.1.1.
    HTH
    --
    Tim Carley
    www.recfusion.com
    [email protected]

  • Classic report, query does not work

    Hello

    I have a query that allows to choose from a table manufacturing exists in the other. It works in another query editor. But not in the Apex or in classic report page.

    SELECT q.user_name, COUNT (*) say
    OF kom_qabz.kom_qabz q
    WHERE q.amount IS NOT NULL
    AND THERE ARE
    (SELECT 1
    FROM: kom_qabz.kom_qabz_history
    WHERE h.copy_time > = TO_DATE ('20120803', 'YYYYMMDD') - 1
    AND h.copy_time < TO_DATE ('20120803', 'YYYYMMDD')
    AND h.qabz_number = q.qabz_number
    AND h.seriya_id = q.seriya_id)
    GROUP BY q.user_name

    Is there any problem?

    Hello

    Has received the kom_qabz schema for the workspace of the application when you generate the report?

    See you soon,.

  • SQL procedure does not work with 'current cursor' Oracle 11 g

    Hi all
    I've written a procedure that should update all rows for a single column on a given table.
    Here is the code:

    CREATE OR REPLACE PROCEDURE "xxx". "" loop_update_autowert_x ".
    (
    number of startwert
    column_name VARCHAR2,
    table_name varchar2
    )
    AS

    stmt varchar2 (2000);
    stmt2 varchar2 (2000);
    number of zaehler;
    number of sum_gesamt;
    TYPE obj_ref_type IS REF CURSOR;
    obj_cur obj_ref_type;
    Start
    stmt2: = ' select rownum, rowid of | table_name | "for update";
    Obj_cur OPEN FOR stmt2;
    dbms_output. Enable (1000000);
    dbms_output.put_line (' ist Startwert: ' | startwert);
    dbms_output.put_line (' ist column name: ' | column_name);
    dbms_output.put_line (' ist Table name: ' | table_name);
    loop
    extract the obj_cur in zaehler, my_rowid;
    exit WHEN obj_cur % NOTFOUND;
    sum_gesamt: = zaehler + startwert;
    stmt: = "update". table_name | 'set ' | column_name | ' = ' || sum_gesamt | "WHERE the current of obj_cur";
    dbms_output.put_line (stmt);
    immediately execute stmt;
    end loop;
    close obj_cur;
    end;

    the error I get is:
    Anmeldung bei der data base Oracle Test2.
    ORA-03001: Funktion nicht solution
    ORA-06512: in "xxx.loop_update_autowert_x", line 29
    ORA-06512: In line 10
    Startwert ist: 5
    Column name ist: one
    Table Name is: T
    Update T set a = 6 WHERE the currents of obj_cur
    Process finished.
    Abmeldung von der data base Oracle Test2.

    have anyone an idea what is wrong or this construction with the clause "cursor open for the statement" is not possible with the current cursor location

    thx for help
    Best regards
    Hans-Peter

    When informed of the cursor works with static cursors and static sql only.

    ----------
    Sybrand Bakker
    Senior Oracle DBA

  • That means 1e9 and why this query does not work?

    What does 1e9? Someone has links to documentation on this oracle? And why I get this error?
    SQL> select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER';
    select segment_name,(bytes/1e9) AS size from dba_segments where segment_name='MSG_MASTER'
                                       *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected

    SIZE is a keyword - so if you want the name of the column size then use 'SIZE' else give it a different name

    Try dividing by other exponentials, then you'll see how: 1e0 1e1 (div 1), (div by 10), 1e2 :-) etc

    Mette

    Published by: mettemusens on 2009-05-12 16:02

  • Logging SQL 2012 does not work

    I installed Log Insight Manager 2.5 GA (Version 2.5.0 - 2347850) and install the agent on a Server Standard SQL 2012 and also installed the SQL management pack but nothing appears in the Insight journal.

    Here's my entry in liagent.ini for SQL file I got out of an on-line tutorial.

    [filelog |] SQL2012]

    Directory is Microsoft SQL Server\MYSQL11. MSSQLSERVER\MSSQL\Log\

    include = ErrorLog.log

    exclude = * .trc

    Charset = UTF-16

    {event_marker = ^ \d{4}-\d {2} - \d {2} \d{2}:\d{2}:\d{2}\.\d{2}

    And here are some entries from the journal of the animal.

    2015-02-17 09:07:55.202336 0 x 00000968 < warng > FLogCollector:692 | There are currently no log file that goes through the filter of file name "enter" / "exclude" for channel < SQL2012 >.

    2015-02-17 09:07:55.202336 0 x 00000968 < path > FLogCollector:246 | Subscriber to channel < SQL2012 >.

    Is this a configuration problem? I've set up on another SQL server server and see if that does the same thing.

    If it's a permissions issue then you could increase the debug_level 1 by adding

    [record]

    debug_level = 1

    and then look at the log of the agent. You can also try to change the include

    include = ERRORLOG *.

    or remove the option include all together and that the agent collect all files in this directory.

Maybe you are looking for

  • Drive DVD M30X 165 are not working properly

    HelloI bought this phone 2 weeks ago, but now the drive hurts... sometimes it do not read the CD, after some testing, it works but its's not me on my nervs... Now, I wanted to burn a cd, but this does not also, ahead nero and burning of windwos xp pr

  • Need help with the error code Udates Windows 0 x 80070424

    Hi, can someone give me some advice on how to enable Windows Auto Udates back, they seemed to have close the cottages and after trying to use all the options available I knew I am now facing an error code when I try to use the Microsoft Web site myse

  • BlackBerry classic catastrophic autonomy

    I'm just on the edge of Blackberry abandonment after being a loyal Blackberry user for more than a decade. Until yesterday, I had a Q10 that I was very satisfied since the first day I've owned. Then the new update came last month and I've updated the

  • Synchronize music from mp3 player to Windws Media Center music

    Original title: SYNC MUSIC Is it possible to sync music from an mp3 player in my library of music to windows media?

  • FDMEE: Data load rule problem

    Hello everyone,I have a question to FDMEE loading the data from a flat file to the validation step because a wrong to the mapping of the data rule it look likeIt is not an entity or an accountWhat is the fault in the charge of mapping data?