How to display column specified in group by clause only once?

I've a result coming out of a sql query that uses group by clause as follows:
2008-07-25 19" LCD Screen 5
2008-07-25 HP Printer     4
2008-08-01 Hanging Files 11
2008-08-01 Stapler     3
2008-08-15 19" LCD Screen 5
2008-08-15 Hanging Files 14
What should I do in the query to display the result set as follows:
2008-07-25 19" LCD Screen 5
     HP Printer     4
2008-08-01 Hanging Files 11
     Stapler     3
2008-08-15 19" LCD Screen 5
Hanging Files 14

Hi,
That's a display issue, and display issues are best handled by the front end.
What is your frone end?
If it's SQL*Plus, you can use the BREAK command.
For example:
BREAK ON  deptno     NODUPLICATES
SELECT       deptno
,       ename
FROM       scott.emp
ORDER BY  deptno
,            ename
;Output:
`   DEPTNO ENAME
        10 CLARK
           KING
           MILLER
        20 ADAMS
           FORD
           JONES
           SCOTT
           SMITH
        30 ALLEN
           BLAKE
           JAMES
           MARTIN
           TURNER
           WARDNote that deptno is never NULL: KING and MILLER have deptno=10; but it doesn't show in the display, because it's the same as the deptno on the previous row.
NODUPLICATES is actually the default, so you could just say
BREAK ON deptnoThe BREAK command remains in force until you end the session (or un-do it, e.g. with "CLEAR BREAKS")
Remember to issue the BREAK command at least once in the session before running the query.
To get the same results in SQL, use the analytic ROW_NUMBER function.

Similar Messages

  • More than 1 column in the group by clause

    DB Version:10gR2
    I understand the basics of GROUP BY clause. I have a question on why we have on more than 1 columns in GROUP BY clause.
    In the below example, the course name by itself does not make up a group. A Course name plus its BeginDate make up a group. This is the whole point of having more than 1 columns in the GROUP by clause. Right?
    SQL> select r.course, r.begindate , count(r.attendee) as attendees
      3   from registrations r
      4   group by r.course, r.begindate
      5   order by course
      6  /
    COURSE BEGINDATE      ATTENDEES
    JAVA    12/13/1999           5
    JAVA    2/1/2000             3
    OAU     8/10/1999            3
    OAU     9/27/2000            1
    PLS     9/11/2000            3
    SQL     4/12/1999            4
    SQL     10/4/1999            3
    SQL     12/13/1999           2
    XML     2/3/2000             2

    ExpansiveMind wrote:
    Thanks Dmorgan. I am just learning the basics of GROUP BY clause. I have noticed that all Non-aggregate columns in SELECT list have to be present in the GROUP BY clause. I thought it was a "syntactical requirement". Now, i realise that these columns are present in the GROUP BY clause because only a combination of columns make up a group.Well, it is a bit of both actually. It is a syntactic requirement that all non-aggregated columns in the select list must appear in the group by clause. However, the non-aggregated columns in the select list is what defines your group. Your two examples define two different groups, and would answer two different questions.
    John

  • How to use single column in a group by clause

    hi frs
    i hve used sum function in a sql how to use a single column in a query.
    for ex
    select sum(sal),ename,job,deptno,empno from emp
    group by deptnowhether its possible to use single column in a group by class.
    i want like this because in my custom report i need it. Report query has more than 30 column so its not possible to use 30 columns in a group by.
    pls help.
    Thanks
    Rajesh

    Maybe something like this -
    Select ename, job, deptno, empno, sal, col1, col2, col3, col4 ......, coln
    From
    Select SUM(sal) sal, deptno deptno_i
    From Emp
    Group By deptno
    ,Emp
    Where deptno = deptno_i
    Shailender Mehta

  • How to Display Columns when Query is returning No Columns?

    I am Creating a Load Status Dash Board and I want to Dispaly Columns when Load is Not Started  too. As of Now My query is returning no Results which needs to Modified and Display Columns and Status Not Started to it? Could you please suggest any solutions to it? Thanks

    Hi,
    if you like to show a message instead of NO RESULTS . then you could easily get it by changing the custom text in the properties
    if you want it in a table format . you need to have a table with some data according to the reporting requirement
    thanks

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • Select columns not in group by clause

    Hi Guys,
    I want to fetch columns from a table which are not in group by clause. The catch here is that I also need a count and decode column..
    SELECT col_A, col_B, decode(col_C, '10', '10', '26', '26', '00') col_CT, col_X, col_Y count(*) CNT
    FROM TABLE_T
    WHERE col_B IN (100,101,102) AND col_C IN ('44','45','10','26')
    GROUP BY col_A, col_B, decode(col_C, '10', '10', '26', '26', '00')
    ORDER BY col_CT
    Since, col_X and col_Y are not in GROUP BY clause, it throws error. Also, decode/count of the columns makes it more complex.
    Please help me on this.
    Thanks,
    Amy

    Hi, Amy,
    Welcome to the forum!
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statments, relevant columns only) for all tables involved, and the results you want from that data.
    Always say which versionof Oracle you're using.
    How to do what youy want depends on what you want, which is unclear.
    If you say "GROUP BY a, b, c", that means you only want one row of output for each distinct combination of a, b and c. How do x and y fit into that? Do you want a separate output row for each distinct combination of a, b,c, x and y? Then add x and y to the GROUP BY clause. If you don't want separate rows for each combinataion of x and y, what do you want when a group has more than 1 value for either of them?
    You can simplify the code a little by doing the DECODE in a sub-query; then you can use the alias col_ct as many times as you like in the main query. That will make the code easier to maintain, too.

  • How to include case stmt in group by clause

    Hi i have a question,
    How do i include a case statement in the group by clause?
    For example:
    Select
    (case when x.ctry is null then y.ctry else x.ctry end) as coo,
    sum (x.in_amt)
    from
    tbl1 x,
    tbl2 y
    where
    x.id = y.id
    group by
    (case when x.ctry is null then y.ctry else x.ctry end)
    Assume, I have got millions of records in both the tables, then my guess is, the above query might take huge time to complete.
    Any alternate method to do this?

    cd/ wrote:
    To remove the expression from the GROUP BY clause. I didn't advocate any performance improvements, did I?No you didn't. And your advice can indeed remove the expression from the GROUP BY clause. But I'm still puzzled as to why that would be a goal in itself.
    Regards,
    Rob.

  • How to display empty months when grouping records by month

    Guys, I've got a recordset that successfully displays all
    records in the
    table grouped according to the month that the record was
    created in.
    This allows me to display a Monthly tally (a bit like a
    barchart - where the
    height of the column is derived by the qty of records for
    that given month)
    for each of the months in the year so far. However, it dawned
    on me today
    that if there was no activity in a given month, the month
    simply doesn't
    appear at all, rather than displaying but showing "0" as I
    would prefer.
    For example, the type of thing I want to display onscreen is:
    Month 1 2 3 4 5 6 7 8 9 10 11 12
    But let's say there were no records inserted in months June
    to September
    (inclusive), what I'm actually getting onscreen is:
    Month 1 2 3 4 5 10 11 12
    But what I actually want to appear onscreen is:
    Month 1 2 3 4 5 6 7 8 9 10 11 12
    I hope that makes some kind of sense...
    I'm using Dreamweaver CS3, ASP/VBScript, and MySQL.
    My current SQL Statement is as follows:
    SELECT Count(AffiliateID) AS TotalClicks, MONTH(`VisitDate`)
    AS Month
    FROM tbl_affiliaterefferals
    WHERE `AffiliateID` = "49" AND YEAR(`VisitDate`) =
    YEAR(Now()) GROUP BY
    MONTH(`VisitDate`)
    ORDER BY MONTH(`VisitDate`) ASC
    I figured one workaround would be to have 12 separate
    recordsets - one for
    each month - on the one page, but there must be a cleaner way
    of doing it
    surely?
    Any/all help greatly appreciated.
    Regards
    David

    This is a multi-part message in MIME format.
    ------=_NextPart_000_0086_01C932EC.D9CE33D0
    Content-Type: text/plain;
    format=flowed;
    charset="iso-8859-1";
    reply-type=original
    Content-Transfer-Encoding: 7bit
    Hi Joe,
    I've simply got a table, within one cell of which is another
    table to which
    I've applied a background colour and am specifying the height
    of the <td>
    cell as the qty of the number of records returned for Month 1
    of the current
    year. Then I'm applying a repeat region to the <TD>
    cell containing the
    table that varies in height, in order to force the table to
    repeat
    horizontally according to the number of records (months)
    retrieved from the
    database.
    The code for the table is in the attached txt file.
    I appreciate your time in responding however you must have
    missed my
    comments about what I'm working in as I'm working in
    ASP/VBScript and
    haven't the first clue when it comes to PHP.
    I don't suppose you know or can point me in the direction of
    an ASP
    equivalent of your suggestion?
    Regards
    David
    "Joe Makowiec" <[email protected]> wrote in
    message
    news:[email protected]...
    > On 20 Oct 2008 in macromedia.dreamweaver, DTB-K wrote:
    >
    >> I figured one workaround would be to have 12
    separate recordsets -
    >> one for each month - on the one page, but there must
    be a cleaner
    >> way of doing it surely?
    >
    > Without seeing the code you're using to display it...
    >
    > Probably what that code is doing is looping through the
    recordset:
    >
    > <?php do { ?>
    > ...
    > <?php } while ($row_dates =
    mysql_fetch_assoc($dates)); ?>
    >
    > That's DW's standard PHP MySQL recordset behavior. What
    you want to do
    > is something more like:
    >
    > <?php
    > for ($i=1;$i<13;$i++) { // Do 12 months
    > echo '<p>Month: ';
    > echo $i; //Echo the month
    > if ($row_Recordset1['Month'] == $i) {
    > // Have data for this month
    > echo ' Clicks: ';
    > echo $row_Recordset1['TotalClicks'];
    > // Now get the next row
    > // Note that we only want to get the next row if the
    current month
    > // has data. That's why the fetch command is inside the
    if.
    > $row_Recordset1= mysql_fetch_assoc($Recordset1);
    > } // End if
    > echo "</p>\n";
    > } // End for
    > ?>
    >
    > --
    > Joe Makowiec
    >
    http://makowiec.net/
    > Email:
    http://makowiec.net/contact.php
    ------=_NextPart_000_0086_01C932EC.D9CE33D0
    Content-Type: text/plain;
    format=flowed;
    name="Code.txt";
    reply-type=original
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: attachment;
    filename="Code.txt"
    <table border=3D"0" cellpadding=3D"0"
    cellspacing=3D"0">
    <tr>
    <td colspan=3D"2" valign=3D"bottom"><h1>Current
    Year:</h1></td>
    </tr>
    <tr>
    <td valign=3D"bottom" =
    class=3D"BodyTxtsml"><strong>Month</strong></td>
    <%=20
    While ((Repeat1__numRows <> 0) AND (NOT
    Rs_MonthlyClicks.EOF))=20
    %>
    <%Dim TotalClicks, Cellheight
    TotalClicks =3D =
    FormatNumber((Rs_MonthlyClicks.Fields.Item("TotalClicks").Value),
    0, -2, =
    -2, -2)
    Cellheight =3D (TotalClicks)
    %> =20
    <td valign=3D"bottom" class=3D"BodyTxtsml" =
    title=3D"<%=3D(TotalClicks)%>"><div
    align=3D"center"><table border=3D"0" =
    cellspacing=3D"0" cellpadding=3D"0">
    <tr>
    <td height=3D"<%=3D(Cellheight)%>" =
    bgcolor=3D"#003366" onMouseOver=3D"this.bgColor =3D
    '#FFDB9D'" =
    onMouseOut=3D"this.bgColor =3D'#003366'"
    width=3D"40"> </td>
    </tr>
    =
    </table><%=3D(Rs_MonthlyClicks.Fields.Item("Month").Value)%></div></td>
    <%=20
    Repeat1__index=3DRepeat1__index+1
    Repeat1__numRows=3DRepeat1__numRows-1
    Rs_MonthlyClicks.MoveNext()
    Wend
    %> =20
    </tr>
    </table>
    ------=_NextPart_000_0086_01C932EC.D9CE33D0--

  • How to add columns in the Group Custom Columns

    Hi,
    In a group, if you select Edit Group link, and select the Columns tab, and then select the "Modify" button, then select a target type from the drop down, you can pick listed columns and move it to the Selected Columns list. I am interested in adding a column in the drop down list, how do I do that? If the target type is a plug-in that I created, then what properties I should set in the metadata xml file?
    Thanks for the help.

    As far as I am aware, there are no properties in your plugin's target type metadata XML file that relate to what columns show up in the Groups UI in the EM console. I suggest pursuing this as a bug against the Groups UI.

  • How to display Column List (Search Bar - Do Not Display) in Ascending Order

    Hi,
    I am having a Interactive Report..
    In the Search Bar we have Select Columns, under that we have Do Not Display.
    where all the columns (currently not displayed) are listed.
    How can we display these columns in Ascending order
    Thanks,
    Deepak

    Do you want to display these columns in the IR?
    If yes. Select the column you want to display and click the the '>'.
    In the interactive report regions - source, where you have your query to select the columns use order by to sort them in assn order.
    Do you want to keep these columns as 'Do not display' and have them in assn order there?
    Select all columns to display and move the columns back to the 'Do not display' region one by one making selections in assn order.
    Or in the query select the columns in the order desired.
    I don't know if I am helping. I fell like I got your question all wrong. Still...
    Edited by: machan on Dec 11, 2009 11:01 AM

  • How to display employee no in group tree without separator and decimals

    Post Author: makk07
    CA Forum: Formula
    Hi Everyone,   In my database the employee number is stored as follows:8,367.0029,785.00140,742.00   And in the report I have a group based on formula to display employee name and employee number. My formula is as follows:{@Full Name} & ' - ' & {table.EMPLOYEE NO}and in the group tree you will see it asjohn,smith - 140,742.00 but I want to display it as follows:john,smith - 140742, and I am using crystal XI   Please anybody suggest how to achieve that.Thanks in advance

    Post Author: SKodidine
    CA Forum: Formula
    Change your formula to:
    {@Full Name} & ' - ' & totext({table.EMPLOYEE NO},0,'','')

  • Display column name with Group by

    Hi,
    I am having a table with a column series which is repeating.
    When i want to get all the unique series and its count, in the normal sql, I am using
    select series,count(1) from temp_table group by series;
    But the same is not working in the case of SQLX,
    I want <root><series><name count="8">series1</name><name count="18">series2</name></series></root> kind of output.
    But when i use SQLX query,
    select XMLElement("root",XMLElement("series",XMLAgg(XMLElement("name", ... group by series
    it is returning more than one record.
    How to get the desired result??
    Thanks
    Guru

    I wanted to know whether it is possible to get the count in the sqlx itself, Can anybody point me to any SQLX query for that?

  • How to display Column of a particular list to page using Content Search Webpart?

    Hi,
    I am having two columns 'Column1 & Column2' in a list names Demo. I need to display the items of both the columns into a page with the help of Content Search Webpart. I am using SharePoint 2013 Platform.
    Expecting some useful comments on the same...!!
    Warm Regards,
    Tony Joy.

    Hi,
    If you just want to display two columns of a list, Content Query Web Part will be more appropriate:
    http://community.bamboosolutions.com/blogs/sharepoint-2013/archive/2013/05/10/how-to-use-the-content-query-web-part-to-rollup-data-in-sharepoint-2013.aspx
    To display multiple columns, here is a similar thread for your reference:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/1484df2b-0fb9-4b58-b833-a75019db88c7/content-query-display-multiple-columns
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to display Column data in one row

    Hello,
    I have one Employee with 4 effective date displayed in one column. Effective date is drived by Reason of : New Hire, Rehire, Transfer etc.
    I want to show the effective dates for one reason in one single row. For example a person was rehired 4 times it will show as
    1006555     6/12/2006     1/2/2007     6/11/2007     5/12/2008     12/29/2008     5/17/2010
    It's currntly showing as:
    AUDITEFFECTIVEDATE_3
    6/12/2006
    1/2/2007
    6/11/2007
    5/12/2008
    5/17/2010

    Well that's a little tougher... For a solution to work, you're going to need to find a way to differentiate between the the specific hiring events.  Without seeing what data is available, I'd say start looking at the use of running totals... or in this case a running count.
    Set it up to reset on EmployeeID and count each "event", incrimenting up with each instance.
    Then your formula would look more like this...
    IF {EventType} = "Rehire" AND {#RTotal1} = 1 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Exit" AND {#RTotal1} = 1 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Rehire" AND {#RTotal1} = 2 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Exit" AND {#RTotal1} = 2 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Rehire" AND {#RTotal1} = 3 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Exit" AND {#RTotal1} = 3 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Rehire" AND {#RTotal1} = 4 THEN AUDITEFFECTIVEDATE_3
    IF {EventType} = "Exit" AND {#RTotal1} = 4 THEN AUDITEFFECTIVEDATE_3
    This issue then becomes an issue of space on the report. You end up wasting 1/2 of your horizontal space trying to allot for one odd ball... You'll also get to re-work the report if the same employee goes for rounds 5, 6 or 7...
    HTH,
    Jason

  • How to display  Columns  in Alphabatical  order when using DESC command

    Hello
    A table column is inserted not in alphabetic order during the table creation definition.
    So while describing the table definition (e.g. desc emp)
    it will not show in the same order as we are written during the table creation.
    Question: is there any utility/command/query which will display the columns in alphabatical order while describing it.
    Regards
    Nikhil Wani

    select column_name from user_tab_columns
    order by column_name;
    should do it.
    Sunil

Maybe you are looking for

  • How to remove login form for iView in portal

    Hi, I have created a workset in portal which provides links for various BI reports. In the properties of each page for report I set the property to lunch it in headerless window. When I login with test user and click on link for report its asking for

  • Sorting photo's between albums in iphoto

    I have a huge photo library that I am trying to sort out.  There are photos that have been included in more than one album on my source list, how can I identify these and the albums they are in?  I have run a duplicates anhilator already so know ther

  • Task URL causing error in SharePoint Designer

    Hi I am creating a workflow in designer and I have a step to send out an email. In the email I am inputting a Hyperlink where the user can click on and directly go to the task to approve. I type the description or text to be displayed and put the ful

  • Management Point created using Powershell will error CM Console when viewing properties

    Greetings, We have an established ConfigMgr 2012 R2 CU3 environment with several Primaries and management points already active. These were all installed manually using the CM Console. I am now trying to add additional Management Points using Powersh

  • How do I activate/use the subwoofer on a 5.1 Dolby Digital-system in ga

    Hello guys, in most games I don't have sound on the subwoofer of my Onkyo TX-DS 575. The Onkyo receiver is set to multi-channel input (which basically connects the signal through the receiver without altering it) and the separate channels (5 surround