Extract Numbers and count their times

Oracle 10.2.0.1
Windows xp
Table1 is having below data :
Region  Region_Name   Sales_Allowed (This is also codes of region)
01      R1            26,19,30,04,10,20
02      R2            15,18,01,34,30,10,26,50
03      R3            45,80,12,02,01,48,77
04      R4            11,22,50,26,19,06,45
05      R5
80      R80           12,13,14,15,77Total 80 regions and maximum sales_allowed is 20 regions; i mean there can not be more than 20 regions in a region where sales is allowed.
My requirements :
1.Which region is having highest Sales_allowed. In the above example 02 is having maximum
regions in it.
2.If i wish to know that how many times RegionN is coming in the table as sales_allowed, something like in the above example 26 is coming 3 times (in 01,02 and in 04), may be other region is coming 10 times in different rows; so i want something like :
Output based on above example please:
Region    Times
01        0
02        1
03        0
04        1
05        0
06        1
26        3
..        <N>I am sure, this question is in the forum, but not finding the exact/near solution....
Thank you.

Or is it more like this?
SQL> ed
Wrote file afiedt.buf
  1  with t as (select '01' as Region, 'R1' as Region_Name, '26,19,30,04,10,20' as Sales_Allowed from dual union all
  2             select '02', 'R2', '15,18,01,34,30,10,26,50' from dual union all
  3             select '03', 'R3', '45,80,12,02,01,48,77' from dual union all
  4             select '04', 'R4', '11,22,50,26,19,06,45' from dual union all
  5             select '80', 'R80', '12,13,14,15,77' from dual)
  6  --
  7  -- END OF TEST DATA
  8  --
  9  select x.rn as region, nvl(y.cnt,0) as cnt
10  from   (select rownum rn from dual connect by rownum <= 80) x
11         left outer join
12         (select regexp_substr(sales_allowed,'[^,]+',1,rn) as region, count(*) as cnt
13          from   t cross join (select rownum rn from dual connect by rownum <= 20)
14          where regexp_substr(sales_allowed,'[^,]+',1,rn) is not null
15          group by regexp_substr(sales_allowed,'[^,]+',1,rn)
16         ) y
17         on (x.rn = to_number(y.region))
18* order by 1
SQL> /
    REGION        CNT
         1          2
         2          1
         3          0
         4          1
         5          0
         6          1
         7          0
         8          0
         9          0
        10          2
        11          1
        12          2
        13          1
        14          1
        15          2
        16          0
        17          0
        18          1
        19          2
        20          1
        21          0
        22          1
        23          0
        24          0
        25          0
        26          3
        27          0
        28          0
        29          0
        30          2
        31          0
        32          0
        33          0
        34          1
        35          0
        36          0
        37          0
        38          0
        39          0
        40          0
        41          0
        42          0
        43          0
        44          0
        45          2
        46          0
        47          0
        48          1
        49          0
        50          2
        51          0
        52          0
        53          0
        54          0
        55          0
        56          0
        57          0
        58          0
        59          0
        60          0
        61          0
        62          0
        63          0
        64          0
        65          0
        66          0
        67          0
        68          0
        69          0
        70          0
        71          0
        72          0
        73          0
        74          0
        75          0
        76          0
        77          2
        78          0
        79          0
        80          1
80 rows selected.
SQL>

Similar Messages

  • Why do my contacts suddenly show up as phone numbers when sending or receiving texts? So weird- I now suddenly just see their numbers and not their names. Unless I have memorized the number, I don't know who the message is from. Thanks!

    Or receiving texts? It just suddenly started, so all I see when I send or receive a text is the phone number. I don't know who the person is unless I've memorized their number. Thanks.

    try this...general-settings-"mail,contacts,calendars"-contacts-
    sort order-first,last
    display order-first,last
    (didnt notice op date)

  • Accepting n numbers and Print their sum and average in Pl/SQL

    Hi All,
    I want to accept n number of values and i want to do some calculations on it.For this purpose I have tried "&" and "&&" operators. Is there any proper method for doing the same
    Thanks in advance
    Kiran

    hi
    I don't think that u can read from command line in frm a pl/sql block
    U may try using Java stored procedure/or other embeded language for that matter(example ..proc)
    ..................pushpi

  • Add EMO button and counter

    Hi guys,
    Doing a college project and am stuck with this. Honestly haven’t a clue about Labview but been trying my best.
    I'm trying to add a counter that will increment every time my slider returns and I also want to add an EMO button to stop the slider instantly.
    I've cut the relevant section out of my VI and posted.
    Appreciate any help.
    Attachments:
    Server VI.5.vi ‏19 KB

    Hi guys,
    Thanks for the replies. I've tried looking over the tutorials, but i must be just a bit slow
    This is supposed to be the clamp part of a moulding machine.
    Hi Ravens,
    Thanks for the advice, EMO was Emergency Motor Off, to be honest I haven't a clue, this is just a college project but I'm only back in work so have missed last 2 months and this project is due in 2 weeks. Trying to play catch up is just making things more confussing.
    All I want to do with this part of the VI is the ability to stop the ram as soon as a button is pressed. And count each time the Ram returns home to indicate a Shot count for parts out.
    I know the wiring is awful but i'm so lost I just need to get something that I can submit.
    Cheers.

  • In the NI Library VI: Extract Numbers, the string control is automatically loaded each time the VI is opened with "Counting to five: one 2 three 4.0 five. Where is this string data coming from?

    Even after deleting the string "Counting to five: one 2 three 4. five." from the string control and replacing it with another string the original string returns after the VI is saved then reopened. Where is this string data coming from? I've attached a copy of the library function. I've been able in my application to get around the problem by replacing the string control with a string constant. But I'm still curious as to what's going on.
    Thanks,
    Chuck
    Solved!
    Go to Solution.
    Attachments:
    Extract Numbers Test.vi ‏9 KB

    Chuck,
    String control has been set to default with the string you are seeing.  To change this, enter the new string, right click the control and select
    Data Operations>>Make Current Value Default
    Now save your vi.

  • VB 2012 - Help Finding Specific Numbers in a Database Column and Count the Number of Times They Appear.

    Hello,
    I am doing a project that uses MS Access to access data about a baseball team . The MS Access Database provides the names, addresses, and age of the players. All the players are 12, 13, or 14 years old. I need to display the average age for the team on a
    label, which was easy. The problem is that I also have to display the number of players who are 12, 13, and 14 years old and I have no idea how to do that.
    Here is my code so far:
    Public Class frmBaseball
    Private Sub TeamBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TeamBindingNavigatorSaveItem.Click
    Me.Validate()
    Me.TeamBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.LittleLeagueDataSet)
    End Sub
    Private Sub frmBaseball_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'LittleLeagueDataSet.Team' table. You can move, or remove it, as needed.
    Me.TeamTableAdapter.Fill(Me.LittleLeagueDataSet.Team)
    End Sub
    Private Sub btnAges_Click(sender As Object, e As EventArgs) Handles btnAges.Click
    Dim strSql As String = "SELECT * FROM Team"
    Dim strPath As String = "Provider=Microsoft.ACE.OLEDB.12.0 ;" & "Data Source=e:\LittleLeague.accdb"
    Dim odaTeam As New OleDb.OleDbDataAdapter(strSql, strPath)
    Dim datAge As New DataTable
    Dim intCount As Integer = 0
    Dim intTotalAge As Integer
    Dim decAverageAge As Decimal
    odaTeam.Fill(datAge)
    odaTeam.Dispose()
    For intCount = 0 To datAge.Rows.Count - 1
    intTotalAge += Convert.ToInt32(datAge.Rows(intCount)("Age"))
    decAverageAge = Convert.ToDecimal(intTotalAge / datAge.Rows.Count)
    Next
    lblAverage.Visible = True
    lblAverage.Text = "The average age of the team is " & decAverageAge.ToString("N2")
    lbl12.Text = "The number of 12 year olds is "
    lbl13.Text = "The number of 13 year olds is "
    lbl14.Text = "The number of 14 year olds is "
    lbl12.Visible = True
    lbl13.Visible = True
    lbl14.Visible = True
    End Sub
    End Class
    I think I should use a For..Next loop but I don't know how to identify and match using this database, and then count how many repeated 12, 13, 14 years old there are.
    Any help would be really appreciated.

    Hello,
    Conceptually speaking you would group the data and count. Beings this is school work the demo below is a static example and not suitable for your assignment, its to show a point. Now if you have learned about LINQ and Lambda this logic can apply to your
    question but need to work out using this your data which can be done. If not look at using SQL Grouping.
    Example of SQL grouping and count
    select country, count(country) as count from customers group by country
    Module Module1
    Public Sub GroupingDemo()
    Dim dt As DataTable = SimulateLoadFromDatabase()
    Dim TeamData = dt.AsEnumerable.GroupBy(
    Function(student) student.Field(Of Integer)("Age")) _
    .Select(Function(group) New With
    Key .Value = group.Key,
    Key .Info = group.OrderByDescending(
    Function(x) x.Field(Of String)("Name"))}) _
    .OrderBy(
    Function(group) group.Info.First.Field(Of Integer)("age"))
    Dim dictData As New Dictionary(Of String, String)
    For Each group In TeamData
    Console.WriteLine("Group: {0} count: {1} ", group.Value, group.Info.Count)
    dictData.Add(group.Value.ToString, group.Info.Count.ToString)
    ' The following is not needed but good to show
    For Each item In group.Info
    Console.WriteLine(" {0} {1}",
    item.Field(Of Integer)("Identifier"),
    item.Field(Of String)("Name"))
    Next
    Next group
    Console.WriteLine()
    Console.WriteLine("This data can be used to populate control text")
    For Each Item As KeyValuePair(Of String, String) In dictData
    Console.WriteLine("{0} {1}", Item.Key, Item.Value)
    Next
    End Sub
    Private Function SimulateLoadFromDatabase() As DataTable
    Dim dt As New DataTable With {.TableName = "MyTable"}
    dt.Columns.Add(New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32),
    .AutoIncrement = True, .AutoIncrementSeed = 1})
    dt.Columns.Add(New DataColumn With {.ColumnName = "Name", .DataType = GetType(String)})
    dt.Columns.Add(New DataColumn With {.ColumnName = "Age", .DataType = GetType(Int32)})
    dt.Rows.Add(New Object() {Nothing, "Bill", 13})
    dt.Rows.Add(New Object() {Nothing, "Karen", 14})
    dt.Rows.Add(New Object() {Nothing, "Jim", 13})
    dt.Rows.Add(New Object() {Nothing, "Paul", 15})
    dt.Rows.Add(New Object() {Nothing, "Mike", 14})
    dt.Rows.Add(New Object() {Nothing, "Jill", 13})
    Return dt
    End Function
    End Module
    Output in the IDE output window
    Group: 13 count: 3
    3 Jim
    6 Jill
    1 Bill
    Group: 14 count: 2
    5 Mike
    2 Karen
    Group: 15 count: 1
    4 Paul
    This data can be used to populate control text
    13 3
    14 2
    15 1
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Counting peaks within one minute intervals and outputting with time stamp

    I'm currently working on my senior design project for biomedical engineering. We are creating a piezoelectric sensor in order to measure respiration on a bed non-invasively. The sensor lays on bed under subject and records movement due to respiration. We currently have figured out how to detect peaks. However, now we want to count number of peaks detected within a 1 min time period and output that result with a 'timestamp'. We would like the output to be into excel as two columns, rate(number peaks in 1 min) and time. Time in minutes and not actual time is fine. Sampling rate was 500Hz.
    My current VI has peak detection criteria and can output total number of peaks and their locations.
    Any help would be greatly appreciated as this is our last step before verification and have been stuck on it for awhile. 
    It won't allow me to attach a tdms file in which our data is stored as, so I can't upload the data currently.
    Also attached is our current VI for peak detection labeled 3.26.Resp.PeakDetect.
    Thanks for any and all help!!
    Attachments:
    3.26.Resp.PeakDetect.vi ‏146 KB

    I see no need for a case structure.  Or did you set up a state machine that I missed?
    I recommend making a VI that does nothing but read your 30,000 samples and process it (counting the peaks and what not).  From there, you create the array for the number of peaks and the time (in minutes).  Then you can call that VI inside of a loop to build up the array of data points.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    You may have switched on [http://kb.mozillazine.org/accessibility.browsewithcaret caret browsing].
    You can press press F7 (on Mac: fn + F7) to toggle caret browsing on/off.
    See http://kb.mozillazine.org/Scrolling_with_arrow_keys_no_longer_works
    * Tools > Options > Advanced : General: Accessibility: [ ] "Always use the cursor keys to navigate within pages"

  • I have a new iPad with wifi. When I send messages I can see my sons and my husbands but not my phone number.  We all have an iPad and all use the same apple ID as iPad the bill.  How can I remove their numbers and add mine?

    I have a new iPad with wifi. When I send messages I can see my sons and my husbands but not my phone number.  We all have an iPad and all use the same apple ID as iPad the bill.  How can I remove their numbers and add mine?

    Add another e-mail account to your messages, so people could reach you on that e-mail from messages. As soon as you are online (if you have wifi only iPad) you are able to send and receive messages. i.e. your son can send you a messages from his iPhone addressing it to your (that additional) e-mail address.

  • If I have 2 tv's and each their own apple tv can I display the same program to them from my macbook at the same time?

    If I have 2 tv's and each their own apple tv can I display the same program to them from my macbook at the same time?
    for instance Keynote?

    Welcome to the Apple community.
    The Apple TV cannot display keynote presentations or websites from the computer. It can display them via mirroring from the iPad 2 or better or the iPhone 4S.
    You cannot AirPlay to 2 Apple TV 2's at the same time from an iOS device. You can watch the same video, TV show or listen to the same music from your iTunes library on multiple Apple TV's at the same time.

  • How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    How can I add a new Template to My Templates in Pages? I've read most of the discussions on the subject but it doesn't work for me. By the time I reach the Templates folder, I only see templates for Numbers and not for Pages. Need help, please.  Thanks

    Si vous avez utilisé la commande Save As Template depuis Pages, il y a forcément un dossier
    iWork > Pages
    contenant Templates > My Templates
    comme il y a un dossier
    iWork > Numbers
    contenant Templates > My Templates
    Depuis le Finder, tapez cmd + f
    puis configurez la recherche comme sur cette recopie d'écran.
    puis lancez la recherche.
    Ainsi, vous allez trouver vos modèles personnalisés dans leur dossier.
    Chez moi, il y en a une kyrielle en dehors des dossiers standards parce que je renomme wxcvb.template quasiment tous mes documents Pages et wxcvb.nmbtemplate à peu près tous mes documents Numbers.
    Ainsi, quand je travaille sur un document, je ne suis pas ralenti par Autosave.
    Désolé mais je ne répondrai plus avant demain.
    Pour moi il est temps de dormir.
    Yvan KOENIG (VALLAURIS, France)  mercredi 23 janvier 2011 22:39:28
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How do i keep only the name of a month in a cell in Numbers and not have it auto fill the date and time?

    how do i keep only the name of a month in a cell in Numbers and not have it auto fill the date and time?

    Hi JN and Barry,
    Barry wrote:
    The second case may not be included in the available D&T formats in Numbers 3
    For my region, the Date & Time data formats include month.
    The Date Pop-Up
    This may not be the case for all regions.
    Remember that the month is only the display, and the Full Date & Time is still there. If I change the format to reveal what is behind the curtain:
    Regards,
    Ian.

  • Time Capsule with BT Home Hub - 9 hours of trying to set up and counting...

    Hi...I am at my wits end having spent two long evenings trying simply to connect a Time Capsule to an iMac. We have pored over the instructions, read all the postings in all the forums, probably in the entire world (OK, slight exaggeration) and tried every possible combination, and still we end up with a non-responsive Time Capsule (blinking amber light), and the Airport software saying "Waiting for the Time Capsule to restart" in a perpetual loop. The issues may well be around compatibility with the BT Home HUb, but there again they may not. There are no clues about why it fails so consistently in every combination. For the record, these are the combinations we have so far tried: ethernet connection from WAN port on TC to Ethernet port on Home Hub...A wired connection is established successfully. But then immediately the wireless connection wizard starts up, we can't turn it off, and the wireless connection wizard fails. We have tried it in all three combinations of the Wireless wizard. The end result is always the above, the blinking amber light.
    We have tried adding the TC without any ethernet connection being involved in the first place. This was the most promising, we actually finally got a green light on the TC itself, but, crucially, NOT in the Airport software: that just hung in the same perpetual loop saying "waiting for Time capsule to restart", even though it CLEARLY HAD RESTARTED (because it gave us the green light). So, after about 9 hours and counting trying to get this "out of the box" solution simply to be recognised by a Mac computer, let alone connected to any other devices in the house (heaven forbid), we are now at our wit's end. Does anyone have any advice?

    hi cprelude, I have the same or nearly the setup as you a BT HH V1 and a 500gb timecapsule this is hardwired to bt hh and works well so fear not it can be resolved. first hold the reset button on the HH with the TC disconnected, then while the HH is restarting unplug the TC for a couple of mins then replug inyour TC with the reset switch at the rear pushed in and then let the TC restart and plug in the ethernet cable to thr HH then use Airport utility to connect to the TC. then if all goes well you can set up two wireless networks first being the HH and the second the TC 5ghz. if I was you I would do the first backup on TC via ethernet as the first wireless backup can take hours and hours depending on the amount GBs you already have on your hard drive
    good luck
    john

  • HT1222 Can someone explain why the Safari 5.1.7 update seven times and counting?

      The latest Safari 5.1.7 update seven times and counting?  Is this required or is there something else a foot?
    Tomez

    Doublechecking before proceeding. Do you mean that your Apple Software Update keeps offering you the Safari update? Or is something different going on?
    Which version of Safari are you currently running? For example, when I go "Help > About Safari", I see:

  • Word Count - ignore numbers and symbols

    Hi Guys,
    can anyone tell me how to ignore numbers and symbols by adjusting the script below, i.e., just counting letters in a whole document.
    myDoc = app.activeDocument
    h = 0
    for ( var j = 0; myDoc.stories.length > j; j++) {
    h = myDoc.stories[j].words.length + h
    alert("You have " + h + " words in this document" )
    Cheers,
    Samuel

    In CS3 and later you can use this:
    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = "[\\u\\l][-\\u\\l]+";
    found = app.documents[0].findGrep ();
    alert ("You have " + found.length + " words in this document.")
    A "word" is defined here as any string of upper- and lower-case letters and hyphens. Maybe that's too strict, but you can tweak the GREP to suit your needs.
    Peter

Maybe you are looking for