Count of rows from different Columns

SELECT (SELECT COUNT (empno) empno
          FROM emp) empno, (SELECT COUNT (mgr) mgr
                              FROM emp) mgr, (SELECT COUNT (sal) sal
                                                FROM emp
                                               WHERE sal > 2000) sal
  FROM DUAL;Hi friends
Please let me know any better solutions for this query..??

user10594152 wrote:
Please let me know any better solutions for this query..??Why not just..
SQL> select * from emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
14 rows selected.
SQL> ed
Wrote file afiedt.buf
  1  select count(empno) as emps
  2       , count(mgr) as mgrs
  3       , sum(case when sal > 2000 then 1 else 0 end) as sals
  4* from emp
SQL> /
      EMPS       MGRS       SALS
        14         13          6
SQL>

Similar Messages

  • Count of rows from different tables.

    Hi Friends,
    I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
    Ex
    select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
    please suggest me some solution

    may be thsi?
    select count(a.id) from table1 a,table2 b,table3 c,table4 d
    where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5;

  • How to get multiple records in one row and different column

    Hi All,
    I am using oracle database 11g
    and i have a two tables table_1, table_2
    table_1 having columns
    emp_no
    first_name
    middle_name
    last_name
    email
    and table_2 having columns
    emp_no
    phone_type
    phone_number
    and having entires
    emp_no phone_type phone_number
    1001 MOB 9451421452
    1001 WEMG 235153654
    1001 EMG 652341536
    1002 MOB 9987526312
    1003 WEMG 5332621456
    1004 EMG 59612356
    Now i want the output of values with phone type as MOB or WEMG in a single row with different columns
    emp_no first_name middle_name last_name email mobile officeno
    1001 mark null k [email protected] 9451421452 235153654
    1002 john cena gary [email protected] 9987526312 null
    1003 dany null craig [email protected] null 5332621456
    1004 donald finn sian [email protected] null null
    can i have any inputs to achive this???
    Regards
    $sid

    Frank Kulash wrote:
    sonething like this:Frank, you missed aggregate function (pivot requires one). However main thing is it will cause ORA-01748:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k'last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
    SELECT     *
    FROM     table_1      t1
    JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    PIVOT     (    max(t2.phone_number)
         FOR  t2.phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
            FOR  t2.phone_type  IN  ( 'MOB'   AS mob
    ERROR at line 19:
    ORA-01748: only simple column names allowed hereYou need to:
    with table_1 as (
                     select 1001 emp_no,'mark' first_name,null middle_name,'k' last_name,'[email protected]' email from dual union all
                     select 1002,'john','cena','gary','[email protected]' from dual union all
                     select 1003,'dany',null,'craig','[email protected] null' from dual union all
                     select 1004,'donald','finn','sian','[email protected]' from dual
         table_2 as (
                     select 1001 emp_no,'MOB' phone_type,9451421452 phone_number from dual union all
                     select 1001,'WEMG',235153654 from dual union all
                     select 1001,'EMG',652341536 from dual union all
                     select 1002,'MOB',9987526312 from dual union all
                     select 1003,'WEMG',5332621456 from dual union all
                     select 1004,'EMG',59612356 from dual
         table_3 as (
                     select  t1.emp_no,first_name,middle_name,last_name,email,
                             phone_type,phone_number
                       FROM     table_1      t1
                       LEFT JOIN     table_2      t2  ON  t1.emp_no = t2.emp_no
    SELECT     *
    FROM     table_3
    PIVOT     (    max(phone_number)
         FOR  phone_type  IN  ( 'MOB'   AS mob
                                 , 'WEMG'  AS wemg
        EMP_NO FIRST_ MIDD LAST_ EMAIL                     MOB       WEMG
          1004 donald finn sian  [email protected]
          1003 dany        craig [email protected] null            5332621456
          1001 mark        k     [email protected]      9451421452  235153654
          1002 john   cena gary  [email protected]    9987526312
    SQL>SY.

  • Different number of rows for different columns in JTable

    hi
    I need to create a JTable with different number of rows for different columns...
    Also the rowheight should be different in each column...
    say there is a JTable with 2 columns... Col1 having 5 rows and column 2 having 2 rows...
    The rowHeight in Col2 should be an integer multiple of Rowheight in Col1
    how do I do this ??
    can anybody send me some sample code ?????
    thanx in advance

    How about nesting JTables with 1 row and many columns in a JTable with 1 column and many rows.
    Or you could leave the extra columns null/blank.
    You could use a GridBagLayout and put a panel in each group of cells and not use JTable at all.
    It would help if you were more specific about how you wanted it to appear and behave.

  • Find MIN, MAX of multiple rows from multiple columns

    Hello,
    I need to figure out how to pull the MIN/MAX of multiple rows from multiple columns into one column. Even if some are NULL/blank.
    For Example: (C: Column, R: Row, N - NULL/Blank)
    C:____1____2____3____ 4____Max
    R:____20___22___13____4____*22*
    R:____N____N____32____14___*32*
    R:____N____12____N____N____*12*
    That is, it always gives a value for MIN/MAX unless there are NO values in all the rows of the columns.
    So if there is one value, it will select that for the MIN/MAX, as it's the smallest/biggest since there is nothing to compare it to.
    Here is my current code:
    CASE WHEN COLUMN 1 < COLUMN 2 THEN COLUMN 2 ELSE COLUMN 1 END

    Hi Thank you for your feedback, unfortunately, I just found out that EVALUATE Function is disabled in our environment for security reasons, so the only other way I've discovered is this:
    The problem is that none of the conditions in the case statement are met--so the column is set to null. You can add a WHEN statement (section 2 below) to catch the nulls. There are five cases to consider:
    Case 1: begin insp > bad order
    Case 2: begin insp < bad order
    Case 3: bad order only (begin insp is NULL)
    Case 4: begin insp only (bad order is NULL)
    Case 5: both begin insp is NULL and bad order is NULL
    1) If bgn-crm-insp-ob > report-bo-ob then bgn-crm-insp-ob
    (Case 1)
    CASE WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob') > filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    2) If report-bo-ob is NULL then bgn-crm-insp-ob
    (Case 4, 5) for case 5, you will get NULL
    WHEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') IS NULL THEN filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'bgn-crm-insp-ob')
    3) Else report-bo-ob
    (Cases 2, 3)
    ELSE filter ("- Terminal Task Measures"."Task Reported DateTime (Local)" using "Task Detail"."Task Code" = 'report-bo-ob') END
    Hopefully this works, I'll give feedback if it does, or if you have any further suggestions please submit, again, THANK YOU SO MUCH ANYWAYS!

  • Count of rows having different values

    SQL>  select  * from med;
    CERT  REC  PRIM RACE
    100    10   EN   USA
    100    11   EN   USA
    100    12   EN   USA
    100    13   SP   MX
    200    14   SP   MX
    200    15   SP   MX
    6 rows selected.
    SQL>  select  * from sub;
    CERT  REC PRIM RACE
    100    10   EN   USA
    100    11   EN   USA
    100    12   EN   USA
    100    13   SP   MX
    200    14   SP   MX
    200    15
    6 rows selected.
    SQL> select  * from den;
    CERT  REC  PRIM RACE
    100    01   EN   USA
    100    02   EN   USA
    100    03   EN   USA
    100    04   SP   MX
    200    06   SP   MX
    (cert,rec) uniquly identifies a person;
    In Den table rec =med.rec-9 or rec =sub.rec-9 which implies
                med       sub     den
    (cert,rec)=(100,10)=(100,10)=(100,01)How can I find out how many people in the table where the PRIM and RACE hold different values.?

    Hi,
    Perhaps this ,
    with med as (
    select 100 CERT,   10 rec,   'EN' prim,   'USA' race from dual union all
    select 100  ,  11,   'EN',   'USA' from dual union all
    select 100  ,  12,   'EN',   'USA' from dual union all
    select 100  ,  13,   'SP',   'MX' from dual union all
    select 200  ,  14,   'SP',   'MX' from dual union all
    select 200  ,  15,   'SP',   'MX' from dual )
    sub as (
    select 100 CERT,    10 rec ,  'EN' prim,   'USA' race from dual union all
    select 100,    11 ,  'EN',   'USA' from dual union all
    select 100,    12 ,  'EN',   'USA' from dual union all
    select 100,    13 ,  'SP',   'MX' from dual union all
    select 200,    14 ,  'SP',   'MX' from dual union all
    select 200,    15, null, null  from dual )
    den as (
    select 100 cert,    01 rec,   'EN' prim,  'USA' race from dual union all
    select 100,    02,   'EN' ,  'USA'from dual union all
    select 100,    03,   'EN' ,  'USA'from dual union all
    select 100,    04,   'SP' ,  'MX'from dual union all
    select 200,    06,   'SP' ,  'MX'from dual )
    ----- sample data
    select cert, prim, race ,count(rec) rec
    from (
    select *
    from med
    union all
    select *
    from sub
    union all
    select *
    from den
    group by cert, prim, race
    ORDER BY 1,2,3
          CERT PR RAC        REC
           100 EN USA          9
           100 SP MX           3
           200 SP MX           4
           200                 1HTH
    SS

  • How to convert Rows to different columns

    Hi All,
    I am having a table address with the following data.
    ID          REL_NAME     REL_RELATION  REL_PHONE
    1---          kish_rel1---     wife---     1111
    1---          kish_rel2---     sister---     2222
    1---          kish_rel3---     brother---     3333
    2---          ram_rel1---     brother---     4444
    Now i want to display rows data into columns. See the output i want. Exactly, I dont know how many rows are there for each ID. It may increase or decrease.
    ID          REL_NAME     REL_RELATION  REL_PHONE
    1---kish_rel1---     wife---     1111---kish_rel2---     sister---     2222---kish_rel3---     brother---     3333
    2---ram_rel1---     brother---     4444
    Thanks in advance,
    Pal

    Hi,
    I have found this is useful. But it is static. It wont work if we dont know the maximum number of rows present when grouped by ID.
    Is there any other solution, which will give correct values, if we dont know the row count when grouped by ID.
    SELECT hrid,
    MAX(case when seq=1 then rel_name end) AS "rel_name1",
    MAX(case when seq=1 then rel_relation end) AS "rel_relation1",
    MAX(case when seq=1 then rel_phone end) AS "rel_phone1",
    MAX(case when seq=2 then rel_name end) AS "rel_name2",
    MAX(case when seq=2 then rel_relation end) AS "rel_relation2",
    MAX(case when seq=2 then rel_phone end) AS "rel_phone2",
    MAX(case when seq=3 then rel_name end) AS "rel_name3",
    MAX(case when seq=3 then rel_relation end) AS "rel_relation3",
    MAX(case when seq=3 then rel_phone end) AS "rel_phone3",
    MAX(case when seq=4 then rel_name end) AS "rel_name4",
    MAX(case when seq=4 then rel_relation end) AS "rel_relation4",
    MAX(case when seq=4 then rel_phone end) AS "rel_phone4"
    FROM (SELECT hrid, rel_name, rel_relation, rel_phone, ROW_NUMBER() over(partition by hrid ORDER BY hrid) AS seq FROM address)
    GROUP BY hrid
    Thanks,
    Pal

  • Changing rows into different column names

    Hi,
    i need to tranpose the rows into differnent column names
    my sample data :
    id , val
    1 3
    1 4
    1 5
    into
    id , val1, val2 , val3 , val4 ... valn ..
    1 3 4 5
    from askTom's i see that it's tranpose into a single column using the ref cursor ?
    how can i do made it into different column names ?
    kindly advise
    tks & rdgs

    For example, lets say that you want to order your columns from least value to greatest and that you'll never have more than three values per id. Then you can use the analytic function row_number() like this to create a pivot value.
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table;And so your pivot query ends up looking like this.
    select id,
           max(case when rn=1 then val end) AS val1,
           max(case when rn=2 then val end) AS val2,
           max(case when rn=3 then val end) AS val3
      from (
    select id, val,
           row_number() over (partition by id order by val) as rn
      from your_table
    group by id;But notice that I started out by making up answers to Justin's questions. You'll have to supply the real answers.

  • Distinct data from different columns of a table-Single query

    I have a table with different columns. Each of these columns have entries. A particular column, say, a column called name can have same entries more than one time. Likewise other columns can also have same entries more than once. My requirement is to have distinct entries from each of these columns using a single query, such that , for eg; the name column will contain the name George only once on retrieval. Place column will have the place Newyork only once...like that...but Newyork and newyork should be treated different(likewise in other columns also ie; case sensitive). I want to retrieve the above said using a single query from a table. Kindly help.
    Regards,
    Anees

    You're asking a SQL question in a JDBC forum. Look for a SQL forum. The website of the database manfactuer may have a SQL forum/mailinglist.

  • Count distinct rows from an internal table

    Hi,
    i have an internal table containing pairs of entries like
    1       1
    1       2
    1       3
    2       1
    2       2
    What i want to do is to determine the value of rowcount from first column ( here it would be 2 and not 5 ) - to me it seems like a DISTINCT. Any suggestions for that ?
    Clemens

    Hi clemens,
    1. One of the ways is to use COLLECT.
    2. suppose your original internal table is ITAB.
       Create one more with just one field
        STAB eg.
    3. Loop at ITAB.
        STAB-field1 = ITAB-Field1.
        COLLECT stab.
        ENDLOOP.
    4. In stab u will have only TWO records,
        1
       2
    regards,
    amit m.

  • Count the rows which differes a column value

    msg deleted
    Edited by: user11253970 on Jul 14, 2009 11:33 AM

    Perhaps this
    with a as (
         SELECT cert_no, count(distinct RACE_CODE) RACE_CODES   FROM subscriber
         group by cert_no having count(distinct RACE_CODE) > 0 )
    b as (  
         SELECT cert_no, count(distinct RACE_CODE) RACE_CODES FROM med_subscriber
         group by cert_no having count(distinct RACE_CODE) > 0 )
    c as (
         select cert_no, count(distinct RACE_CODE) RACE_CODES from den_subscriber
         group by cert_no having count(distinct RACE_CODE) > 0 )
    select  cert_no, a.race_codes + b.race_codes||' (in med_subscriber and subscriber tables)'
            ||' , '||  c.race_codes ||' (in den_subscriber table).'  col1
    from a , b ,  c
    where a.cert_no = b.cert_no
    and a.cert_no = c.cert_no
      note: not tested for your data.
    SS

  • Getting 2nd Least Value from Different Column

    Hi there All,
    I have one odd requirement.
    I hava table which has diffrent columns of numeric Datatype.
    The task is to get the least values from the table.
    I can take the least value by least(col1,col2,col3 ...) function.Until this stage it is fine.
    But also I have take 2nd least value and 3rd least value, which I am quite unsure how to get it.
    Looking forward for suggestions.
    Thanks in Advance.
    Regards,
    Ajeet

    The following is a generic solution that will allow you to select the nth least and allow you to pass as many column names as you like and will return null if the nth least requested exceeds the number of distinct values. The nleast function that I wrote uses the str2tbl function by Tom Kyte. I have included a demonstration of its usage below. The value returned for the 1st least is the same as that returned by the least function.
    This should have been posted on the SQL and PL/SQL discussion group of these forums, rather than the general database. I also posted the same response in the SQL discussion group of the Orafaq forums.
    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM your_table
      2  /
          COL1       COL2       COL3
             1          2          3
             4          6          5
             8          7          9
            11         12         10
            15         13         14
            18         17         16
    6 rows selected.
    scott@ORA92> -- type and functions:
    scott@ORA92> create or replace type myTableType as table of number;
      2  /
    Type created.
    scott@ORA92> create or replace function str2tbl( p_str in varchar2 )
      2  return myTableType
      3  as
      4        l_str      long default p_str || ',';
      5        l_n         number;
      6        l_data    myTableType := myTabletype();
      7  begin
      8        loop
      9            l_n := instr( l_str, ',' );
    10            exit when (nvl(l_n,0) = 0);
    11            l_data.extend;
    12            l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
    13            l_str := substr( l_str, l_n+1 );
    14        end loop;
    15        return l_data;
    16  end;
    17  /
    Function created.
    scott@ORA92> CREATE OR REPLACE FUNCTION nleast
      2    (p_n        IN NUMBER,
      3       p_nums        IN VARCHAR2)
      4    RETURN           NUMBER
      5  AS
      6    v_nleast      NUMBER;
      7  BEGIN
      8    SELECT DISTINCT column_value
      9    INTO   v_nleast
    10    FROM   (SELECT column_value,
    11                  DENSE_RANK () OVER (ORDER BY column_value) AS num_rk
    12              FROM   (select *
    13                   from   table (CAST (str2tbl (p_nums) AS mytabletype)))
    14             WHERE   column_value IS NOT NULL)
    15    WHERE  num_rk = p_n;
    16    RETURN v_nleast;
    17  EXCEPTION
    18    WHEN OTHERS THEN RETURN NULL;
    19  END nleast;
    20  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- query:
    scott@ORA92> SELECT col1, col2, col3,
      2           LEAST (col1, col2, col3) AS the_least,
      3           nleast (1, col1 || ',' || col2 || ',' || col3) AS first_least,
      4           nleast (2, col1 || ',' || col2 || ',' || col3) AS second_least,
      5           nleast (3, col1 || ',' || col2 || ',' || col3) AS third_least,
      6           nleast (4, col1 || ',' || col2 || ',' || col3) AS fourth_least
      7  FROM   your_table
      8  /
          COL1       COL2       COL3  THE_LEAST FIRST_LEAST SECOND_LEAST THIRD_LEAST FOURTH_LEAST
             1          2          3          1           1            2           3
             4          6          5          4           4            5           6
             8          7          9          7           7            8           9
            11         12         10         10          10           11          12
            15         13         14         13          13           14          15
            18         17         16         16          16           17          18
    6 rows selected.

  • Using a custom itemrenderer in datagrid to update value in the same row but different column/cell

    Here's what I have so far.  I have one datagrid (dg1) with enable drag and another datagrid (dg2) with dropenabled.  Column3 (col3) of dg2 also has a custom intemrenderer that's just a hslider.
    When an item from dg1 is dropped on dg2, a custom popup appears that asks you to use the slider in the popup to set a stress level.  Click ok and dg2 is populated with dg1's item as well as the value you selected from the popup window.  I was also setting a sliderTemp variable that was bound to the itemrender slider to set it but that's obviously causing issues as well where all the itemrenderer sliders will change to the latest value and I don't want that.
    What is needed from this setup is when you click ok from the popup window, the value you choose from the slider goes into dg2 (that's working) AND the intemrenderer slider needs to be set to that value as well.  Then, if you used the intemrenderer slider you can change the numeric value in the adjacent column (col2).   I just dont know how to hook up the itemrenderer slider to correspond with that numeric value (thatds be in col2 on that row);
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600"
                        xmlns:viewStackEffects="org.efflex.mx.viewStackEffects.*" backgroundColor="#FFFFFF" creationComplete="init(event)"
                        xmlns:components="components.*" xmlns:local="*">
         <mx:Script>
              <![CDATA[
                   import mx.binding.utils.ChangeWatcher;
                   import mx.collections.ArrayCollection;
                   import mx.controls.Alert;
                   import mx.controls.TextInput;
                   import mx.core.DragSource;
                   import mx.core.IUIComponent;
                   import mx.events.CloseEvent;
                   import mx.events.DataGridEvent;
                   import mx.events.DragEvent;
                   import mx.events.FlexEvent;
                   import mx.events.ListEvent;
                   import mx.events.SliderEvent;
                   import mx.events.SliderEventClickTarget;
                   import mx.managers.DragManager;
                   import mx.managers.PopUpManager;
                   import mx.utils.ObjectUtil;
                   [Bindable]private var myDP1:ArrayCollection;
                   [Bindable]private var myDP2:ArrayCollection;
                   [Bindable]public var temp:String;
                   [Bindable]public var slideTemp:Number;
                   private var win:Dialog;     
                   protected function init(event:FlexEvent):void{
                        myDP1 = new ArrayCollection([{col1:'Separation from friends and family due to deployment'},{col1:'Combat'},{col1:'Divorce'},{col1:'Marriage'},
                             {col1:'Loss of job'},{col1:'Death of a comrade'},{col1:'Retirement'},{col1:'Pregnancey'},
                             {col1:'Becoming a parent'},{col1:'Injury from an attack'},{col1:'Death of a loved one'},{col1:'Marital separation'},
                             {col1:'Unwanted sexual experience'},{col1:'Other personal injury or illness'}])
                        myDP2 = new ArrayCollection()
                   protected function button1_clickHandler(event:MouseEvent):void
                        event.preventDefault();
                        if(txt.text != "")
                             Alert.yesLabel = "ok";                    
                             Alert.show("", "Enter Stress Level", 3, this,txtClickHandler);
                   private function image_dragEnter(evt:DragEvent):void {
                        var obj:IUIComponent = IUIComponent(evt.currentTarget);
                        DragManager.acceptDragDrop(obj);
                   private function image_dragDrop(evt:DragEvent):void {
                        var item:Object = dg2.selectedItem;                    
                        var idx:int = myDP2.getItemIndex(item);
                        myDP2.removeItemAt(idx);
                   protected function dg1_changeHandler(event:ListEvent):void
                        temp=event.itemRenderer.data.col1;     
                   protected function dg2_dragDropHandler(event:DragEvent):void
                        event.preventDefault();                         
                        dg2.hideDropFeedback(event as DragEvent)
                        var win:Dialog = PopUpManager.createPopUp(this, Dialog, true) as Dialog;
                        win.btn.addEventListener(MouseEvent.CLICK, addIt);
                        PopUpManager.centerPopUp(win);                              
                        win.mySlide.addEventListener(Event.CHANGE, slideIt);
                   private function txtClickHandler(event:CloseEvent):void {
                        trace("alert");
                        if (event.detail==Alert.YES){
                             myDP2.addItem({label:temp});
                   private function addIt(event:MouseEvent):void{                    
                        myDP2.addItem({col1:temp, col2:slideTemp})
                   private function slideIt(event:SliderEvent):void{                    
                        slideTemp = event.target.value;               
              ]]>
         </mx:Script>
                   <mx:Panel x="10" y="10" width="906" height="481" layout="absolute">
                        <mx:Image x="812" y="367" source="assets/woofie.png" width="64" height="64" dragDrop="image_dragDrop(event);" dragEnter="image_dragEnter(event);"/>
                        <mx:DataGrid x="14" y="81" width="307" height="251" dragEnabled="true" id="dg1" dataProvider="{myDP1}" wordWrap="true" variableRowHeight="true" change="dg1_changeHandler(event)">
                             <mx:columns>
                                  <mx:DataGridColumn headerText="Examples of Life Events" dataField="col1"/>
                             </mx:columns>
                        </mx:DataGrid>
                        <mx:DataGrid x="329" y="81" height="351" width="475" dragEnabled="true" dropEnabled="true" id="dg2"
                                        wordWrap="true" variableRowHeight="true" dataProvider="{myDP2}" editable="true"
                                        dragDrop="dg2_dragDropHandler(event)"  rowHeight="50" verticalGridLines="false" horizontalGridLines="true" >
                             <mx:columns>
                                  <mx:DataGridColumn headerText="Stressor" dataField="col1" width="300" wordWrap="true" editable="false">
                                  </mx:DataGridColumn>
                                  <mx:DataGridColumn headerText="Stress Level" dataField="col2" width="82" editable="false"/>
                                  <mx:DataGridColumn headerText="Indicator" dataField="col3" width="175" paddingLeft="0" paddingRight="0" wordWrap="true" editable="false">
                                       <mx:itemRenderer>
                                            <mx:Component>
                                                 <components:Compslide/>
                                            </mx:Component>
                                       </mx:itemRenderer>
                                  </mx:DataGridColumn>
                             </mx:columns>
                        </mx:DataGrid>                    
                        <mx:Text x="14" y="10" text="The first category of underlying stressors is called Life Events. The list includes both positive and negative changes that individuals experience. Both can be stressful. For example, becoming a parent is usually viewed as a positive thing, but it also involves many new responsibilities that can cause stress. " width="581" height="73" fontSize="12"/>
                        <mx:TextInput x="10" y="380" width="311" id="txt"/>
                        <mx:Text x="10" y="335" text="Add events to your list that are not represented in the example list.  Type and click &quot;Add to List&quot;&#xa;" width="311" height="51" fontSize="12"/>
                        <mx:Button x="234" y="410" label="Add to List" click="button1_clickHandler(event)"/>
                   </mx:Panel>     
    </mx:Application>

    how do i go about doing that?  do i put a change event function in the itemrenderer?  and how would i eventually reference data.col2?

  • Sequential Count of rows in a Column

    Hi,
    In a query, I have a table defined with the relevant detail required by the business. I need to insert a count into the first column so it identifies a unique number. e.g. row 1 = 1, row 2 = 2 etc.
    How can this be done?

    Further to this question, to clarify diagramatically what I'm trying to achieve is as follows:
    Row Counter  | Header 2   |  Header 3  |  Header 4
    1                     data               data           data
    2                     data               data           data                    
    3                     data               data           data
    4                     data               data           data
    I need to add the first column into my report but I don't know how to acheive this.
    Can anyone assist?

  • Need a rolling count of rows from table using just SQL

    Oracle 11gR2
    RHEL 6.4
    Given the following table data:
    EMPLOYEE     HIRE_DATE     TERM_DATE     DEPT
    John Doe          01/01/13                                   101
    Jane Smith       01/05/13                                   102
    Bob Jones        02/04/13          04/22/13             102
    Jenny Boo        03/12/13          03/31/13             103
    Joe Schmoe     03/24/13                                    102
    Bill Max            04/23/13                                   103
    Jill Clay            04/24/13                                   103
    Joe Boom         05/11/13                                   102
    I want to return the number of employees that are still employed for each month so long as they were hired anytime in that month and irregardless if they were terminated later that month (i.e only the month concerns me).  So I would be expecting
    MONTH  EMPLOYEES
    Jan         2
    Feb        3
    Mar        5
    Apr        6   (Jenny Boo has been terminated)
    May       6   (Jenny Boo and Bob Jones have been terminated)  
    I know there are some bright people out there that are SQL experts but I am not one of them.  If there is a way to do this in just SQL I would like to see it.

    Assuming you want count just for months where someone was hired or terminated:
    with t as (
                select  trunc(hire_date,'mm') dt,
                        1 weight
                  from  emp1
               union all
                select  last_day(term_date) + 1 dt,
                        -1 weight
                  from  emp1
                  where term_date is not null
    select  to_char(dt,'FMMonth, YYYY') month,
            sum(sum(weight)) over(order by dt) employees
      from  t
      group by dt
      order by dt
    MONTH            EMPLOYEES
    January, 2013            2
    February, 2013           3
    March, 2013              5
    April, 2013              6
    May, 2013                6
    SQL>
    If you want all months within given range:
    with r as (
               select  date '2013-03-01' from_dt,
                       date '2013-12-01' to_dt
                 from  dual
         t as (
                select  trunc(hire_date,'mm') dt,
                        1 weight,
                        from_dt
                  from  emp1,
                        r
                  where hire_date <= last_day(to_dt)
               union all
                select  last_day(term_date) + 1 dt,
                        -1 weight,
                        from_dt
                  from  emp1,
                        r
                   where last_day(term_date) + 1 <= to_dt
               union all
                select  add_months(from_dt,level - 1) dt,
                        0 weight,
                        from_dt
                  from  r
                  connect by add_months(from_dt,level - 1) <= to_dt
         s as (
               select  dt,
                       sum(sum(weight)) over(order by dt) employees,
                       from_dt
                 from  t
                 group by dt,
                       from_dt
    select  to_char(dt,'FMMonth, YYYY') month,
            employees
      from  s
      where dt >= from_dt
      order by dt
    MONTH            EMPLOYEES
    March, 2013              5
    April, 2013              6
    May, 2013                6
    June, 2013               6
    July, 2013               6
    August, 2013             6
    September, 2013          6
    October, 2013            6
    November, 2013           6
    December, 2013           6
    10 rows selected.
    SQL>
    SY.

Maybe you are looking for