How to work even and odd number query

Plz explain how below worked even and odd query
2 ) why used subquery after from and which time we can use(what time of out put)
even
select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
 WHERE d.row %2=0   
odd
select * FROM (SELECT ROW_NUMBER() OVER(ORDER BY stud_id) as row ,grno,stud_id from stud_Enrollment) d
 WHERE d.row %2=1

Row_Number function returns the sequential number of a row
(By using partition of a result set, starting at 1 for the first row in each partition)
>> why used subquery after from and which time we can use(what time of out put)
When we need sequntial numbers, we can use row_number function. Put it into derived table and use this derived table after FROM clause (Same way it is used in your query)
CREATE TABLE stud_Enrollment (
grno int,
stud_id int,
stud_name varchar(20)
INSERT INTO stud_Enrollment
VALUES (101, 511, 'Dheeraj'), (112, 521, 'Vaibhav'), (132, 522, 'Lalit'), (124, 564, 'Amogh'), (143, 598, 'Sushrut')
SELECT * FROM stud_Enrollment
-- Result of your table
--grno stud_id stud_name
--101 511 Dheeraj
--112 521 Vaibhav
--132 522 Lalit
--124 564 Amogh
--143 598 Sushrut
-- Now we need to find out the rows which are at even position, ie row should be at position of 0,2,4,6,8 etc..
-- But we don't have sequential number here in your table result
-- So we can create one new column by using row_number function
SELECT
ROW_NUMBER() OVER (ORDER BY stud_id) AS row, --> additiona "row" column
grno,
stud_id,
stud_name
FROM stud_Enrollment
-- We got "row" column in below output
--row grno stud_id stud_name
--1 101 511 Dheeraj
--2 112 521 Vaibhav
--3 132 522 Lalit
--4 124 564 Amogh
--5 143 598 Sushrut
-- Now above table is used after FROM clause. It uses row column in WHERE part
SELECT
FROM (SELECT
ROW_NUMBER() OVER (ORDER BY stud_id) AS row,
grno,
stud_id,
stud_name
FROM stud_Enrollment) d
WHERE d.row % 2 = 0
--row grno stud_id stud_name
--2 112 521 Vaibhav
--4 124 564 Amogh
-Vaibhav Chaudhari

Similar Messages

  • How to display even and odd number ranges between two given inputs.

    Hi Every one,
    I am just started my career in sap abap and trying to find the solution for this.
    I am trying to display number range using select options, but I am getting an error "Memory low leave the transaction before taking a break".
    Example: when I give two number 2 and 10 , it should display set of all even and odd numbers in that range.
    Below is the code logic that I am using:
    data: a type i,
             b type i,
             c type i,
             d type i,
             num type i.
    select-options: in for num.
    a = inp-low.
    b=inp-high.
    c = inp-low mod 2.
    d = inp-high mod 2.
    while a <=b and c = 0.
    write: "even numbers:', a.
    b = a + 1.
    endwhile.
    while a <=b and c <> 0.
    write: "odd numbers:', b.
    b = a + 1.
    endwhile.
    Any help will be much appreciated.

    This is your logic...changed:
    data: a type i,
              b type i,
              c type i,
              d type i,
              num type i.
    data: even type i,
           odd  type i.
    select-options: in for num.
    a = in-low.
    b = in-high.
    c = a mod 2.
    if c is INITIAL. "It measn a is even
       even = a.
       odd  = a + 1.
    else.
       odd  = a.
       even = a + 1.
    endif.
    * Even
    a = even.
    while a <= b.
       write: / 'even numbers:', a.
    *  b = a + 1.
       a = a + 2. "The next even number
    endwhile.
    * Odd
    a = odd.
    while a <= b .
       write: / 'odd numbers:', a.
       a = a + 2. "The next odd number
    endwhile.

  • Counting even and odd values

    Is there another way to count even and odd number than this one
    private static int countEvenOrOdd(int[] array, boolean countEvenNumbers){
              int count = 0;
              int remainderRequired = (countEvenNumbers ? 0 : 1);
              for(int i = 0; i < array.length; ++i){
                   if(array[i] % 2 == remainderRequired){
                        ++count;
              return count;
         }

    > I like hacking ;-) Have a look at this: ...
    Jos, you forgot the method for counting both:int countOddsAndEvens(int[] array) {
    return (countOdds(array) + countEvens(array));
    } ; )Yep, you're right, and for completeness reason I'd like to add the following:int countOthers(int[] array) {
       return array.length-countOddsAndEvens(array);
    }And for those junit maniacs:boolean testCounters(int[] array) {
       return countOddsAndEvens(array)+countOthers(array) == array.length;
    }btw, the moment I posted my previous reply I realized that I could've done better:int countOdds(int[] array) {
       int c= 0;
       for (int i= 0; i < array.length; c+= array[i++]&1);
       return c;
    }kind regards,
    Jos ( <-- never has to maintain others' code ;-)

  • Add Even and Odd Numbers

    I have a programming assignment that needs to read a set of integers and then finds and prints the sum of the evens and sum of the odds.
    I know how to find out which numbers are odd and even, I just can't figure out how to add up the evens and odds. Say a set of 10 integers is inputted, how can they be added up after it is determined if they are even or odd?

    Here is my code after the tip from student... It compiles but once ran it doesn't do anything after the integers are put in.
    import java.util.*;
    public class EvenOddIntegers {
        static Scanner console = new Scanner(System.in);
        static final int limit = 10;
        public static void main(String[] args) {
             int number = 0, limit = 0, sumEven = 0, sumOdd = 0;
             int odds = 0;
            int evens = 0;
             System.out.print("Enter ten positive integers: ");
             while (limit <= 10)
                  number = console.nextInt();
             if (number % 2 == 0)
                  sumEven += number;
             else if (number % 2 != 0)
                  sumOdd += number;
             System.out.println("Sum of even numbers is " + sumEven + ".");
             System.out.println("Sum of odd numbers is " + sumOdd + ".");
    }

  • Zero bleed at inside page on even and odd master pages

    Hello guys!  Going directly to my question would be how to apply bleed option specifically on inside pages when working with individual master pages for master and facing pages on the main document. The thing is when I've set no bleed on inside on my Document Setup it has applied on my even and odd master pages (remembering I have individual master pages set on my document). I am not sure if I was clear enough but I keep it open for eventual comments and so on.  Thank you.

    Ok Peter. Thank you! I am posting some screen shots to help understanding.

  • Split and add Even and odd numbers

    Hi All,
    I got a seven digit number any number say for example (6581231). Now i need to add even number and odd number separately.
    Output should be
    6 + 8 + 2 = 16
    5 + 1 + 3 + 1 = 10
    Thanks
    S

    Assuming the number is always 7 digits one way to do this would be:
    Data: string(7) type c,
             num type i.
             Nmod type i.
    **move the number to a string.
    Move num to string.
    split into 7 individual chars.
    Num1 = string+1
    Num2 = string+2.
    Num3 = string+3
    Etc…
    divide each by 2 and find remainder
    Nmod = num  mod 2.
    if remainder is 0, number is even
    If nmod = 0.
    Number is even.
    Else.
    Number is odd.
    Endif.

  • Detecting even and odd numbers

    Hi, I'm drawing a series of rectangles using AS3, and need
    every alternate one to be lighter... I'm using a switch statement
    currently, with a variable counting the number of rectangles and
    case 1, case 2, case 3, etc.
    Is there a formula or some way of telling whether there is an
    even or odd number of rectangles so my switch statement can just be
    case even:, case odd: ? The way I have it is fine for 10 or so
    rectangles but I'd rather make it more expandable.
    Would appreciate any suggestions

    % is a modulo operator that finds a remainder of a division.
    9%2 = 1, 9%4 = 1, but 9%3 = 0.
    In the case of odd/even numbers one can look at it as that an
    even number that leaves no remainder when divided by 2 and odd
    number is a number that leaves remaining 1 when divided by
    2.

  • Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    I have friends all over Europe, does it matter what number they use to call me? Nope! All incoming calls are free for me.
    The only time you ever have to worry about which number is if you get charged for incoming domestic/international calls.
    You can tag their number (work/home/iphone) and that may show on the CallerID accordingly.
    It should show, John Doe
    underneath,    work/home/mobile
    For example:
    http://shawnblanc.net/images/img-0009-1.png

  • How to find the largest odd number and smallest even number from an array

    Hello All
    I want to find out largest odd number and the smallest even number from an arry numbers? What is the best method to achieve this.
    Thanks
    Sravz

    You need to sit down and figure out an algo on how you would do it if you had to do the same thing from a blind container perspective:
    1 - collect all the items you want to look at
    2 - look at an item
    3 - is it odd?
    4 - if it is odd then check if it is larger than previously largest number
    5 - save it if it is larger
    6 - return back to 2 unless no more items
    7 - item is not odd so it must be even--is it smaller than previous
    8 - save it if it is smaller
    9 - return back to 2 unless no more items
    Now you just need to know how to check if something is even or odd: to do this you will need the modulous operator--integer division.
    Note: this all assumes that your needs are for integer type of numbers, otherwise there is not enough information to define an answer. For instance, if you are using floats at 0.5--it that even or odd? Do you consider an err factor when dealing with floats? etc...

  • Change colour of a circle whether mousePressed is an even or odd number

    Right this is sort've difficult to explain. I have implemented a grid of circles for a Connect 4 game with the help of you fine people :) Now to add to this, I am looking to change the colour of a circle depending on whether it's an even or odd mousePressed. Basically this is like playing somebody else, so each player takes it in turns. If there is an easier way to do this then I would greatly appreciate it.
    public class CircleGrid extends JPanel implements MouseListener
            boolean ifRed;
            public CircleGrid()
              ifRed = true;
              addMouseListener(this);
            public void toggleColor()
              ifRed = !ifRed;
              repaint();
            public void paintComponent(Graphics g)
              if (ifRed)
                g.setColor(Color.RED);
              else
                g.setColor(Color.BLUE);
              g.fillOval(0, 0, 50, 50);
            public void mousePressed(MouseEvent evt)
               toggleColor();
            public void mouseClicked(MouseEvent evt)
            public void mouseReleased(MouseEvent evt)
            public void mouseEntered(MouseEvent evt)
            public void mouseExited(MouseEvent evt)
         }That is the code which draws the ovals and such on to my gameCenter JPanel.
    I was thinking something like:
    pesudo code --
    if mousePressed is an even number
    then set g.setColor = blue
    else
    g.setColor = red
    Thank you guys. I would appreciate any help. I'm still very much a newbie and some of my questions, I'm sure, are trivial to most of you but we all have to start somewhere.

    Hey LW, cheers buddy. :)
    I used your idea.
    Here's my working code:
    if (clicks == 0)
                        ifRed = true;
                        repaint();
                        clicks = 1;
                   else if (clicks > 0)
                        ifRed = false;
                        repaint();
                        clicks = 0;
                   }

  • CSS Even and Odd VLANS

    On the Catalyst 5000 architecture, all Even VLANs are running on one BUS on the backplane and all the odd VLANs are running on the other BUS on the backplane. Is CSS work in the same way? Hence, is it going to be a problem if I have all Even VLANs or all Odd VLANs?
    Thanks,
    /david

    David,
    The CSS does not work in this manner so your vlans can be odd or even and have not effect on the css. The only thing to keep in mind is that ever 4 ports, 1-4, 5-8, 9-12, etc.. are on separate EPIFs. So when doing network planning, you may want to consider separating connections.
    For example, if you are only using a few ports on a CS150, it would be beneficial to use ports 1,5 and 9 as they are all on different EPIFs.
    Regards
    Pete Knoops
    Cisco Systems

  • Even and odd counts..

    Whats the easiest way to determine if a button has been pushed and even or an odd number of times?
    Here is why I'm asking...
    If it has been pushed an even number of times than i want it to display one method, if odd I want
    it to display another method....

    Add a MouseListener to your Button and call the getClickCount() method on the MouseEvent, if the following condition is true then its an even number of clicks :
    if (Math.IEEEremainder((double)clickCount, 2.0) == 0.0)Ronny.

  • How to append calling and called number with translation rules?

    Hello,
    I have one question about digit manipulations.
    How to append calling number and called number with IOS commands?
    For example, when 123 dials 45678, translations have to be performed and the new called number to be 12345678.
    Thank you,
    I will vote this conversation.

    It is not possible with translation rules.
    However, you can do that with a TCL/IVR script.

  • Link with Work Centre and Order Number?

    Can anybody give me a link between the Work center(CRHD-ARBPL) and Order Number(AUFK-AUFNR)?
    Regards,
    Subhasish

    aufk-aufnr = afko-aufnr.
    afko-aufpl = afvc-aufpl.
    afvc-arbid = crhd-objid.
    now take arbpl from crhd.
    regards
    shiba dutta

  • How to work with sap bw bex query structure

    Dear Friends,
    How can we use SAP BW bex query structure in crystal reports.
    Thanks with regards.
    Malik

    i have two structure in my query.
    and structure is comming in my Crystal report.
    i have 10 memebers in that structure and i make display off for some of members .
    but in crystal all of members are comming either its property is hidden or not.
    any help higly appricated.
    Regards
    Malik

Maybe you are looking for

  • How to include income codes on 1042S reporting

    I am configuring 1042 S processing. The different rates of withholding for treaty countries are being properly deducted. My real question is: Do I need to have different withholding tax codes? I am using 42 with a tax wh type of 03. However, the paym

  • Please advise a novice..

    Hi, Am considering buying the Zen Touch 20gb after much research. Whilst I am aware that this apparantly holds "up to 0,000" songs, it seems this differs with mp3 or wma format. I will be using mp3, so was wondering if anyone could give a rough estim

  • Alternative way of runnung oracle report

    Hi world, There is another way of executing Oracle report from Oracle forms. Usually people use RUN_PRODUCT to execute it. Anyway, the second method is via RUN_REPORT_OBJECT. I've try this method but it seems that, it cannot find the report that i wa

  • Can Lower Thirds made for AE be used in PR?

    I have software to create a lower third for After Effect, but I don't have After Effect. Can I still create a lower third for in my software for After Effect and still use that same Lower Third in Premiere Pro?

  • Run a Form without Browser

    Hi, can i run a form without a webbrowser? (what i want is, to run the form as an windows application) maybe i can convert my forms-application into a java-class and run it with javaw.exe?