Group and count

Hello Friends,
I have a query where I select organization, item_num, and transaction_date.
I need to group and count the result by transaction_date, so I will have 3 groups:
First - will count records where transaction_date falls between the 1st and 10th of the month.
Second - will count records where transaction_date falls between the 11th and 20th of the month.
Third - will count records where transaction_date falls between the 21st and 31st of the month.
The result of this count will be used in the Oracle Report.
Please, give me your advise on how I can achive this.
Thank you.

select organization,
       item_num,
       count(case
               when transaction_date between trunc(transaction_date, 'mm') and trunc(transaction_date, 'mm') + 9 then 1
             end) "1-10",
       count(case
               when transaction_date between trunc(transaction_date, 'mm') + 10 and trunc(transaction_date, 'mm') + 19 then 1
             end) "11-20",
       count(case
               when transaction_date between trunc(transaction_date, 'mm') + 20 and trunc(last_day(sysdate)) then 1
             end) "21-end"
  from mytable
group by organization, item_num
Ramin Hashimzade

Similar Messages

  • Group and count by range of amount

    Hi all,
    I have a list of 400,000 lines like this:
    But I need grouped by amount of 10 and count the number of clients grouped, something like this:
    I hope the pictures explain better my problem.
    Thanks for your support
    Carlos

    Hi Carlos,
    According to your description, this issue is more related to excel instead of excel development.
    The Excel IT Pro Discussions forum is the better place for excel questions, we will move it there for you.
    Regards
    Starain
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Grouping and Counting

    I have a table of member_id's and number codes and dates. Each member can have any number of any of the available codes allocated to him on different dates. I need to be able to be able to group by member_id and count the number of a specified code allocated to each member. I need to show zero counts. Does that make sense?
    Any help with this would be greatly appreciated
    Lindsay

    lindsay wrote:
    I have a table of member_id's and number codes and dates. Each member can have any number of any of the available codes allocated to him on different dates. I need to be able to be able to group by member_id and count the number of a specified code allocated to each member. I need to show zero counts. Does that make sense?Not really. When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    Where exactly does APEX come into this? It sounds more like a general SQL problem which might be better suited to the {forum:id=75} forum.
    Either here or there, Re: 2. How do I ask a question on the forums? would make the problem clearer than any amount of vague description. Post this code wrapped in <tt>\...\</tt> tags.

  • Select, grouping and counting...

    Hi again, I managed to bypass my trigger problem, so thanks a lot...!
    Now, I have a simple question...
    Using two tables, Joueur (NoJ (PK), NoE(PK, FK1), NomJ, Adresse, Tel, CoJ)
    and Equipe (NoE(PK,FK1), NomE, NoJC(Fk1 of NoJ))
    I'll explain the model...
    It's a Team table, and a Player Table.
    Naturally, the PK on Player (Joueur) is NoE (team number) and NoJ (Player number)
    On the Team table, the primary key is NoE (Team number
    and the foreign key is NoE AND NoJC which stands for the number of the CAPTAIN player ...
    So...
    I've got to make a table of 4 cloumns: Team number (NoE), Team name (NomE), Team captain name, number of player in team...
    So I need to combine those two tables... on the first table, I got all the info BUT the number of players, which lists all 1 due to the where NoJC = NoJ... but this function is required to get the Captain name...
    Select NoE, NomE, NomJ as Capitaine, count(*)
    from EQUIPE join JOUEUR using (NoE)
    where NoJ=NoJC
    group by NoE, NomE, NomJ;
    select noe, count(*)
    from EQUIPE join JOUEUR using (NoE)
    group by noe;Any clue?

    I suggest for you :
    Put then column noJC in joueur table nojc NUMBER CONSTRAINT fk_no_joueur_cap REFERENCES joueur(noj);
    Regards Salim.
    SQL> DROP TABLE joueur;
    Table supprimée.
    SQL> DROP TABLE equipe;
    Table supprimée.
    SQL> CREATE TABLE equipe (noe NUMBER CONSTRAINT pk_no_eq PRIMARY KEY, nome VARCHAR2(30));
    Table créée.
    SQL> CREATE TABLE joueur (noj NUMBER CONSTRAINT pk_no_joeur PRIMARY KEY,
      2                       noe NUMBER CONSTRAINT fk_no_equipe REFERENCES equipe(noe),
      3                       nomj VARCHAR2(30), adresse VARCHAR2(100), tel VARCHAR2(20),
      4                       coj VARCHAR2(10), nojc NUMBER CONSTRAINT fk_no_joueur_cap REFERENCES joueu
    r(noj) );
    Table créée.
    SQL> INSERT INTO equipe
      2       VALUES (1, 'RC Kouba');
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (1, 1, 'Salim', '... Montreal', '514-111-1111', 'NNN', NULL);
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (2, 1, 'Richard', '... Montreal', '514-111-2222', 'NNN', 1);
    1 ligne créée.
    SQL> INSERT INTO joueur
      2       VALUES (3, 1, 'Stéphane', '... Montreal', '514-111-3333', 'NNN', 1);
    1 ligne créée.
    SQL> COMMIT ;
    Validation effectuée.
    SQL>
    SQL> SELECT   equipe.noe, equipe.nome, j.noj nojc, j.nomj capitaine,
      2           COUNT (joueur.noj) AS "Nombre de joueurs"
      3      FROM joueur, equipe, joueur j
      4     WHERE joueur.noe = equipe.noe AND j.noe = equipe.noe AND j.nojc IS NULL
      5  GROUP BY equipe.noe, nome, j.noj, j.nomj;
           NOE NOME                                 NOJC CAPITAINE                      Nombre de joueurs
             1 RC Kouba                                1 Salim                                          3
    SQL>

  • 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.

  • Group and Group counter in Routing

    Hi all,
    what is group and group counter in routing , how these are used in routing , please explain.
    Regards,
    Joseph.

    Dear Joseph,
    1.Each routing is stored against a group and group counter no.
    2.When we create routing without respect to any material and only by giving the plant,the set of operations gets saved under one
    group counter and group no.
    4.Many materials can be assigned to this same group and group counter no,so that the routing is valid for all the materials included.
    5.When you create a routing for material specific,the set of operation gets saved in a group no and group counter no as 01,when
    you create another routing with another set of operations for the same material,plant and task list combination now the group no
    remains same and the group counter gets saved under 02.
    6.This data can be further helpful in assigning the routing data in the production version,.
    Check and revert
    Regards
    S Mangalraj

  • Max, Min and Count with Group By

    Hello,
    i want the max, min and count of a table, which is grouped by a column
    I need a combination of these two selects:
    select
         max(COUNTRY_S) MAXVALUE,
         min(COUNTRY_S) MINVALUE
    from
         tab_Country
    select
         count(*)
    from
         (select COUNTRY_TXT from tab_Country group by COUNTRY_TXT) ;
    The result should be one row with the max and min value of the table and with the count of the grouped by table, not the max and min of each group! - i hope you understand my question?
    Is this possible in one SQL-select?
    Thank you very much
    Best regards
    Heidi

    Hi, Heidi,
    HeidiWeber wrote:
    Hello,
    i want the max, min and count of a table, which is grouped by a column
    I need a combination of these two selects:
    select 
         max(COUNTRY_S) MAXVALUE, 
         min(COUNTRY_S) MINVALUE 
    from 
         tab_Country 
    select 
         count(*) 
    from 
         (select COUNTRY_TXT from tab_Country group by COUNTRY_TXT) ; 
    The result should be one row with the max and min value of the table and with the count of the grouped by table, not the max and min of each group! - i hope you understand my question?
    Is this possible in one SQL-select?
    Thank you very much
    Best regards
    Heidi
    It's not clear what you want.  Perhaps
    SELECT  MAX (country_s)               AS max_country_s
    ,       MIN (country_s)               AS min_country_s
    ,       COUNT (DISTINCT country_txt)  AS count_country_txt
    FROM    tab_country
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Wsus query needed - get WSUS-Computers, belonging WSUS-Group and Not Installed Count

    Hi,
    i try to find a way by using basic WSUS powershell cmds in combination with piping in Server 2012 R2 to get all registered computers in WSUS plus belonging WSUS-Group and Update "Not Installed Count" as output.
    Is that possible?
    I tried multiple times and enden up in using posh - is there no way based on standard powershell commandlets.
    Thank you
    Peter

    Hi Michael,
    it seems that you are right :(. I tried out a few things with powershell (source
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/19/use-powershell-to-find-missing-updates-on-wsus-client-computers.aspx) - big problem is that i actually cant get belonging WSUS Group to Server object. I only are able to get all WSUS Groups
    but cant find the right sytax to get only belonging ones.
    Any ideas?
    Thanks
    Peter
    #Load assemblies
    [void][system.reflection.assembly]::LoadWithPartialName('Microsoft.UpdateServices.Administration')
    #Create Scope objects
    $computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
    $updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
    #Gather only servers
    $ServersId = @($wsus.GetComputerTargets($computerscope) | Where {
    $_.OSDescription -like "*Server*"
    } | Select -expand Id)
    #Get Update Summary
    $wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) | Where {
    #Filter out non servers
    $ServersId -Contains $_.ComputerTargetID
    } | ForEach {
    New-Object PSObject -Property @{
    ComputerTarget = ($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName
    ComputerTargetGroupIDs = ($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).ComputerTargetGroupIds
    ComputerTargetGroupNames = ($wsus.GetComputerTargetGroups())
    NeededCount = ($_.DownloadedCount + $_.NotInstalledCount)
    #DownloadedCount = $_.DownloadedCount
    NotInstalledCount = $_.NotInstalledCount
    #InstalledCount = $_.InstalledCount

  • Group by and count of line items

    Hi
    I have a requirement to implement group by part # and count of the line items
    I was able to do group by at the node level and how to do the count
    Thanks
    New BIP

    Hi Alex
    sorry did not check until now glad some one came out to help me
    Can i send you the template, xml and output to your email please
    Thanks
    NewBIP

  • Tasl list group and group counter

    hi,
    i have one requirement . I have give internal number range to the task list. so my need to to create task list with one group and several group counter. But what is happening is when i run LSMW for that. seperate group numbers has been generated for each task list. is there any way to get the same group number with different counters using LSMW>

    hi
    since you have given internal number range for task list system will try to create task list with different group numbers .if you want the same group number with different group counter then i think you have to use the task list with external number and use the number created before
    regards
    thyagarajan

  • How do I know which group and group counter used to create current estimate

    Is there a way to know, if for a given set of materials, what groups and groups counters have been used to create the current cost estimate. Or for a given comboniation of material, group and group counter has been used to create a current cost estimate. I can look each up through displaying the cost estimate but I am looking for a quick way since the number of materials are in 100s.
    I was wondering if there is a table I could look up to get the info.
    Any help would be much appreciated.
    Regards

    The name of the table that needs to be used is KEKO. I figured it out so I thought I would share
    Edited by: NIK83 on Mar 7, 2011 10:16 PM

  • CR - giving total transaction count for few groups and 0 for few groups.

    For the column "No of First Call Resolution" I have to count no of interactions based on the Interaction Result, the formula is
    COUNT(Interaction_ID) WHERE INTERACTION_RESULT = 'FCR'
    For which, I wrote the below formula
    If {14CICustomerInteractions_query.Interaction Result} = "FCR" then Count ({14CICustomerInteractions_query.Interaction_ID})
    I have 33,232 interactions on the particular day I selected. When I try to group up and do the calculations it is giving total transaction count for few groups and 0 for few groups.
    Need Solution

    Hi,
    What field is the report grouped on?
    If you wish to find the no of interactions based on some condition and display it for every group, then here's what you need to do:
    1) Create this formula and place this on the details section:
    whileprintingrecords;
    numbervar c;
    If {14CICustomerInteractions_query.Interaction Result} = "FCR" then
    c := c + 1;
    2) Create another formula and place this one on the Group Footer:
    whileprintingrecords;
    numbervar c;
    3) Create this formula to reset the variable and place this on the Group Header:
    whileprintingrecords;
    numbervar c := 0;
    Let me know how this goes!
    -Abhilash

  • Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount 28

    Post Author: tadj188#
    CA Forum: Formula
    Needed: Sum of LineCount Including Groups and Detail Data On Each Page Used To Generate New Page If TotalPageLineCount > 28
    Background:
    1) Report SQL is created with unions to have detail lines continue on a page, until it reaches page footer or report footer, rather than using  subreports.    A subreport report is now essentially a group1a, group1b, etc. (containing column headers and other data within the the report    with their respective detail lines).  I had multiple subreports and each subreport became one union.
    Created and tested, already:
    1) I have calculated @TotalLineForEachOfTheSameGroup, now I need to sum of the individual same group totals to get the total line count on a page.
    Issue:
    1) I need this to create break on a certain line before, it dribbles in to a pre-printed area.
    Other Ideas Appreciated:
    1) Groups/detail lines break inconveniently(dribble) into the pre-printed area, looking for alternatives for above situation.
    Thank you.
    Tadj

    export all image of each page try like this
    var myDoc = app.activeDocument;
    var myFolder = myDoc.filePath;
    var myImage = myDoc.allGraphics;
    for (var i=0; myImage.length>i; i++){
        app.select(myImage[i]);
        var MyImageNmae  = myImage[i].itemLink.name;
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
        app.jpegExportPreferences.exportResolution = 300;
           app.selection[0].exportFile(ExportFormat.JPG, File(myFolder+"/"+MyImageNmae+".JPEG"), false);
        alert(myImage[i].itemLink.name)

  • Total count and count based on column value

    Primaryid  Id     Status
    1            50          1
    2            50          1
    3          50          1
    4            50          3
    5           50          2
    6            50          1
    7            51         1
    8            51         2Im looking for a query which returns total count of rows for id 50 and count of rows with status 1
    something like
    Id    count_total   count_total_status1
    50        6              4
    51        2              1Any suggestion ?

    SQL> select * from t4;
    PID ID STATUS
    1 50 1
    2 50 1
    3 50 1
    4 50 3
    5 50 2
    6 50 1
    7 51 1
    8 51 2
    已选择8行。
    SQL> select distinct id,count(id),sum(decode(status,1,1,0)) from t4 group by id;
    ID COUNT(ID) SUM(DECODE(STATUS,1,1,0))
    51 2 1
    50 6 4

  • What is the difference between function groups and Object Orientation

    Hello all
    I have read about this on the help.sap.com site, I still do not understand it completely, can some one explain me with  a simple example please ? (Not the increment counter example please !).
    Thanks a ton.
    Rgds
    Sameer

    Hello Sameer
    When you call a module of a function group for the first time in your program then the entire function group is loaded. However, this can happen only once within your report and all global variables within the function group will have the same values all the time (except they are manipulated via fm's).
    In contrast, you can create as many instances of the same class as you want and all of them can have different global attributes. And all these instances are independent of each other.
    On the other hand, if fm_A changes global attributes of the function group and fm_B reads these attributes then fm_B read the changed values.
    Or in other words:
    Function Group = can be instantiated only ONCE
    Class = can be instantiated unlimited
    Regards
      Uwe

Maybe you are looking for

  • How can I move move my iphoto Library

    Does anyone know how to move and redirect photos from one drive to another. My photos keep downloading to my hard drive which is quickly running out of space so I have added a new internal storage disk to my G4. It doesn't seem as if there is a way t

  • I have acrobat on old pc and want to move it to new pc?

    Seems like I need to deactivate on old pc and reactivate on new pc, but it has been so long since I bought a new computer for home I can't remember. Any help?

  • Class object from XML.

    Hi. I want to create DataGrid with itemReneder for each column. This is inline generated itemRenderer: DataGridColumn.itemRenderer = new ClassFactory(MyCustomClass); // MyCustomClass - it manually generated class which contains some form items(TextIn

  • IPhoto updating/recovering Issues

    Hello, Quite a while ago, I accidentally deleted my iphoto application. I attempted to recover the application by installing the applications disk that came with my macbook, a late 2010 macbook pro. I successfully installed the applications, iWeb, iD

  • Mls qos trust dscp??? is setting my DSCP values to zero!?

    Hi, I was just doing some testing to ensure that the command 'mls qos trust dscp' is working on my 6509 switches before rolling out QoS. Before adding any configuration I could see using wireshark that traffic from my Avaya 9608 handset was coming th