Column Group Values Function without using Analytics?

I'm looking for a out-of-the-box Oracle SQL function that will visually group column values. (As shown in the Department column below).
I know that you can accomplish this using analytic lead/lag functions (also shown below), but I figure there must be another simpler, straight-forward function than this?
  SELECT   CASE
              WHEN LAG (deptno)
                      OVER (PARTITION BY deptno
                            ORDER BY ename) IS NULL
              THEN
                 deptno
           END department,
           ename,
           empno
    FROM   scott.emp   
ORDER BY   deptno,
           ename;
DEPARTMENT     ENAME     EMPNO
10          CLARK     7782
          KING     7839
          MILLER     7934
20          ADAMS     7876
          FORD     7902
          JONES     7566
          SCOTT     7788
          SMITH     7369
30          ALLEN     7499
          BLAKE     7698
          JAMES     7900
          MARTIN     7654
          TURNER     7844
          WARD     7521

Solution with model
select deptno  ,empno,ename,ind
from emp
model
partition by ( deptno dept )
dimension by (row_number()over(partition by deptno order by empno) rn)
measures(empno,deptno , ename, 0 ind)ignore nav
rules(deptno[rn>1]=null,
ind[rn>1]= 1
)order by dept,ind
SQL> select deptno  ,empno,ename,ind
  2  from emp
  3  model
  4  partition by ( deptno dept )
  5  dimension by (row_number()over(partition by deptno order by empno) rn)
  6  measures(empno,deptno , ename, 0 ind)ignore nav
  7  rules(deptno[rn>1]=null,
  8  ind[rn>1]= 1
  9  )order by dept,ind
10  /
    DEPTNO      EMPNO ENAME             IND
        10       7782 CLARK               0
                 7934 MILLER              1
                 7839 KING                1
        20       7369 SMITH               0
                 7566 JONES               1
                 7902 FORD                1
                 7876 ADAMS               1
                 7788 SCOTT               1
        30       7499 ALLEN               0
                 7900 JAMES               1
                 7844 TURNER              1
                 7698 BLAKE               1
                 7654 MARTIN              1
                 7521 WARD                1
                 4568 salim               0
15 rows selected.
SQL> Edited by: Salim Chelabi on Mar 31, 2009 3:33 PM

Similar Messages

  • SQL Server Reporting Services- Coloring a Cell Background Based on two different column group values

    Hello All,
    I have a matrix report with time scale on the x axis  and Resources on Y axis Showing the tasks assigned to each resource for a period of time. Here I have to color a matrix cell showing task details on tool tip with background color of the cell.
    So Please help me on this.I have a expression like this...
    In my case the color should be filled for the cell with name "Fields!task_name.Value" based on the values of "Fields!Day_Wise.Value " where we have the values for Daywise as S,M,T,W,T,F,S. So i need the background for the cell with name
    task_name as Light Grey on Friday and Saturday, But we have the same name S for sunday also, which should come in different color.
    =iif(Fields!Day_Wise.Value ="F","LightGrey",
    IIF(PREVIOUS(Fields!Day_Wise.Value) ="F","LightGrey",
    iif(Fields!task_name.Value="","White",
    iif(InStr(Fields!task_name.Value,"||")>0,"Maroon",
    iif(InStr(Fields!task_name.Value,"NULL")>0,"Sienna",
    iif(InStr(Fields!task_name.Value,"Pink")>0,"Pink",
    iif(InStr(Fields!task_name.Value,"Red")>0,"Red",
    iif(InStr(Fields!task_name.Value,"Purple")>0,"Purple",
    iif(InStr(Fields!task_name.Value,"Green")>0,"Green",
    iif(InStr(Fields!task_name.Value,"White")>0,"White",
    iif(InStr(Fields!task_name.Value,"Cyan (Teal)")>0,"Teal",
    iif(InStr(Fields!task_name.Value,"Olive")>0,"Olive",
    iif(InStr(Fields!task_name.Value,"Blue")>0,"Blue",
    iif(InStr(Fields!task_name.Value,"Light Blue (Aqua)")>0,"LightBlue",
    iif(InStr(Fields!task_name.Value,"Yellow")>0,"Yellow","Black"
    Thanks
    AJ Hameed

    Hi AJ Hameed,
    According to your description, you want to set the background color for the cells based on the values inside of cells and the values the column group. You want to set grey for cells on Friday and Saturday, set colors based on the task name on other weekdays.
    Right?
    In Reporting Services, there's no problem if we have two different data values in conditional expression, so we can set background color based on Day_Wise or task_name. One issue in this scenario is, we can't have value "S" for both Saturday and Sunday when
    working in a matrix. Otherwise the task_name will overwrite the previous task_name (for numeric values, it will do sum calculation). So we suggest you change the values for weekdays in database. The expression you have posted was correct. It only has a small
    issue: the "Light Blue(Aqua)" also contains "Blue", so when doing conditional judging, the expression will return "Blue" instead of "Light Blue". We have tested in our local environment. For viewing convenience, we used the Switch() function in our expression:
    =IIf(Fields!Day_Wise.Value="Fri" or Fields!Day_Wise.Value="Sat","LightGrey",
    Switch(
    InStr(Fields!Task_name.Value,"White")>0,"White",
    InStr(Fields!Task_name.Value,"||")>0,"Maroon",
    InStr(Fields!Task_name.Value,"Pink")>0,"Pink",
    InStr(Fields!Task_name.Value,"Red")>0,"Red",
    InStr(Fields!Task_name.Value,"Purple")>0,"Purple",
    InStr(Fields!Task_name.Value,"Green")>0,"Green",
    InStr(Fields!Task_name.Value,"Cyan(Teal)")>0,"Teal",
    Fields!Task_name.Value="","White",
    InStr(Fields!Task_name.Value,"Olive")>0,"Olive",
    InStr(Fields!Task_name.Value,"Blue")>0,"Blue",
    InStr(Fields!Task_name.Value,"Aqua")>0,"LightBlue",
    InStr(Fields!Task_name.Value,"Yellow")>0,"Yellow",
    InStr(Fields!Task_name.Value,"Orange")>0,"Orange",
    InStr(Fields!Task_name.Value,"Null")>0,"Sienna",
    true,"Black"
    The result looks like below:
    Reference:
    Matrices (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How can I publish an App to a selceted group of people without using the Adobe Contetn Viewer?

    How can I publish an App to a selected group of people ( not via App Store) without using the Adobe Content Viewer?
    The App was developed with InDesign 6.0

    You'd have to sign up for an Apple Developer account and then gather all the UDID's (Apple limits this to only 100 devices) that you want your app to be installed on. Create your mobile provisioning profiles to include these ID's and then you could use TestFlight to push out your app and monitor who has installed it. Of course Testflight is intended for monitoring your apps performance but I'm sure you can get away with it if you use it to push you app. One thing to keep in mind is the mobile provisoning profiles are only valid for 1 year. Hope this helps.

  • Passing parameters to table valued functions and using parameters as column name on select

    I am creating a function where I want to pass it parameters and then use those parameters in a select statement. When I do that it selects the variable name as a literal not a column. How do I switch that context.
    Query:
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
    @BANNER_COLUMN AS VARCHAR(MAX),
    @ORION_COLUMN AS VARCHAR(MAX)
    RETURNS @Banner_Orion_Employee_Comparison TABLE 
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison
    (LAST_NAME, BANNER, ORION)
    SELECT
    a.LAST_NAME, @BANNER_COLUMN, @ORION_COLUMN
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    Output
    I execute this:
    select * from ufn_Banner_Orion_Employee_Comparison_parser_v2 ('a.BANNER_RANK' , 'b.[rank]')
    and get:
    Cerecerez NULL
    NULL a.BANNER_RANK
    b.[rank]
          

    George,
    You could go for using a CASE statement as earlier mentioned by Erland. This would look like below: (Downside is that you need to be mentioning all possible values in the CASE)
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
    @BANNER_COLUMN AS VARCHAR(MAX),
    @ORION_COLUMN AS VARCHAR(MAX)
    RETURNS @Banner_Orion_Employee_Comparison TABLE
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
    SELECT
    a.LAST_NAME
    , CASE @BANNER_COLUMN WHEN 'a.BANNER_RANK' THEN a.BANNER_RANK WHEN 'a.BADGE' THEN a.BADGE END --put values as required
    , CASE @ORION_COLUMN WHEN 'b.[rank]' THEN b.[rank] END --put values as required
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    Another method that I would suggest is to get all values from the function, then build a dynamic query to obtain results from it .. Something like:
    ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]()
    RETURNS @Banner_Orion_Employee_Comparison TABLE
    LAST_NAME nvarchar(max),
    EMPNO int,
    BannerColumnName nvarchar(max),
    BANNER nvarchar(max),
    ORION nvarchar(max)
    AS
    BEGIN
    INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
    SELECT
    * --Returns all the columns
    FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
    inner join IWM_Stage.dbo.ViewPersonnel AS b
    on a.BADGE = b.badge
    WHERE a.EMP_STATUS = 'A'
    and a.BANNER_RANK <> b.[rank]
    RETURN;
    END;
    GO
    --Execution
    DECLARE @BANNER_COLUMN AS VARCHAR(MAX), @ORION_COLUMN AS VARCHAR(MAX),@SQL NVARCHAR(MAX)
    SET @BANNER_COLUMN='BANNER_RANK'
    SET @ORION_COLUMN='[rank]'
    SET @SQL='
    select LAST_NAME,'+@BANNER_COLUMN+','+@ORION_COLUMN+' from ufn_Banner_Orion_Employee_Comparison_parser_v2 ()'
    PRINT @SQL
    EXEC @SQL
    You just need to make sure that the column names returned by the function are UNIQUE (Using proper alias names) so that you don't have a problem referring to them from the outside..
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • SP Online - Managed Metadata column Default Value for folders (using CSOM)

    Hello,
    I am working on setting default values (metadata columns)  for different folders on my document library. As so far, I've found solution about how to set default values on whole library and many solutions which works for folders, but not for sharepoint
    online (using metadataDefaults object).
    The only working solution for folders in SPO I've found is editing file library/Forms/client_LocationBasedDefaults and add some data here.
    My question is: is there any easier method to set default values for each folder in document library without manually editing this file? 

    I second that, I have a client looking to do the same thing but I don't see a way to automate this.

  • Which group by function to use in following case?

    Table name: PVH
    | Processid | Name | Timechanged | Value |
    | 268436769 | filecount | 10/1/2008 2:59:01.006000 AM | 0 |
    | 268436769 | filecount | 10/1/2008 2:45:33.004000 AM | 100 |
    I want "value" where max(timechanged) and groupby appianprocessid and name …… that is "0"
    How to get that using simple SQL? I tried following two approaces….
    Select max(timechanged), value from pvh where appianprocessid=268436769 group by appianprocessid, name, value
    This query returns me two values...
    Select max(timechanged), max(value) from pvh where appianprocessid=268436769 group by appianprocessid, name
    This
    Thanks
    Sandeep

    Hello,
    Try:
    SELECT name,  value, timechanged
      FROM PVH p1
    WHERE timechanged = (
      SELECT MAX(timechanged)
        FROM PVH p2
      WHERE p1.appianprocessid = p2.appianprocessid)
    WHERE appianprocessid = 268436769 ;Edited by: SeánMacGC on Jul 14, 2009 2:55 PM
    And another way:
    SELECT name, value, timchanged
      FROM (
      SELECT name,  value, timechanged,
            ROW_NUMBER() OVER (PARTITION BY appianprocessid ORDER BY timechanged DESC) row_num
        FROM PVH)
    WHERE appianprocessid = 268436769
        AND row_num <= 1;And if the timechanged can have duplicate values for each appianprocessid, and you want all rows with the same MAX(appianprocessid), change ROW_NUMBER to RANK in that second query.

  • Global functions without using unique AS file

    Hi all,
    I'm tinkering around with things in AS3, and now that programming the reaction of buttons involves a bit more code, I'm trying to figure out how to kill a few redundancies.
    With the file I'm working with, at different points, using different objects, the user will click some specific thing to advance the main timeline one frame.
    Now, the way I've been doing it is, for each object, I have an addEventListener, which calls a function that only contains:
    MovieClip(root).nextFrame();
    So I've got, on every frame, unique functions that each require three additional lines of code -- I realize it's not much, and it's not a lazy thing, just an organizational, minimization thing.
    Since it's just that one thing, I don't see the point in making an entire AS file, so I didn't know if there was a way to make a function that could be called from any frame, from any object, rather than just have them local.

    I've tried that, but the objects that call the function are all within movie objects that are on the main timeline.  Since they aren't on the main time line, even if I declare a function on the main time line, the code inside the object doesn't see that function declaration and I get an "Access of undefined property" error.

  • Database functions without using a database

    I think I should have posted this here instead of on the
    basics are. Anyway here is my problem.
    I'm creating a little standalone program that needs to have
    database like functions. The program needs to store data fields
    like names, titles, etc. that can be modified/customized by the
    user. I've done this before in mySQL. But I don't want the user to
    have to go to a website or have a database loaded on their
    computer. I just want the fields to be stored in some type of
    document file that would be in the same folder as the program. Any
    suggestions?

    There are several options - all require some simple
    scripting. To name a couple:
    Director can write to text files with the built-in Fileio
    xtra, so you could create a delimited text file database.
    Director's list functions are perfect for creating a simple
    database. You can save lists to files easily using the propSave or
    vList xtras - fre IIRC for simple this simple functionality
    http://www.updatestage.com/products_table.html
    hth
    johnAq

  • Accessing groups on wiki without using WWW

    My issue similar to the other thread but I don't thinks its a permission problem.
    if you type www.example.com everything works. You drop the WWW and everything works
    except when you click on a wiki group it says its not found even though it works
    and it let me click on it. Users and Webmail do not have this problem.

    I have the same issue, and a Apple tech support agent confirmed, though doesn't necessarily sympathize. Two recommendations I heard for getting wiki's to appear as consistently as the rest of your web site...
    A) Force users to only access the version of your domain name listed in Server Admin's "domain name" field (not in "web server aliases"). In your case, I assume you have "www.example.com" listed in the "domain name" field. This would apparently involve hard-coding all links to wikis with absolute URL's. It may also involve redirects, so that if a visitor manually types a wiki address without the "www" that they are redirected to the "www" address.
    B) If the server only hosts one web site: Within Server Admin, leave the "domain name" field blank.

  • How  group by function/procedure used in function

    i want to capture information in different table which extract by select statement like(select trans_date from bankAccount group by cust_id).

    CTAS - Create Table As Select.
    Example:
    CREATE TABLE my_results
    NOLOGGING AS
    SELECT
      trans_date
    FROM bankAccount
    GROUP BY
      cust_idRefer to the [url http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm]Oracle® Database SQL Reference for details.

  • Need to take rownum highest value without using grouping functions

    Hi
    I want to display highest value in the rownum column and customer details without using grouping functions like max or count
    this below query gives me all rownum values and customer details
    SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER;
    can any one help me.

    The above query won't work as it's missing "from" cluase in the inner select statement.
    And even if corrected it willl print rownum values thrice: value "1",max_rownum, max_rownum followed by customer details.
    Below is the simple query to retrieve max row_num along with the corresponding customer details.
    select * from (SELECT ROWNUM ROWNUM_1, CUSTOMER_NO, CUSTOMER_NAME, CUSTOMER_DOJ, CUSTOMER_MOBILENO FROM CUSTOMER order by rownum_1 desc) where rownum<=1 ;

  • Use HCM processes and Forms without using the Enterprise Portal

    is it possible to leverage existing HR Admin Services (HCM processes and Forms) functionality without using the Enterprise Portal?
    1) Create an Adobe form and Interface using SFP
    2) Set up ISR and Form Scenario
    3) Set up Forms configuration to use existing Backend and generic Services
    4) Set up workflow to updated Backend using Services
    is it possible to do the above steps and not use the Portal? If Yes, how do we present the forms to the Manager, and provide different buttons that appears on the Portal by default?
    Any ideas will be greatly appreciated.
    Thanks,
    Saurabh

    Hi Saurabh,
    your assumptions and findings (items can not be started from the backend workflow inbox etc.) are correct: These processes can not be started without the Portal and it is not intended to do this.
    The above mentioned backend report are only forseen for implementation and testing purposes and not for productive use.
    In addition to the fact, that you already can't execute the work items a lot of other features of the framework (Process Browser etc.) are only available through the Portal.
    Best Regards
    Michael Bonrat - Solution Manager HCM Processes and Forms
    Info about HCM Processes and Forms:
    www.service.sap.com/erp: 
    - SAP ERP Human Capital Management -> Workforce Process Management -> HCM Processes and Forms

  • Drill down report without using heirarchies in OBIEE11g

    Hi,
    Can we create multiple column drill down report without using hierarchies in OBIEE11g?
    Kindly let me know the solution.
    Thank you!
    -Harshith

    Yes, It can be done, but for each drill level you will require one seperate report. Drilling can be achieved using OBIEE Report Navigation.
    For eg. If I have to create a drill report which starts from Year and goes to QTR and then to Month level. That means I have to create 3 reports.
    1. A year report which will have report data at year level (Consider Year, Product, Order_QTY and Order_Amt are the columns)
    2. A QTR report which will have report data at Qtr level. This report will have Year column in filter section as IS PROMPTED (Consider Qtr, Product, Order_QTY and Order_Amt are the columns).
    3. A Monthly report which will have report data at Month level. This report will have Year, Qtr column in filter section as IS PROMPTED (Consider Month, Product, Order_QTY and Order_Amt are the columns).
    Then we can go to Yearly report and put the OBIEE navigation on Year column and our target report will be QTR report. Similarly in Qtrly report put the OBIEE navigation on QTR column and our Target report will be Monthly report.
    This way you can impliment drilling without hierarchy.
    For step by step see below URL:
    http://www.askjohnobiee.com/2012/07/how-to-drill-through-guided-navigation.html
    Appriciate if you can mark Correct.
    Thanks,
    Kashi
    Edited by: K N Yadav on 4 Jun, 2013 10:27 PM

  • How to run a PLSQL mapping without using OWB Interface

    Hi there, does anybody know how to call a PL/SQL mapping <mapname.main> function without using OWB interface. We will have to create some other mechanism to call those generated mappings....
    Thanks in advance

    Hi Marcelo ,
    You can use the following code at the sql prompt to the run the mapping .
    DECLARE
    RetVal NUMBER;
    P_ENV WB_RT_MAPAUDIT.WB_RT_NAME_VALUES;
    BEGIN
    RetVal := <Mapping Name>.MAIN(P_ENV) ;
    COMMIT;
    END;
    Regards,
    Shashin

  • Need Workaround for periodical autocommit in WebForms without using Timer

    Hi guys...
    I need to use autocommit in my form for say 1 min.
    As ther is a great performance degradation when i go for timers, i need a workaround to achieve the same functionality without using timers.
    Thanx & Regards
    Sriram

    <p>Get this zip file
    <br><br>
    unzip the file<br>
    copy the bean_timer.jar in your <forms_home>/java directory<br>
    update your formsweb.cfg configuration file<br>
    archive_jini=f90all_jinit.jar,...,bean_timer.jar<br><br>
    open, compile and run the beantimer.fmb sample demo
    <br>
    </p>
    Francois

Maybe you are looking for

  • NFS causes whole system hang

    I have a home server that I just set up recently that runs Arch linux.  It exports a couple of external hard drives via NFS.  I have been mouting them with autofs on my laptop.  However, after several hours the entire system completely hangs up.  I o

  • Using interop DLL to rename steps?

    I am using teststand 2.0 If I rename a step in the Sequence Editor, the editor will automatically update all references to the step (in preconditions, pre/post expressions and so on) to match the new name. The problem: I am writing a program that use

  • Export pic in iphoto

    When I go to Iphoto and highlight one picture to export (say golf clubs cause I want to advertise on Craigslist) and try to export it to desktop, it says: unable to create/users/bryanevie/desktop    (bryanevie is where I have my documents, etc.)  Can

  • No thumbnails on xfce Desktop

    There might be a very silly workaround, but I cant find any to show thumbnails of images on the xfce desktop. Thunar though, can show them. Anyone have any tips?

  • IMAP Notification mailer

    Hello, EBS 11.5.10.2 RDBMS : 11.2 My workfllow notificcation mailer is configured with an imap server under linux named dovcot. My workflow notificaiton mailer is runnig (green flag) but during an approval the mail stuck into inbox ... Nothing in log