Query help for count

Hi Experts,
I have a table like:
Id item1 item2
1 a b
2 x b
3 b a
4 x a
i need take count exact item1,item2 combination should be (a,b) or (b,a).
Is there any way to get the combinations counts.
Regs,
H

with xx as
(select 1 id,'a' item1,'b' item2 from dual union all
select 2 id,'x' item1,'b' item2 from dual union all
select 3 id,'b' item1,'a' item2 from dual union all
select 4 id,'x' item1,'a' item2 from dual union all
select 5 id,'x' item1,'b' item2 from dual union all
select 6 id,'a' item1,'b' item2 from dual union all
select 7 id,'b' item1,'a' item2 from dual
select count(*)  from xx
where (item1 = 'a' and item2 ='b') OR (item1 = 'b' and item2 ='a');

Similar Messages

  • Query rewrite for COUNT(DISTINCT)

    Hi,
    I am having fact table with different dimension keys.
    CREATE TABLE FACT
    TIME_SKEY NUMBER
    REGION_SKEY NUMBER,
    AC_SKEY NUMBER
    I need to take COUNT(DISTINCT(AC_SKEY) for TIME_SKEY and REGION_SKEY. There are oracle dimension defined for time and region which are using TIME_SKEY and REGION_SKEY. I have created MV with query rewrite with COUNT(DISTINCT) but it is not using dimension if I am using any other level and MV can't be fast refreshed as it was build using COUNT(DISTINCT).
    CREATE MATERIALIZED VIEW AC_MV
    NOCACHE
    NOLOGGING
    NOCOMPRESS
    NOPARALLEL
    BUILD IMMEDIATE
    REFRESH COMPLETE ON DEMAND
    WITH PRIMARY KEY
    ENABLE QUERY REWRITE
    AS
    SELECT
    TIME_SKEY ,
    REGION_SKEY,
    COUNT (DISTINCTAC_SKEY)
    FROM FACT
    GROUP BY TIME_SKEY, REGION_SKEY;
    Query used to retrieve data is as below
    SELECT TIME_SKEY, COUNT(DISTINCT AC_SKEY) OVER (PARTITION BY TIME_SKEY) UNIQ_AC, COUNT(DISTINCT AC_SKEY) OVER () UNIQ_AC1
    FROM FACT;
    There can be other queries based on time / region dimension.
    Can you please provide help in solving above issue?
    Thanks,
    Pritesh

    What version of the Oracle database?

  • SQ01 Query Help for (MKPF and MSEG)

    Is their anyway to have the field MSEG-ERFMG show up on the query results as postive or negative color or use a "-" or "+".  Need to try and show whether is was a negative or postive movement.

    F1 help for MSEG-SHKZG
    Debit/credit indicator in revaluation
    This indicator is used for internal program control.
    Please do not change the entry in this field.
    Any changes made could lead to program errors or terminations.
    I guess the "sign" is defined trough this field ("S" - sollen (debit), "H" - haben (credit)). If my assumption is true, you won't be able to see + / - in MSEG-ERFMG simply because this field contains no information on the sign.
    Using ABAP code you can solve it (or in SQ01 you can use calculated field in your query...I'm not sure you can define that calculated field to cover your requirement...).
    Regards,
    Csaba
    Edited by: Csaba Szommer on May 12, 2009 11:20 PM

  • Query Help for Running Count

    hi i have table with data like below
    CREATE TABLE Table1
    ID int
    ,GroupID int
    insert into Table1 values(1,1)
    insert into Table1 values(2,2)
    insert into Table1 values(3,2)
    insert into Table1 values(4,1)
    insert into Table1 values(5,1)
    insert into Table1 values(6,3)
    insert into Table1 values(7,3)
    insert into Table1 values(7,3)
    insert into Table1 values(8,2)
    insert into Table1 values(9,4)
    insert into Table1 values(10,5)
    Here i need the out put with GroupID and the count. The expected output like below
    GroupID
    Count
    1
    1
    2
    2
    1
    1
    3
    3
    2
    1
    4
    1
                 5              1  
    I think you got my scenario. For each groupID i need to put the count but with adjusents same GroupID

    Hi Akhil,
    It looks like your expected is wrong, Try the below:
    CREATE TABLE Table1
    ID int
    ,GroupID int
    insert into Table1 values(1,1)
    insert into Table1 values(2,2)
    insert into Table1 values(3,2)
    insert into Table1 values(4,1)
    insert into Table1 values(5,1)
    insert into Table1 values(6,3)
    insert into Table1 values(7,3)
    insert into Table1 values(7,3)
    insert into Table1 values(8,2)
    insert into Table1 values(9,4)
    insert into Table1 values(10,5)
    ;WITH FirstCte AS (
    SELECT GroupID,id,
    ROW_NUMBER() OVER(ORDER BY id) AS rnComplete,
    ROW_NUMBER() OVER(PARTITION BY GroupID ORDER BY id) AS rnGroupID
    FROM Table1)
    , SecondCte AS (
    SELECT id,GroupID, count(GroupID) Over(partition by GroupID, rnComplete - rnGroupID) as GroupCnt
    FROM FirstCte )
    SELECT m.GroupID, GroupCnt
    FROM SecondCte AS m
    GROUP BY m.GroupID, GroupCnt
    Order by MAX(m.ID)
    Drop table Table1
    GroupID
    Count
    1
    1
    2
    2
    1
    2
    3
    3
    2
    1
    4
    1
                 5              1 

  • Query help for sales employee sales

    Hi....
    How can we have a query for
    Name of sales employee
    Item group
    Item name
    Total selling amount
    Total sales order
    Total delivery
    Total AR invoice
    Please help
    Thanks a lot

    Hi,
    What Total selling amount do you need? Invoice - Credit Memo?
    How about the other Total, total count or total amount?
    Thanks,
    Gordon

  • ABAP Query Code for Count Function

    Hi,
    I have an ABAP Query and just created a new field which requires ABAP Code to do the following :-
    The report is for Purchase Orders and Purchase Requisitions. 2 Purchase Orders may have the same requisition, so what I want to do is count the number of the same requisitions in the report
    e.g.
    PO                Req             Count
    45000001     10015              2
    45000020     10015              2
    Can some one please provide with the full code? Points will be awarded
    Thanks

    Hi,
    No errors in the below code but it is bringing a value 0 even though there are duplicates in the table which is suggesting to me that the code is not working.
    Any help would be appreciated. Thanks
    DATA : BEGIN OF itab OCCURS 0,
            aufnr LIKE ekkn-aufnr,
           END OF itab.
    DATA : count(2) TYPE p.
    DATA : no_of_records(3) TYPE p.
    Clear no_of_records.
    select aufnr from ekkn into itab.
    endselect.
    SORT itab BY aufnr.
    LOOP AT itab.
      ADD 1 TO count.
      AT END OF aufnr.
        IF count GE 2.
          ADD count TO no_of_records.
        ENDIF.
        CLEAR count.
      ENDAT.
    ENDLOOP.
    *WRITE :/ 'Good Bye'.
    DUPLICATES = NO_of_records.

  • Query Help for reporting on last receipt qty

    SBO Version: 8.82 PL11
    Hello Forum,
    I am looking for some help devising a command behind a crystal report. We are hoping to achieve the last receipt quantity. To arrive at this we would like it to get the last GRPO for an item and total the quantity on that particular GRPO. In addition to this, we want to consider all the lines on the document and SUM them.
    At present, the query I have is as follows:
    Select SUM(c0.Quantity) from PDN1 c0 WHERE c0.ItemCode = T1.ItemCode AND Shipdate = (select Max(ShipDate) from PDN1 C0  INNER JOIN OPDN c1 ON c0.DocEntry = c1.DocEntry where C0.Itemcode =T1.ItemCode AND c1.DocStatus <> 'C'))
    Any assistance would be greatly received.
    Thanks
    Sarah

    Hi Sarah,
    Please repost to the SAP Business One Application  space.
    -Abhilash

  • Select query help for Sales order

    Hi Experts,
    I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
    Any help is appreciated. Expecting code samples....Thanks
    Thanks
    Ricky

    hi,
    do like this,
    write a select query for vbak and vbuk as follows.
    delivery status field is <b>lfstk</b> from <b>vbuk</b>,
    and relation field is <b>vbeln</b> from the both the tables.
    reward points if useful,
    regards,
    seshu.

  • Query help for archive log generation details

    Hi All,
    Do you have a query to know the archive log generation details for today.
    Best regards,
    Rafi.

    Dear user13311731,
    You may use below query and i hope you will find it helpful;
    SELECT * FROM (
    SELECT * FROM (
    SELECT   TO_CHAR(FIRST_TIME, 'DD/MM') AS "DAY"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '00', 1, 0)), '999') "00:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '01', 1, 0)), '999') "01:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '02', 1, 0)), '999') "02:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '03', 1, 0)), '999') "03:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '04', 1, 0)), '999') "04:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '05', 1, 0)), '999') "05:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '06', 1, 0)), '999') "06:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '07', 1, 0)), '999') "07:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '08', 1, 0)), '999') "08:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '09', 1, 0)), '999') "09:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '10', 1, 0)), '999') "10:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '11', 1, 0)), '999') "11:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '12', 1, 0)), '999') "12:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '13', 1, 0)), '999') "13:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '14', 1, 0)), '999') "14:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '15', 1, 0)), '999') "15:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '16', 1, 0)), '999') "16:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '17', 1, 0)), '999') "17:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '18', 1, 0)), '999') "18:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '19', 1, 0)), '999') "19:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '20', 1, 0)), '999') "20:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '21', 1, 0)), '999') "21:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '22', 1, 0)), '999') "22:00"
           , TO_NUMBER(SUM(DECODE(TO_CHAR(FIRST_TIME, 'HH24'), '23', 1, 0)), '999') "23:00"
        FROM V$LOG_HISTORY
        WHERE extract(year FROM FIRST_TIME) = extract(year FROM sysdate)
    GROUP BY TO_CHAR(FIRST_TIME, 'DD/MM')
    ) ORDER BY TO_DATE(extract(year FROM sysdate) || DAY, 'YYYY DD/MM') DESC
    ) WHERE ROWNUM < 8;Hope That Helps.
    Ogan

  • Query help for where condition

    Hi ,
    I have String value in table now I require to check that value is valid or not .
    I have below Query .
    SELECT *
    FROM Table TCI
    WHERE (ISDATE(SUBSTRING(SUBSTRING(Data,82,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,82,6),5,2)+'-'+'01')<>1 OR LEN(LTRIM(RTRIM(SUBSTRING(Data,82,6)))) < 0 OR SUBSTRING(Data,82,6)='000000')
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,88,6)))) < 0 OR SUBSTRING(Data,88,6)= '000000' OR ISDATE(SUBSTRING(SUBSTRING(Data,88,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,88,6),5,2)+'-'+'01')<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,173,6)))) < 0 OR ISDATE(SUBSTRING(SUBSTRING(Data,173,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,173,6),5,2)+'-'+'01')<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,195,6)))) < 0 OR ISDATE(SUBSTRING(SUBSTRING(Data,195,6),1,4)+'-'+SUBSTRING(SUBSTRING(Data,195,6),5,2)+'-'+'01') <>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,217,7))))<0 OR ISNUMERIC(LTRIM(RTRIM(SUBSTRING(Data,217,7)))) <> 1)
    AND ISNUMERIC(REPLACE(SUBSTRING(Data,334,10),'-','0'))<>1
    AND ISNUMERIC(SUBSTRING(Data,345,10))<>1
    AND ISNUMERIC( SUBSTRING(Data,355,10))<>1
    AND ISNUMERIC(SUBSTRING(Data,416,8))<>1
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,104,6))))<0 OR ISNUMERIC(SUBSTRING(Data,104,6))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,145,7))))<0 OR ISNUMERIC(SUBSTRING(Data,145,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,152,7))))<0 OR ISNUMERIC(SUBSTRING(Data,152,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,159,7))))<0 OR ISNUMERIC(SUBSTRING(Data,159,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,166,7))))<0 OR ISNUMERIC(SUBSTRING(Data,166,7))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,179,3))))<0 OR ISNUMERIC(SUBSTRING(Data,179,3))<>1)
    AND (LEN(LTRIM(RTRIM(SUBSTRING(Data,201,3))))<0 OR ISNUMERIC(SUBSTRING(Data,201,3))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,365,10),'-','0'))<>1 OR ISNUMERIC( REPLACE(SUBSTRING(Data,365,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,375,10),'-','0'))<>1 OR ISNUMERIC( REPLACE(SUBSTRING(Data,375,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,385,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,385,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,395,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,395,10),'-','0'))<>1)
    AND (ISNUMERIC(REPLACE(SUBSTRING(Data,405,10),'-','0'))<>1 OR ISNUMERIC(REPLACE(SUBSTRING(Data,405,10),'-','0'))<>1)
    I need only invalid record set from below Query ;
    like; If it is not isdate and is_numeric type for particular row then it return only that row.
    currently i'm facing issue like whole string is invalid in that case it gives row .
    should I use case statement in where clause ?
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

    I need only invalid record set from below Query ;
    like; If it is not isdate and is_numeric type for particular row then it return only that row.
    currently i'm facing issue like whole string is invalid in that case it gives row .
    should I use case statement in where clause ?
    Hi PrajapatiNeha,
    Your requirement is confusing. Judging from the query, the column data
    seems to be a string which consists of fixed length date or numberic format substrings, so you are verifying each substring is valid and need to select the invalid substrings?
    If that is your requirement, why not just extract the substrings into a derived table and filter based on the derived table?  The substrings in the derived table will give a more directly overview of your long data string.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Query Help for SO Alert

    Dear Experts,
    I have a scenario where our user would like to be reminded of action items pertaining to a specific BP when entering a new SO.
    I have the following query but would like it to alert only once.  What syntax do I need to configure for this query to send an internal alert once within a few minutes of adding?
    SELECT T0.[DocNum], T0.[DocDate], T0.[CardCode], T0.[CardName], 'Reminder: <<Insert Reminder Here>>.' as "Important Message"
    FROM ORDR T0
    WHERE T0.[CardCode] IN ('ABC01')
    Thanks,
    Richard

    Hi
    You may create an alert by:
    SELECT T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName, 'Reminder: <<Insert Reminder Here>>.' as "Important Message"
    FROM ORDR T0
    WHERE T0.CardCode IN ('ABC01') AND DateDiff(D,T0.DocDate,GetDate())=0
    However, there is no switch to turn it off.
    Thanks,
    Gordon

  • Need help for Count function in XSLT Mapping

    Hi All,
    We have a requirement in our project,to do the xslt mapping from OAGIS 9.0 to EDI XML.In the EDI XML we have a SE tag whose value is the count of the no. of complex elements that will be generated in the EDIXML file( which is the target).
    Please do let me know if anybody has done this functionality in the xslt mapping.
    Thanks in Advance.
    Regards,
    Kaavya

    Hi,
    for the Hex-Number-conversion see:
    [url http://psoug.org/snippet/Convert-Hex-to-Decimal-Decimal-to-Hex_78.htm] self-defined Conversion-Functions
    What number format do you have? YYYMMDD
    Or is there a Date corresponding to 1 and a number n represent the date n-1 days after day 1?
    Please describe further.
    Bye
    stratmo

  • SQL query/report for "count of specific file type"?

    I figured this would be a good first post, as I have found every question I have had to date by browsing the forums, but I am stumped with this one. I recently expressed some concern to HR regarding the use of...lets call it "unauthorized content"
    on our network. Getting little to no response, I would like to produce a report containing a total count based on specific file type. For example, how many .mp3 files are stored on company equipment, how many torrent files (sadly, this is true), etc.
    Having very basic knowledge of SQL, I am puzzled where to start. I am currently using SCCM SP3 and SQL 2008 R2 with both basic reporting and SSRS enabled on the site.

    You'll first need to inventory those file types then here's some reports for you.
    Get the pstreports from my skydrive, import them and you can cange the file type to mp3 or whatever you need. I monitor mp3 files too.
    http://cid-6a8d30f2bc0666d0.office.live.com/browse.aspx/SCCM%20Custom%20Reports
    John Marcum | http://myitforum.com/cs2/blogs/jmarcum/|

  • Query Help (For Election Purpose)

    Hello,
    Oracle Version: 10G
    OS: Windows XP SP-3
    create table election (areacode number(2),boothno number(3),Smith number(4),John number(4),tot number(5));
    insert into election values (1,1, 5,2,7);
    insert into election values (1,2,10,0,10);
    insert into election values (2,9,1,2,3);
    insert into election values (2,6,8,1,9);
    required output:
    Candidate   Area1      Area2     Tot
    Smith        15          9        24  << 15=5+10 i.e. Sum of Smith for areacode=1, 9=1+8 i.e. Sum of Smith for areacode=2
    John          2          3         5  << 2=2+0 i.e. Sum of John for areacode=1, 3=2+1 i.e. Sum of John for areacode=2
    Total        17         12        29Thanks & Regards
    Girish Sharma

    Salim,
    First off, i wish to thanks for your working query. Now if i wish to get following output then ?
    Candidate  Area1     Tot
    Smith        15       15  << 15 Sum of Smith for areacode=1
    John          9        9  << 2=2+0 i.e. Sum of John for areacode=1
    Total        24       24
    Candidate  Area1     Tot
    Smith        15       15  << 15 Sum of Smith for areacode=1
    John          9        9  << 9 Sum of John for areacode=1
    Candidate  Area1
    Smith        15
    John          9
    Candidate  Area1     Tot
    John          9        9  << 9 Sum of John for areacode=1
    Total         9        9
    Candidate  Area1     Tot
    John          9        9  << 2=2+0 i.e. Sum of John for areacode=1means, if there are difference in rows and columns by above query please; means there may be more candidates in an area and/or more/less number of areas in comparision of number of candidates.
    Once again thanks for giving learning and working query....!!!
    Thanks & Regards
    Girish Sharma
    Edited by: Girish Sharma on May 17, 2009 11:25 PM
    Rechecked the output

  • SOS, Urgent help for Count function

    Hi I need to count to different value on a same column
    SELECT DISTINCT A.job, COUNT(*),
    FROM STDNT_EMPLOYEE A, DATA B,
    WHERE A.EMPLID = B.EMPLID
    AND A.CAREER = B.CAREER
    AND A.YEAR = '2008'
    AND D.SEX = 'M'
    and D.SEX = 'F'// This is the line on question
         GROUP BY A.JOB
    output should be
    JOB     Male Female
    receptionist 10 20
    mechanic 4 0
    bookkeeper 3 6
    Any suggestions?
    Thank you

    missed out the group by function, incase
    SELECT DISTINCT A.job, sum(decode(d.sex,'M',1,0)) male,sum(decode(d.sex,'F',1,0)) female
    FROM STDNT_EMPLOYEE A, DATA B,
    WHERE A.EMPLID = B.EMPLID
    AND A.CAREER = B.CAREER
    AND A.YEAR = '2008'
    group by a.job,d.sex

Maybe you are looking for

  • Af:panelHeader appearance like in af:panelBox

    Is it possible to let the header of an af:panelHeader appeare like the header of an af:panelBox component? This means that the upper corners should look rounded and the header line should have a colored ramp. I found out, if af:panelHeader components

  • Safari 4 constant writing to disk

    I have just put safari 4 on an iBookG4 with tiger.11 and 700 odd mb ram. If I leave the computer for a few minutes with safari running (not necessarily even a window open), I can hear constant and rhythmic writing to the disk. I check activity monito

  • HT201210 Ipod 2nd Generation Update Issue

    I can't get my Ipod 2nd gen to update or restore from 4.2.1. How can I get the Ipod to update?

  • Need link for official oracle clusterware & RAC installaiton on sol10 SPARC

    Hi Forum, I have been trying out all types of possible combination of installations for oracle clusterware and RAC on solaris 10 SPARC system. But as every document is not exact in all the steps so i have not succeeded at all. It would be nice if any

  • Which Roxio to use, ...... crunch, popcorn, toast?

    HI, I have several non-portected DVDs with misclanious content (e.g.training). Most DVDs are with two folder AUDIO_TS and VIDEO_TS. What I need is to convert them to a format that i could export to two places: 1) .mac account so i could save them/bac