Duplicates order by count

hello,
Is it possible to see the records in order by the number of counts they appears in the database asc or desc?
ID | Country
1 | USA
2 | UK
3 | USA
4 | HKG
5 | USA
6 | UK
Result should return
ID | Country
1 | USA
3 | USA
5 | USA
2 | UK
6 | UK
4 | HKG
Thanks

with ta
  as
     select 1 col1, 'USA' col2 from dual union all
     select 2 col1, 'UK' col2 from dual union all
     select 3 col1, 'USA' col2 from dual union all
     select 4 col1, 'HKG' col2 from dual union all
     select 5 col1, 'USA' col2 from dual union all
     select 6 col1, 'UK' col2 from dual
SELECT * FROM ta
ORDER BY
COUNT(*) over (partition BY col2) DESCRavi Kumar

Similar Messages

  • Duplicate Orders.

    Hi,
    I have a report which displays no. of orders in staging(before comming in to SAP, between EDI and SAP) by Sold to and PO date. For Ex:
    soldto  podate    no-of-orders
    Walmart 20071001  10
    walmart 20071005  25
    If I put cursor on one of the above lines and by clicking the button 'Duplicate orders', it gives the details of the duplicate orders(6) by cust.ship to, po number and shipto.
    cust.ship-to po number   shipto
    15          105PO15  1055000015
    15          105PO15  1055000015
    15          105PO15  1055000015
    16          105PO16  1055000016
    16          105PO16  1055000016
    16          105PO16  1055000016
    Suppose if the first line has 6 duplicate orders and second line does not have any duplicate orders, then user wants me to display like the following.
    soldto  podate    no-of-orders Duplicate Orders
    Walmart 20071001  10            6
    no second line - because no duplicate orders for this.
    Please help me to solve this.
    Thanks,
    Veni.
    * Initial Output to the Screen
        SET PF-STATUS 'NORM'.
        LOOP AT itab_output.
    READ TABLE itab_kna1 WITH KEY kunnr = itab_output-sndprn BINARY SEARCH.
          itab_output-name1 = itab_kna1-name1.
          MODIFY itab_output.
          CLEAR itab_output.
        ENDLOOP.
        SORT itab_output BY name1 datum.
        LOOP AT itab_output.
          WRITE: /01 sy-vline,
                  02 itab_output-name1,
                  40 sy-vline,
                  41 itab_output-datum,
                  51 sy-vline,
                  52 itab_output-orders,
                  62 sy-vline.
          HIDE: itab_output-inpnr.
        ENDLOOP.
        ULINE: /(62).
      ELSE.
        SET PF-STATUS 'NORM'.
        WRITE: /05 '********* NO DATA FOUND **************'.
      ENDIF.
    * Duplicate order details
    FORM output2.
      SET PF-STATUS 'STAT'.
      SORT itab_output2 ASCENDING BY belnr inpnr.
      LOOP AT itab_output2 WHERE sndprn = itab_output-sndprn
                             AND datum = itab_output-datum.
        FORMAT INTENSIFIED OFF.
        FORMAT COLOR 2.
        CLEAR counter.
        LOOP AT itab_output2 WHERE belnr = itab_output2-belnr
                       AND inpnr = itab_output2-inpnr.
          counter = counter + 1.
        ENDLOOP.
        IF counter > 1.
          SELECT SINGLE * FROM edid4 WHERE docnum EQ itab_output2-docnum
                                  AND segnam EQ 'E1EDKT2'.
          IF sy-subrc EQ 0.
            FORMAT INTENSIFIED ON COLOR = 7.
          ENDIF.
          IF itab_output2-inpnr = 'UNKNOWN'.
            FORMAT INTENSIFIED ON COLOR = 6.
          ENDIF.
          WRITE: /01 sy-vline,
                  02 chk AS CHECKBOX,
                  03 sy-vline,
                  04 itab_output2-lifnr,
                  20 sy-vline,
                  21 itab_output2-belnr,
                  42 sy-vline,
                  43 itab_output2-vtext,
                  72 sy-vline,
                  73 itab_output2-inpnr,
                  83 sy-vline.
        ENDIF.
      ENDLOOP.
      ULINE :/(83).
    ENDFORM.                                                    " OUTPUT2
    * Get data
    FORM check_data.
      LOOP AT t_itab_edid4 WHERE segnam = 'E1EDK02'.
        MOVE t_itab_edid4-sdata TO itab_e1edk02.
        IF ( itab_e1edk02-qualf = '001' AND itab_e1edk02-belnr IN s_ponumb
                                     AND itab_e1edk02-datum IN s_podate ).
          ind = 'V'.
          itab_output2-sndprn = itab_output-sndprn = t_itab_edid4-sndprn.
          itab_output2-docnum = t_itab_edid4-docnum.
          itab_output2-belnr = itab_e1edk02-belnr.
          itab_output2-datum = itab_output-datum = itab_e1edk02-datum.
          EXIT.
        ELSE.
          CLEAR: itab_e1edk02.
          ind = 'I'.
        ENDIF.
      ENDLOOP.
      IF ind = 'V'.
        LOOP AT t_itab_edid4 WHERE segnam = 'E1EDKA1'.
          MOVE t_itab_edid4-sdata TO itab_e1edka1.
    IF ( itab_e1edka1-parvw = 'WE' )."and itab_e1edka1-lifnr in s_shipto ).
            READ TABLE itab_edpar WITH KEY kunnr = t_itab_edid4-sndprn
                                   expnr = itab_e1edka1-lifnr BINARY SEARCH.
            IF sy-subrc EQ 0.
              IF ( itab_edpar-inpnr IN s_shipto ).
                ind = 'V'.
                itab_output2-lifnr = itab_e1edka1-lifnr.
                itab_output2-inpnr = itab_edpar-inpnr.
                itab_output-orders = 1.
                COLLECT: itab_output, itab_output2.
                CLEAR: itab_output, itab_output2.
              ELSE.
                ind = 'I'.
              ENDIF.
              EXIT.
            ELSE.
              IF ( s_shipto EQ space ).
                itab_output2-lifnr = itab_e1edka1-lifnr.
                itab_output2-inpnr = 'UNKNOWN'.
                itab_output-orders = 1.
                COLLECT: itab_output, itab_output2.
                CLEAR: itab_output, itab_output2.
                ind = 'V'.
                EXIT.
              ENDIF.
              ind = 'I'.
            ENDIF.
            EXIT.
          ELSE.
            ind = 'I'.
          ENDIF.
        ENDLOOP.
      ENDIF.

    I'd collect this information in an extra internal table.
    Finally I 'd loop this table:
    loop at ztab where duplicate_order > 0.
    A.

  • If I Order By Count, no data displayed

    Hi!
    I'm using JDeveloper 11g Release 2 (11.1.2.3.0).
    I create a VO with SQL Query DataSource. The Query is the follwing one:
    SELECT COUNT (*),
             Brand.BRA_NAME,
             Model.MOD_NAME
    FROM Sale,
             Car,
             Brand,
             Model
    WHERE ( (Sale.SALE_CAR_ID = Car.CAR_ID) AND (Car.CAR_BRAND_ID = Brand.BRA_ID)) AND (Car.CAR_MOD_ID = Model.MOD_ID)
    GROUP BY Brand.BRA_NAME, Model.MOD_NAME;I want that when the data is displayed as a read-only table, it shows ordered By Count (Maximum count in first position and minimum count in last one).
    If in my query, I put ORDER BY ""COUNT(*)"" DESC, no data is displayed in the table.
    What am I doing wrong?
    Thanks in advance!

    Hi,
    Marcccc wrote:
    Hi!
    I'm using JDeveloper 11g Release 2 (11.1.2.3.0).
    I create a VO with SQL Query DataSource. What's a VO?
    What am I doing wrong?Whenever you have a problem, post a complete test script that people can run to re-create the problem and test their ideas.
    "ORDER BY COUNT (*)" works fine for me:
    SELECT       COUNT (*)
    ,       job
    FROM       scott.emp
    GROUP BY  job
    ORDER BY  COUNT (*)     DESC
    ;Output:
    ` COUNT(*) JOB
             4 CLERK
             4 SALESMAN
             3 MANAGER
             2 ANALYST
             1 PRESIDENTUsually, people give aliases (such as emp_cnt in the example below) to computed columns. Those aliases can be used in the ORDER BY clause, like this:
    SELECT       COUNT (*)     AS emp_cnt
    ,       job
    FROM       scott.emp
    GROUP BY  job
    ORDER BY  emp_cnt     DESC
    ;but that's not required.

  • Refund for duplicate orders

    It looks like I have a duplicate order placed on January 30th. The order numbers are AD015563224 and AD015562812.  What do I need to do to get credit for one of the orders? Joe Basore

    Hi Joe,
    I can take care of that for you. I've canceled one and processed a refund. You should see that refund in your account in 5-7 business days.
    Best,
    Sara

  • Duplicate orders in atg

    Hi
    In my project we are having 10 members we all are using same shared data base
    How atg will create different orders for each users (means we are not getting duplicate orders. how ATG will manage to create different orders for individuals )

    This behavior will be observed only if the servers in question are in a cluster, correct ? What about the Scenario where there are two or more physical servers [One of them is SLM] accessing shared db? Is IDSpace still assigned as the servers are bounced or the id-generator will keep generating the ids as an when the requests come in from any given servers. So lets say a request from Server 1 was assigned id 1456 and if another request was from Server 2 it gets assigned 1457.
    Thank you in advance.

  • Order by count?

    This works fine,
    SELECT vendor, COUNT(purchaseorderid) cnt
    FROM FAC_IMPORT_Purchase_Orders
    WHERE UPPER(vendor) NOT IN ('ALL', 'ASAP', 'VARIES', '0', '-')
    AND
    NOT EXISTS (
    SELECT 1
    FROM fac_vendors
    WHERE txtname = FAC_IMPORT_Purchase_Orders.vendor
    group by vendor
    giving me
    vendor1 22
    vendor2 3
    vendor4 85
    etc.
    I'd like to see the results in order by count (those vendors used the most).
    like this:
    vendor4 85
    vendor1 22
    vendor2 3
    I tried giving the count column an alias of cnt, and using order by and group by cnt but neither worked.
    help?
    thanks!

    Hi,
    GROUP BY  vendor
    ORDER BY  cnt     DESC;should work.
    Post the entire query (and error message, if any) if you have a problem.

  • USE of PREVIOUS command to eliminate duplicate records in counter formula

    i'm trying to create a counter formula to count the number of documents paid over 30 days.  to do this i have to subtract the InvDate from the PayDate.   and then create a counter based on this value.  if {days to pay} is greater than 30 then 1 else 0.
    then sum the {days to pay} field to each group.   groups are company, month, and supplier.
    becuase invoices can have multiple payments and payments can have multiple invoices. there is no way around having duplicate records for the field. 
    so my counter is distorted by by the duplicate records and my percentage of payments over 30 days formula will not be accurate do to these duplicates.
    I've tried Distinct Count based on this formula  if {days to pay} is greater than 30 then . and it works except that is counts 0.00 has a distinct records so my total is off 1 for summaries with a record that (days to pay} is less than or equal to 30.
    if i subract 1 from the formula then it will be inaccurate for summaries with no records over 30 days.
    so i'm come to this.
    if Previous() do not equal
    then
      if {day to days} greater than 30
      then 1
      else 0.00
    else 0.00
    but it doesn't work.  i've sorted the detail section by
    does anyone have any knowledge or success using the PREVIOUS command in a report?
    Edited by: Fred Ebbett on Feb 11, 2010 5:41 PM

    So, you have to include all data and not just use the selection criteria 'PayDate-InvDate>30'?
    You will need to create a running total on the RPDOC ID, one for each section you need to show a count for, evaluating for your >30 day formula. 
    I don't understand why you're telling the formula to return 0.00 in your if statement.
    In order to get percentages you'll need to use the distinct count (possibly running totals again but this time no formula). Then in each section you'd need a formula that divides the two running totals.
    I may not have my head around the concept since you stated "invoices can have multiple payments and payments can have multiple invoices".  So, invoice A can have payments 1, 2 and 3.  And Payment 4 can be associated with invoice B and C?  Ugh.  Still though, you're evaluating every row of data.  If you're focus is the invoices that took longer than 30 days to be paid...I'd group on the invoice number, put the "if 'PayDate-InvDate>30' then 1 else 0" formula in the detail, do a sum on it in the group footer and base my running total on the sum being >0 to do a distinct count of invoices.
    Hope this points you in the right direction.
    Eric

  • Suppress Duplicates and Summarize (Count)

    Hello,
    I am somewhat new to Crystal Reports. I am trying to do a couple things that I cannot figure it out. Please help.
    1. Trying to count a field {JobHours.JobNumber} without the duplicates. I have suppressed the duplicates on the field and the summary is still counting them. Group # 3 Name: JobType.Description
         I could not figure it out so I created also created this formula: {@JobNoDuplicate}
         numberVar X :=1 ;
         if ({JobRecord.Jobnumber}) = previous({JobRecord.Jobnumber}) then 0 else 1
         It works but it wont let me summarize the {@JobNoDuplicate}.
    2. My report is grouped by the "start date" then by the "contractor name" then again by the "job type". I need to count the number of jobs that were planned but its in another crystal report. I dont know how to get the information on this report without messing up all my data/fields.
    Please help and thank you.

    Hi Nicole,
    Create a formula with this code:
    DistinctCount({JobNumber})
    That should give you the count of Job numbers without the duplicates.
    If you're trying to find out count of Job Numbers for each group, then just change the code to:
    DistinctCount({JobNumber}, {group field})
    For the second question, please post that as a new discussion per SCN's rules.
    -Abhilash

  • MIE1 :: Sale order cycle count issue

    Dear All,
    II am using transaction MIE1 to create inventory documents for sales order stock. I am receiving many more items to count than expected.  I checked the cycle count indicator and materials coded to be counted only once a year and last counted in February and March in table MSKA, but still when i executer IME1 system is picking it for cycle count.
    We are on SAP 4.67. Our fiscal year ended at the end of September.
    Anyone know why these materials would show as due to count now?
    Thanks,
    Chaithru

    Hi Terry,
    To be honest there is not normally any standard manipulation of the bin sequence in Physical Inventory, but here are a few places to look here (Grab a coffee first)
    Logistics > Warehouse Management > Strategies > Define Sort Sequence for Putaway >
    Logistics > Warehouse Management > Strategies > Define Sort Sequence for Removal >
    These two items determine the sort order priorty of your bin numbers, eg. if your bin numbers are 10 digits long, you could sort the bins in order using key co-ordinates with differing priority. So the second character of your bin could be sorted prior to the first character. (The logic here will be based upon the individual warehouse layout/rules)
    Next have a look in
    Logistics > Warehouse Management > Activities > Transfers > Processing Performance > Profiles (Have a look at Sort profile)
    Logistics > Warehouse Management > Activities > Transfers > Processing Performance > Control for Performance Data Processing / Define TO Split
    In these two you can manipulate the sort order of the bin numbers in TO and other documents, can look complex but is simple when you have understood the logic
    Good luck
    Steve

  • PRT Value update from PP order in Counter

    Hi Friend,
    Can any one tell me how to update pp order value(Qty) to PRT Counter value.
    Thanks
    Sandy

    Hi,
    Create PRT as Equipment with PRT view activate in Equipment master. then create one measuring counter with PRT equipment no then assign it in Production routing then feed maint plan & counter no in equipment master PRT screen .
    Check value of counter will b updated when production order is confirmed but it is possible in discrete manufacturing PP process only.
    Regards,
    AVI DDS

  • Get Process Order Confirmation&Counter from material document/goods receipt

    Hi @ all,
    i´m looking for a way (the tables) to get the order confirmation and the counter from a goods receipt. I have the material document number und the position of the goods receipt.
    Kind regards,
    Axxter

    Hi,
    we don´t have the goods receipt material documents in AFRU. I don´t know the reason why.
    Message was edited by:
            Sebastian Becker

  • Actual template allocation duplicate order posting

    Hi,
    We recently upgraded from 4.6C to 6.0. We use template allocation to allocate overhead to our process orders at month-end. We are doing our first month-end since going live on 6.0. When we ran tcode CPTD (actual template allocation) it posted the debit quantity and value to the process order twice, and the credit value to the business process only once. Therefore, the CO document is out of balance. We then run tcode CON2 to revalue the postings at actual price. Because of this error, we have a remaining un-allocated balance in our business processes for this month. We also have incorrect costsallocated to our process orders. How do we correct program CPTD, and correct these postings?
    Thanks...

    Hi
    I am using environment 9 yes.
    My formula is very simple:
    On Object I have:
    SenderCostCenter = '130570' AND
    SenderActivityType = 'LABORA'
    And then I have simply put "1" in Plan Quantity and Actual Quantity.
    So what it does is it allocates the unit cost of the combination of cost center 130570 and act. type LABORA one time to each material/order no matter lot size.
    Should I perhaps have put "1" into the Plan Fix and Actual Fix instead?
    Thanks

  • Cancelling a duplicate Order

    While pacing an order of  $60, for 12 months, Skype Number, something unknown  issue happend and two orders are placed showing two orders each for $60 on my account as well as my card.
    I want to cancel one of the orders and want to keep only one.
    Can you please let me know how to cancel one order and ask for refund.
    Thanks.
    Solved!
    Go to Solution.

    I was abel to resolve the issue by contacting the support team via live chat, It was quick.
    Below are details to get to live chat, I found below details in one of the posts, Just in case if anyone else looking:
    Please contact customer service for assistance; here is a link to the instruction on how to contact Skype Customer Service via their secure portal: Contact Customer Service 
    As you know you wish to contact Customer Service, skip past Step 2 of the instruction and proceed to Step 3, Continue Support Request

  • How do I cancel a duplicate order on an electronic order?

    I ran into a bug in the Apple store which caused me to accidentally order the $107.91 iOS Developer Program twice. I don't have that much money in my bank account and I don't know how to contact anyone from Apple. Is there an email address or 24/7 phone number I can call? I've already tried 1-800-MY-APPLE and 1-800-692-2775, and 1-800-854-3680.

    "... order the $107.91 iOS Developer Program .."?
    By how much is the $107.91 developer program better than the $99 everyone advises?

  • HT1933 duplicate order of a ringtone

    i accidentally ordered a text tone twice about 5 seconds apart.  how do i and can i get reimbursed for the 2nd order of the same tone?

    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

Maybe you are looking for