Help for the query

hello,
I have a question again. The tables for the query are "Patient" and "Station".
Station-Table:
s_id, station
Patient-Table:
p_id, name, s_id, gender
I want to know how many Patient are Male and Female for each Station. That means that the output should be:
Station Male Female
S1 12 10
S2 6 4

I supposed the values in gender are 'M' for Male and 'F' for Female
select s.station, sum(decode(p.gender, 'M', 1, 0)) Male , sum(decode(p.gender, 'F', 1, 0)) Female
from station s, patient p
where s.s_id=p.s_id
group by s.station;

Similar Messages

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • Need help for the query columns to rows

    Hi everyone,
    I have two tables TABLE1 and TABLE2; TABLE1 is Master table,TABLE2 is child table.
    The key for TABLE1 is C1 column
    The key for TABLE2 is C1,C_MONTH Columns
    The sample data is as follows
    TABLE1
    ======
    C1 C2
    1 A
    2 B
    3 C
    4 D
    TABLE2
    ======
    C1 C_MONTH C3
    1 JAN AAA
    1 FEB BBB
    1 MAR CCC
    1 APR DDD
    2 JAN ZZZ
    2 FEB YYY
    2 MAR XXX
    2 APR UUU
    I want to display the data as follows
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    Can any one help me how to write this query?
    Thanks in advance

    [email protected] wrote:
    Thanks for the update
    but I want the out put as column values rather than one column as follows
    C1 C2 J_MONTH J_VALUE F_MONTH F_VALUE M_MONTH M_VALUE A_MONTH A_VALUE
    1 A JAN AAA FEB BBB MAR CCC APR DDD
    2 B JAN ZZZ FEB YYY MAR XXX APR UUUThis is a standard pivot.
    In 10g or below you can do something like...
    SQL> ed
    Wrote file afiedt.buf
      1  with table1 as (
      2                  select 1 c1, 'A' c2 from dual union all
      3                  select 2, 'B' from dual union all
      4                  select 3, 'C' from dual union all
      5                  select 4, 'D' from dual
      6                 ),
      7       table2 as (
      8                  select 1 c1, 'JAN' C_MONTH,'AAA' C3 from dual union all
      9                  select 1,'FEB','BBB' C3 from dual union all
    10                  select 1,'MAR','CCC' C3 from dual union all
    11                  select 1,'APR','DDD' C3 from dual union all
    12                  select 2,'JAN','ZZZ' C3 from dual union all
    13                  select 2,'FEB','YYY' C3 from dual union all
    14                  select 2,'MAR','XXX' C3 from dual union all
    15                  select 2,'APR','UUU' C3 from dual
    16                 )
    17  -- end of test data
    18  select table1.c1, table1.c2
    19        ,max(decode(c_month, 'JAN', c_month)) as jan_month
    20        ,max(decode(c_month, 'JAN', c3)) as jan_value
    21        ,max(decode(c_month, 'FEB', c_month)) as feb_month
    22        ,max(decode(c_month, 'FEB', c3)) as feb_value
    23        ,max(decode(c_month, 'MAR', c_month)) as mar_month
    24        ,max(decode(c_month, 'MAR', c3)) as mar_value
    25        ,max(decode(c_month, 'APR', c_month)) as apr_month
    26        ,max(decode(c_month, 'APR', c3)) as apr_value
    27  from table1 join table2 on (table1.c1 = table2.c1)
    28* group by table1.c1, table1.c2
    SQL> /
            C1 C JAN JAN FEB FEB MAR MAR APR APR
             1 A JAN AAA FEB BBB MAR CCC APR DDD
             2 B JAN ZZZ FEB YYY MAR XXX APR UUU
    SQL>From 11g upwards you can use the new PIVOT keyword.

  • Needs help for the query

    Hi All,
    I had atable containing 2 columns like NO and Grade.
    ID Grade DEPTID
    1 A 10
    2 E 20
    3 D 20
    4 C 30
    5 H 10
    6 K 10
    7 B 30
    8 L 30
    9 R 20
    i need output as
    DEPTID Employees and grades in the DEPT
    10 1 A , 5 H , 6 K
    20 2 E , 3 D , 9 R
    30 4 C , 7 B , 8 L
    Please anyone give me query for this.
    thanks in advance.
    rampa

    STRAGG for string aggregation. One of the most frequent ask question over here.
    Here a forum search for you.
    Of course, the options depend of version you are on.
    Nicolas.

  • RPD - Cannot obtain number of columns for the query result :Working with MS SQL 2012 schema

    Hi All,
    I have created my warehouse in MS SQL 2012.
    For management purpose, I have created different schemas in SQL database
    In RPD, Physical layer, when i view data > I get error as
    [nQSError:16002] Cannot obtain number of columns for the query result.
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Invalid object name 'tbl'..
    [nQSError:16001] ODBC error state : S0002 code : 208 message: [Microsoft][ODBC SQL Server Driver][SQL Server] Statements could not be prepared..
    I have already browsed : OBIEE 11g Strange ODBC Driver Error with SQL Server : Total Business Intelligence ... did not help me
    please help!!!

    Hi All,
    After all R&D it is been found that Oracle business administrator( RPD) needs default dbo schema. It doesn't accept custom schema for pulling data.
    If anybody have other views please share.!!
    Thank you

  • To know the users and the variables for the query

    Hi,
    Say I have one query and which is executed 5 times in the day n i can see this in ST03N Expert mode. Now, suppose i want to see the users who executed the query and what are the selections they gave for the query to run, is there a place to see this?
    Appreciate your time
    Sriram

    Sriram,
    You can use BW Statistics to view technical information regarding users. SAP also delivers queries that give you usage by users, just install from business content. The statistics cubes extract data from various tables including:
    RSDDSTAT
    RSDDSTATAGGR
    etc..
    You can search more, names will start with "RSDDSTAT*"
    Hope it helps,
    Farhan

  • Help wit the query

    I need help with the query
    Here is what I need
    For a particular comm record if there is no Salary record where comm:Date = Salary:Date, then
    • Find maximum dated Salary record as of comm:Date.
    • Clone this record and set Salary:Date = comm:Date
    • Set Salary:rate = comm:rate
    Like wise for a particular Salary record If there is no comm record where Salary:Date = comm:Date then
    • Find maximum effective dated comm record as of Salary:Date
    • Apply Rate 2 amount from this maximum effective dated record to Salary record i.e. Set Salary:rate = comm:rate
    Example
    Salary Table :
    ID Sal_Date Rate Hours
    1 07/01/2011 400.00 40
    2 02/15/2011 200.00 40
    3 01/01/2011 160.00 40
    Sal_comm Table:
    Sal_Date comm_Rate
    1 07/01/2011 10.00
    4 03/01/2011 7.50
    3 01/01/2011 4.00
    I need to merge comm_Rate column in Salary table, since there is no salary record as off 03/01/2011, I need to find the maximum dated salary record as of 03/01/2011
    i.e. the record dated 02/15/2011. Now I need to clone that salary record, set the SAL_date as 03/01/2011 and update Rate2 amount. So the record set will be like:
    Sal_Date:
    id sal_Date Rate Hours comm_Rate
    1 07/01/2011 400.00 40 10.00
    4 03/01/2011 200.00 40 7.50
    2 02/15/2011 200.00 40 4.00
    3 01/01/2011 160.00 40 4.00

    So you need all used dates as the "driving" dataset. And you need the according data for each of these.
    WITH salary_table as
    (select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,400 rate,40 hours from dual union all
    select 2 id,to_date('02/15/2011','MM/DD/YYYY')sal_date,200 rate,40 hours from dual union all
    select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,160 rate,40 hours from dual),
    sal_comm as
    (select 1 id,to_date('07/01/2011','MM/DD/YYYY')sal_date,10 comm_Rate from dual union all
    select 4 id,to_date('03/01/2011','MM/DD/YYYY')sal_date,7.5 comm_Rate from dual union all
    select 3 id,to_date('01/01/2011','MM/DD/YYYY')sal_date,4 comm_Rate from dual)
    select to_char(all_dates.sal_date,'MM/DD/YYYY') sal_date,sal.rate,sal.hours,com.comm_rate
    from (select sal_date from salary_table
          union
          select sal_date from sal_comm) all_dates
    inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
               from salary_table s1) sal
      on (all_dates.sal_date between sal.sal_date and sal.next_sal_date)
    inner join (select s1.*,lead(sal_date-1,1,to_date('31/12/9999','DD/MM/YYYY')) over (order by sal_date) next_sal_date
               from sal_comm s1) com
      on (all_dates.sal_date between com.sal_date and com.next_sal_date)
    order by   all_dates.sal_date desc;
    SAL_DATE   RATE                   HOURS                  COMM_RATE             
    07/01/2011 400                    40                     10                    
    03/01/2011 200                    40                     7.5                   
    02/15/2011 200                    40                     4                     
    01/01/2011 160                    40                     4                     
         

  • A filter to be applied on the F4 help in the query

    Hi
    I have a requirement wherein the user wants a filter to be applied on the F4 help in the query (for e.g. company code) for a specific area(for this e.g. real estate). Can I do this as now it brings all the company codes that exist
    Thanks
    Bhima

    Hi,
    It might be done. If your specific area is a compounding attribute to company code then restrict your area and co_code by variables (user entry). After you enter area into variable, F4 help for a co_code variable will show only codes from the entered area.
    Best regards,
    Eugene

  • Help for TSQL query

    Hi,
    I want to design query. Below are the required:
    Existing Table :
    Code   Val1   Val2   Val3
    A       A11      -         -
    B        -       B22        -
    C        -       -         C33
    Output required:  
    Code  Col1  Col2
    A       A11   B22
    B       B22   C33
    C       C33  -
    Can anyone help with the query? 

    Why don't you normalize your data?
    E.g.
    DECLARE @Sample TABLE
    Code CHAR(1) ,
    Val1 CHAR(3) ,
    Val2 CHAR(3) ,
    Val3 CHAR(3)
    INSERT INTO @Sample
    VALUES ( 'A', 'A11', NULL, NULL ),
    ( 'B', NULL, 'B22', NULL ),
    ( 'C', NULL, NULL, 'C33' );
    -- SQL Server 2012+
    WITH Normalized
    AS ( SELECT U.Code ,
    U.Attribute ,
    U.Value
    FROM @Sample S UNPIVOT ( Value FOR Attribute IN ( Val1, Val2, Val3 ) ) U
    SELECT N.Code ,
    N.Value ,
    LEAD(N.Value, 1, NULL) OVER ( ORDER BY N.Code ASC )
    FROM Normalized N;
    -- SQL Server 2008+
    WITH Normalized
    AS ( SELECT U.Code ,
    U.Attribute ,
    U.Value ,
    ROW_NUMBER() OVER ( ORDER BY U.Code ) AS RN
    FROM @Sample S UNPIVOT ( Value FOR Attribute IN ( Val1, Val2, Val3 ) ) U
    SELECT L.Code ,
    L.Value ,
    R.Value
    FROM Normalized L
    LEFT JOIN Normalized R ON L.RN = R.RN - 1;
    btw, post in future concise and complete examples. Include table DDL and sample data INSERT statements as runnable T-SQL scripts.

  • How to  Export/Import "report for the query" to another company

    Hello,
    I do this:
    1.create query in SQL analizer
    2.copy paste into SBO query generator and save
    3.create report for the query
    Then, How to Export/Import "report for the query" to another company ?
    Thanks for your HELP.

    Look for SAP Note number 600813
    That's the note Adele means, I guess.
    <b>Edit (@13:18)</b>
    The direct link:
    https://websmp101.sap-ag.de/~sapidb/012006153200000183292003E.ITF
    ---- Replace *SOURCE* with the source database name.
    ---- Replace *DEST* with the destination database name.
    insert into [*DEST*].[dbo].[RDOC]
    select [*SOURCE*].[dbo].[RDOC].*
    from
    [*SOURCE*].[dbo].[RDOC],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf]
    where [*DEST*].[dbo].[cinf].[lawsset]=[*SOURCE*].[dbo].[cinf].[lawsset]and [*DEST*].[dbo].[cinf].[version]=[*SOURCE*].[dbo].[cinf].[version] and [*SOURCE*].[dbo].[RDOC].[Doccode]NOT IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    insert into [*DEST*].[dbo].[RITM]
    select [*SOURCE*].[dbo].[RITM].*
    from [*SOURCE*].[dbo].[RITM],[*DEST*].[dbo].[cinf],[*SOURCE*].[dbo].[cinf] where [*SOURCE*].[dbo].[RITM].[Doccode] NOT IN (select Doccode from [*DEST*].[dbo].[RITM])AND [*SOURCE*].[dbo].[RITM].[Doccode]IN (SELECT Doccode from [*DEST*].[dbo].[RDOC])
    Hope it helps...
    Grtz, Rowdy

  • Infoobject F4 help in the Query takes lot of time and hangs

    Hi All,
    I have 0Material in the query and the F4 help  for selection takes lot of time and hangs after some time.
    The 0Material has 2 million records the  Infoobject properties for Bex are as below:
    Selection:No selection restriction
    Query Def. Filter Value Selection: Values in Master Data Table
    Query Execution Filter Val.Selectn:Only Posted Values for Navigation
    We tried to alter some of the Properties but we have the same issue.
    Suggest other options that can be be looked into to get the F4 help in the Query .
    Thanks,
    Mike

    hi Mike,
    check if helps
    Note 817335 - Performance in F4 Help 
    Note 748623 - Input help (F4) has a very long runtime - recommendations
    Note 581802 - Variable dialog boxes: performance of the F4 help
    search oss note for f4 performance ......

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • F4 help for the batch field in VL02N transaction

    We have upgraded our system from 4.6 to ecc 6.0 .In 4.6 the f4 help for the batch had " Batch selection via plant/Material/Storage location/Batch " which is not there in ECC 6.0.
    Please tell us the procedure to add in the existing  search help H_MCHA in ECC 6.0
    Thanks
    Aruna

    Hi Aruna.
      Create ur own search help using se11 tcode for required fields.
      Thanks & Regards,
    Kiran.
    Plz give rewards if and only if it is helpfull.

  • F4 help for the field requisitioner in ME51n

    hi friends,
    i got a requirement to give F4 help for the filed  requisitioner in Me51N which will be in item level .
    can any one give me the exit, badi, enhancement-point for this.
    thanks and regards,
    venkat.

    not answered

  • F4 HELP  for the field

    HI all,
    in the report selection screen i have one field for which F4 HELP  doesnt exits, even in the table for that field F4 HELP is not there but the user requests me to get the F4 HELP for that field in the selection screen .
    please help how to get F4 HELP  for the field
    thanks in advance.

    The following are the options for F4 help
    Code:
    PARAMETERS: p_ccgrp LIKE rkpln-ksgru. "Cost Center Group
    *Input help for Cost Center Group
    AT SELECTION-SCREEN ON VALUE-REQUEST   FOR p_ccgrp.
    TYPES: BEGIN OF ty_ccenter_group,
    setname TYPE setnamenew,
    descript TYPE settext,
    END OF ty_ccenter_group.
    DATA: it_ccenter_group TYPE TABLE OF ty_ccenter_group.
    CLEAR it_ccenter_group.
    SELECT a~setname
    b~descript
    INTO TABLE it_ccenter_group
    FROM setheader AS a INNER JOIN
    setheadert AS b ON
    asubclass EQ bsubclass AND
    asetname EQ bsetname
    WHERE a~setclass EQ '0101' AND
    b~langu EQ sy-langu.
    CALL FUNCTION 
    'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    ret field        =  'SETNAME'
    dynpprog     =  v_repid
    dynpnr         =    SY-DYNR
    dynprofield = 'P_CCGRP'
    value_org    = 'S'
    TABLES
    value_tab   = it_ccenter_group.
    F4IF_FIELD_VALUE_REQUEST:
    This FM is used to display value help or input from ABAP dictionary. We have to pass the name of the structure or table (TABNAME) along with the field name (FIELDNAME). The selection can be returned to the specified screen field if three
    parameters DYNPNR, DYNPPROG, DYNPROFIELD are also specified or to a table if RETRN_TAB is specified.
    CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
    TABNAME = table/structure
    FIELDNAME = 'field name'
    DYNPPROG = SY-CPROG
    DYNPNR = SY-DYNR
    DYNPROFIELD = 'screen field'
    IMPORTING
    RETURN_TAB = table of type DYNPREAD
    Getting F4 help based on other  field  .
    Suppose  if there  are  2 fields on selection screen  user name and Purchasing Document  and  the case is getting values of  Purchasing Document Number  based on  user name
    Code:
    TYPES:   BEGIN OF ty_match_nast,
                    objky TYPE na_objkey,
                    END OF ty_match_nast.
    Data: it_match_nast   TYPE STANDARD TABLE OF ty_match_nast.
    Data: it_dypr_val   TYPE STANDARD TABLE OF dynpread.
    DATA: wa_dypr_val  TYPE dynpread.
    DATA: it_return TYPE STANDARD TABLE OF ddshretval.
    Case when only username value is entered.
           SELECT objky
            FROM   nast
            INTO  TABLE it_match_nast
             WHERE kappl  = c_ef
             AND   kschl = c_neu
             AND   usnam = wa_dypr_val-fieldvalue.
          ENDIF.
    *Read User name  on  selection screen field value
      CLEAR wa_dypr_val.
      REFRESH it_dypr_val.
      wa_dypr_val-fieldname = 'P_UNAME'.      "User name
      APPEND wa_dypr_val TO it_dypr_val.
    *FM to get the value
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname             = sy-repid
          dynumb             = sy-dynnr
          translate_to_upper = 'X'
        TABLES
          dynpfields         = it_dypr_val_h.
    *Pass the values to f4 table
       CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield     = u2018OBJKY'
            dynpprog    = sy-repid
            dynpnr      = sy-dynnr
            dynprofield = 'P_EBELN'
            value_org   = 'P'
         TABLES
            value_tab   = it_match_nast
            return_tab  = it_return.

Maybe you are looking for