Need to get total count of a column in the given query

Hi,
I have the following query for which i need a total count of distinct concatenated_address. I am trying to use count(distinct adv.concatenated_address) in the below query but because of the group by it does not give me the expected result.
I am not reusing the same query, in my program again, to get the count as it would affect the performance. This query takes really long to execute and so is there a way to incorporate the count in this single query itself without having to use it twice.
SELECT DISTINCT (acv.customer_name||','||
acv.customer_number||','||
REPLACE(adv.concatenated_address, ',', ' ')||','||
adv.postal_code||','||
rct.interface_header_attribute1||','||
rct.interface_header_attribute6||','||
rct.creation_date||','||
rct.trx_date||','||
aps.due_date ||','||
SUM(aps.amount_due_original)||','||
SUM(aps.amount_due_remaining) ||','||
rct.printing_count ||','||
TO_DATE(rct.printing_last_printed)||','||
TO_DATE(rct.printing_original_date)||',') str
,acv.customer_id
,REPLACE(adv.concatenated_address, ',', ' ') address
FROM ar_customers_v acv
,ar_addresses_v adv
,hz_cust_site_uses hcsu
,ra_customer_trx rct
,ar_payment_schedules aps
WHERE adv.customer_id = acv.customer_id
AND hcsu.cust_acct_site_id = adv.address_id
AND hcsu.site_use_code = 'BILL_TO'
AND rct.bill_to_customer_id = acv.customer_id
AND rct.bill_to_site_use_id = hcsu.site_use_id
AND aps.customer_trx_id = rct.customer_trx_id
GROUP BY acv.customer_name
,acv.customer_number
,adv.concatenated_address
,adv.postal_code
,rct.interface_header_attribute1
,rct.interface_header_attribute6
,rct.creation_date
,rct.trx_date
,aps.due_date
,rct.printing_count
,TO_DATE(rct.printing_last_printed)
,TO_DATE(rct.printing_original_date)
     ,acv.customer_id
ORDER BY acv.customer_id
,REPLACE(adv.concatenated_address, ',', ' ')
Thank you

try this please
SELECT COUNT(str),customer_id
FROM
(SELECT DISTINCT (acv.customer_name||','||
acv.customer_number||','||
REPLACE(adv.concatenated_address, ',', ' ')||','||
adv.postal_code||','||
rct.interface_header_attribute1||','||
rct.interface_header_attribute6||','||
rct.creation_date||','||
RCT.TRX_DATE||','||
aps.due_date ||','|| 
SUM(aps.amount_due_original)||','||
SUM(aps.amount_due_remaining) ||','||
rct.printing_count ||','||
TO_DATE(rct.printing_last_printed)||','||
TO_DATE(rct.printing_original_date)||',') str
,acv.customer_id
,REPLACE(adv.concatenated_address, ',', ' ') address
FROM ar_customers_v acv
,ar_addresses_v adv
,hz_cust_site_uses hcsu
,ra_customer_trx rct
,ar_payment_schedules aps
WHERE adv.customer_id = acv.customer_id
AND hcsu.cust_acct_site_id = adv.address_id
AND hcsu.site_use_code = 'BILL_TO'
AND rct.bill_to_customer_id = acv.customer_id
AND rct.bill_to_site_use_id = hcsu.site_use_id
AND aps.customer_trx_id = rct.customer_trx_id
GROUP BY acv.customer_name
,acv.customer_number
,adv.concatenated_address
,adv.postal_code
,rct.interface_header_attribute1
,rct.interface_header_attribute6
,rct.creation_date
,rct.trx_date
,aps.due_date
,rct.printing_count
,TO_DATE(rct.printing_last_printed)
,TO_DATE(RCT.PRINTING_ORIGINAL_DATE)
,ACV.CUSTOMER_ID)

Similar Messages

  • How to use a calculated column in the same query

    Hi All,
    I need some help with using a calculated column in the same query.
    For eq
    I am joining a couple of tables and some of the select columns are calculated based on the columns of the tables and i want a new column in the same query to use this calculated feild in some other calcualtion.
    something like this...
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    Thanks

    user548171 wrote:
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    ThanksWhat about just repeating the column values:
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( (12+3) / (12-3)  * 100  > 0 )  THEN 'Yes' ELSE 'No'  END FROM DUAL

  • My hard drive crashed on my MacBook Pro crashed and I need to get my CS5 up and running on the new hard drive. I copied what I could onto an external hard drive but when I drag and drop I get directions to uninstall but the uninstall folder I have does sa

    my hard drive crashed on my MacBook Pro crashed and I need to get my CS5 up and running on the new hard drive. I copied what I could onto an external hard drive but when I drag and drop I get directions to uninstall but the uninstall folder I have does says it is an alias that is no longer present. I get error 6. I would like to get my software up and running on the laptop again please

    If you subscribed to iTunes match the songs are kept in icloud. If you didn't but you did save the actual iTunes library folder which should include the music, video, etc.  you should be able to just drag this file back to your machine in the same place and when you open iTunes it will give you a chance to identify the iTunes library folder. 
    You can test this to find out if you saved the media files or not and don't need to attach your nano to do it. 
    You are correct that once you connect the nano it will clear the existing files from it and sync it with the new iTunes library. 
    If you don't have the media files i'm not sure if/how to get them back on a windows ipod.  I have everything backed up regularly because of the horror stories I have seen & heard.

  • Knowing the primary key columns of the given table

    Hi,
    How can I get the primary key columns of the given table?
    Regards,
    Sachin R.K.

    You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
    And then see which columns are in for the constriant_name
    in all_cons_columns/user_cons_columns view.
    Below is the example
    select acc.column_name from
    all_cons_columns acc, all_constraints ac
    where acc.constraint_name = ac.constraint_name
    and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
    and ac.constraint_type = 'P'
    Hope this helps
    Srinivasa Medam

  • Rows to columns/Transpose the records Query and Display output

    hi ,
    can anyone help me query this and transpose it to this format?
    i am still a beginner in sql.
    thanks for help!
    Rows to columns/Transpose the records Query and Display output
    id     startdate     endate                    
    1111     1/2/2001     11/3/2001                    
    1111     2/5/2002     4/3/2002                    
    1111     2/6/2000     2/5/2001                    
    3333     5/2/2003     11/3/2003                    
    3333     6/2/2003     12/3/2003                    
    3333     2/6/2005     2/5/2005                    
    desired output     
    id     startdate1     endate1     startdate2     endate2     startdate3     endate3
    1111     1/2/2001     11/3/2001     2/5/2002     4/3/2002     2/6/2000     2/5/2001
    3333     5/2/2003     11/3/2003     6/2/2003     12/3/2003     2/6/2005     2/5/2005

    Have you only 3 dates for each id ?
    So, try :
    SQL> l
      1  with tbl as
      2  (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
      3  select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
      4  select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
      5  select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
      6  select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
      7  select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
      8  select id, max(decode(dr,1,startdate)) start1,
      9             max(decode(dr,1,enddate)) end1,
    10             max(decode(dr,2,startdate)) start2,
    11             max(decode(dr,2,enddate)) end2,
    12             max(decode(dr,3,startdate)) start3,
    13             max(decode(dr,3,enddate)) end3
    14  from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
    15* group by id
    SQL> /
                                                    ID START1   END1     START2   END2     START3   END3
                                                  1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
                                                  3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
    SQL> HTH,
    Nicolas.

  • Getting total count instead particular count

    Hi all,
    Need out put in the report , i made relation (link) b/w customer_id's
    customer_id:1234
    customer name:Vision Tech
    order no order_name Cost
    1000        ABC        1000
    1001      CCC          2000
    Total Order: 2      Total Cost: 3000
    customer_id:1000
    customer name:Tech
    order no order_name  Cost
    400         DDD           300
    4001       EEE           400
    Total Order: 2     Total Cost: 700
    But getting Total Order: 4     Total Cost: 3700 for both

    Hi,
    I need the as below out put
    Suppose
    deptno 10
    dname ABC
    empno ename sal deptno
    100     aaa     100  10
    101     bbb      100 10
    Total Eployees: 2   Total Sal: 200
    deptno 20
    dname ABC
    empno ename sal deptno
    110     ccc  100  20
    121     ddd  100 20
    161     eee  100 20
    Total Eployees: 3   Total Sal: 300
    But i am getting as below
    deptno 10
    dname ABC
    empno ename sal deptno
    100     aaa     100  10
    101     bbb      100 10
    Total Eployees: 4   Total Sal: 500
    deptno 20
    dname ABC
    empno ename sal deptno
    110     ccc  100  20
    121     ddd  100 20
    161     eee  100 20
    Total Eployees: 4   Total Sal: 500
    I am creating Summry columns for "Total Employees" and "Total Sal"
    Total Employees
    Function:Count
    Source: Empno
    Reset At:Report
    Total Sal
    Function:SUM
    Source:SAL
    Reset At:Report

  • Query to get total counts in the given scenario

    Hi,
    I am using Oracle 10g
    I have a table A with following data
    AgId     Trm     CD     S
    1000     100010     12-JAN     A
    1000     100019     20-MAR     A
    1000     100019     20-JUL     D
    1001     100011     25-JAN     A
    1001     100011     20-FEB     D
    1001     100011     23-MAR     A
    1001     100012     31-JAN     A
    1002     100013     14-FEB     A
    1002     100013     05-APR     D
    1002     100015     02-MAY     A
    1003     100014     03-MAR     A
    1003     100014     25-MAR     D
    1004     100016     22-MAY     A
    1004     100017     21-JUN     A
    1004     100018     01-JUL     A
    1005     100020     21-MAY     D
    1005     100020     21-JUL     A
    1005     100020     11-AUG     D
    Here the overall status of AgId '1000' is A as he is having atleast 1 Trm active
    Similarly, status of AgId '1001' is A
    status of AgId '1002' is A
    But,status of AgId '1003' is D as his trm is disconnected after activation(according to date column'CD')
    Then, status of AgId '1004' is A
    and finally status of AgId '1005' is D again as his trm deactivated, activated and deactivated at last
    So, considering these criteria can any one give me a query to get total no of AgId's who are 'Active' and similarly for 'Deactive'

    Hi,
    when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    CREATE TABLE ... etc.
    {noformat}{noformat}
    Also do not forget to put correct statements. Your insert were missing semicolon at the end.
    Coming back to your problem, I assum that the current status of any trm is the latest status so I have done what follows:
    {code:sql}
    SELECT agid
         , trm
         , cd
         , s
         , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
         , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
    FROM a
    ORDER BY agid, trm, cd;
    Output:
          AGID        TRM CD        S         RN     RN_TOT
          1000     100010 12-JAN-12 A          1          1
          1000     100019 20-MAR-12 A          1          2
          1000     100019 20-JUL-12 D          2          2
          1001     100011 25-JAN-12 A          1          3
          1001     100011 20-FEB-12 D          2          3
          1001     100011 23-MAR-12 A          3          3
          1001     100012 31-JAN-12 A          1          1
          1002     100013 14-FEB-12 A          1          2
          1002     100013 05-APR-12 D          2          2
          1002     100015 02-MAY-12 A          1          1
          1003     100014 03-MAR-12 A          1          2
          1003     100014 25-MAR-12 D          2          2
          1004     100016 22-MAY-12 A          1          1
          1004     100017 21-JUN-12 A          1          1
          1004     100018 01-JUL-12 A          1          1
          1005     100020 21-MAY-12 D          1          3
          1005     100020 21-JUL-12 A          2          3
          1005     100020 11-AUG-12 D          3          3I have used to columns rn and rn_tot to find the latest entry for a specific agid, trm
    Using the query above I have done the following:
    WITH mydata AS
       SELECT agid
            , trm
            , cd
            , s
            , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
            , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
        FROM a
    SELECT agid
         , CASE WHEN SUM (CASE s WHEN 'A' THEN 1 END) > 0 THEN 'A' ELSE 'D' END s
      FROM mydata
    WHERE rn = rn_tot
    GROUP BY agid;
    Output:
          AGID S
          1000 A
          1001 A
          1002 A
          1003 D
          1004 A
          1005 D
    {code}
    Which is listing the agid and its status if at least there is one trm with final status 'A' for that agid.
    To sum up everything you can do simply like this:
    {code:sql}
    WITH mydata AS
       SELECT agid
            , trm
            , cd
            , s
            , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
            , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
        FROM a
    totdata AS
       SELECT agid
            , CASE WHEN SUM (CASE s WHEN 'A' THEN 1 END) > 0 THEN 'A' ELSE 'D' END s
         FROM mydata
        WHERE rn = rn_tot
        GROUP BY agid
    SELECT S, COUNT(*) cnt
      FROM totdata
    GROUP BY S;
    Output:
    S        CNT
    D          2
    A          4
    {code}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Need to get sequence value in another column in oracle

    Hi ALL,
    I have sql query as below
    select header_id,order_number from oe_order_headers_all.
    and data it is displaying as
    heder_id     order_number
    111            500001
    121            500400
    I need to display  another field with some sequence value like as below
    id     heder_id     order_number
    1      111                    500001
    2      121                    500400
    so how to get sequence value in another column please help me on this.
    Thnaks

    You can just use ROWNUM Pseudocolumn
    select rownum id, header_id,order_number from oe_order_headers_all

  • Need to get different data from same column in same query

    need party_name from table hz_parties once to get bank_name & other to get branch name in the same query ,,,, how can i do that?

    thx but it's not fetching what i need as wht i need excatly is as the following
    select distinct party_name -- branch_name or bank_name
    from hz_parties hz
    , hz_code_assignments bankca
    , hz_code_assignments branchca
    where
    -- bankca.class_category = 'BANK_INSTITUTION_TYPE'
    -- AND bankca.class_code IN ('BANK', 'CLEARINGHOUSE')
    branchca.class_category = 'BANK_INSTITUTION_TYPE'
    and branchca.class_code IN ('BANK_BRANCH', 'CLEARINGHOUSE_BRANCH')
    AND branchca.owner_table_id = hz.party_id
    -- AND bankca.owner_table_id = hz.party_id
    if class_code from table x = branch then select party_name from table y & call it branch
    else if class_code from table x =bank then select party_name from table y & call it bank

  • I'm JS illiterate, need help getting an Acrobat form to work like the Excel file I made it from.

    Hi folks.
    I am tasked to put together a purchase order request form and it has to be in PDF format.
    I originally built it in Excel, and after a day and a half of googling, I finally came upon the formula(s) that make 2 of columns interact the way I want them to.
    Column A ("Line Item Number") triggers its corresponding cell in Column C ("Obligate/Deobligate") in the following way:
    If the A cell is blank, its corresponding C cell diplays "O/D"
    If the A cell has a number entered into it which is the same as any cell above it, the corresponding C cell displays "Deobligate"
    If the A cell has a number entered into it which is different than every cell above it, the corresponding C cell displays "Obligate"
    The formula I used, starting in the second C cell is:
    =IF(A2="","O/D",IF(COUNTIF(A1:A1,A2),"Deobligate","Obligate"))
    And it changes down the column ending at the 23rd C cell with:
    =IF(A23="","O/D",IF(COUNTIF(A1:A22,A23),"Deobligate","Obligate"))
    Will this even translate into Javascript?  And if it does, I assume that I would paste the script into the "Calculate" portion of the form field properties, is this correct?
    Also, (I realize I'm asking a lot), if the correct code is fast and easy for someone here to whip up, I would appreciate it, since as I said before, I really don't know the first thing about JS, or coding in general.
    Thanks in advance.

    Yes, it should be a custom calculate script. Here's a sample one below. It assumes the fields are named "A1", "A2", ..."A23". You will have to change the value of the "row" variable for each script, which is currently set to 2, meaning it should go in the A2 field. This really should be a function in a document-level JavaScript to it can be called by passing the row number or extracting it from the value of event.target.name, but it should get you started. Note that I didn't test it, so it might need some tweaking:
    // Custom Calculation script for row 2
    (function () {
        // Row number of this field
        var row = 2;
        // Get the value of the A column field
        var sVal = getField("A" + row).valueAsString;
        var sVal2;
         // Set this field value to  "O/D" if blank
        if (!sVal) {
            event.value = "O/D";
            return;
        // Scan the previous rows to see if any match this value
        for (var i = 1; i < row; i += 1) {
            // Get the current row value
            sVal2 = getField("A" + i).valueAsString;
            // See if it matches
            if (sVal2 === sVal) {
                event.value = "Deobligate";
                return;
         // No match was found. so set this field value to "Obligate"
        event.value = "Obligate";

  • Need to get data from multiple database instances in a single query

    Hi,
    I need a small favour from you guys. The prob is as follows:
    I need to get name, row_id from table A from schema 1 and gbu_name, name from table B from schema 2 where a.name = b.name. I wrote the query in the following manner:
    SELECT a.name, a.row_id, b.gbu_name
    FROM Schema1.A as a, Schema2.B as b
    Where a.name = b.name
    But this query is not working and the error is like " The table does not exists".
    Please update me how to avoid the error and get the right sort of result.
    Thanks & Regards,
    Debabrata

    Ah, youre actually asking different things.
    In your topic title, you say youre running separate instances
    In your body text, you say you are under different user/schema
    So tell me, do you have more than one database or not? How many entries in your TNS file?
    I would say, for "multiple database instances"
    SELECT
      a.id, b.id
    FROM
      tableA a
      INNER JOIN
      tableB@OTHER_DATABASE_LINK_NAME b  <--NOTE!
      USING(id)And of course you will have to look up CREATE PUBLIC DATABASE LINK sql..
    Message was edited by:
    charred

  • I need help getting my Airport Extreme to connect to the internet

    Hello everyone,
    I need some help setting up my AirPort Extreme. I'm trying to reestablish the express after a couple years of not using it. When I've set it up in the past, I've always had a hard time, and by accident it seems, I click something or turn something on and off, and I get it to work.
    I have  a 802.11g second generation airport extreme. I'm able to connect to my network and I can move files back and forth from the laptop to the desktop, and vise versa.
    I have a MacPro 2007, ethernet cable connected to my Linksys router, with two internal hard drives. One has OSX 10.5.8, AirPort Utility 5.6.1, and everything is up to date. The other has OSX 10.6.8, AirPort Utility 5.6.1. I also have a MacBookPro 2011, It came with Snow Leopard installed and I upgraded  it to OSX 10.7.4. I installed AirPort Utility 5.6.1.
    All three systems can see and connect to my network, but will not connect to the internet.  The extreme's IP starts with 169.254.xxx.xxx, and there's an exclamation point on the wi-fi icon.
    The set up I have now is a Westell DSL modem from Verizon. I have the ethernet cable from the DSL modem connected to the WAN port of the express and the other cable going from the ethernet port from the extreme to the ethernet port of my Linksys router 4 port switch, model #BEFSR41 V.3. I have reversed the connection to and from the extreme with the same result.
    This is what I've done so far with no luck:
    • Unplugged the DSL modem, Linksys router, and the extreme for about twenty minutes.
    • Updated the Linksys firmware.
    • I have reset the extreme from the back and thru the AirPort Utility many, many times.
    • I've done a hard reset. I don't know if it worked. After the extreme powered back up, my network's name and settings were still the same. On a positive note, I'm now able to get on the web when I set the connection sharing to "Distribute a range of IP addresses" using the ethernet on my desktop. Before, I was only able to do so when the connection sharing in AirPort Utility  was set to "Off (Bridge Mode)".
    Any other Ideas?
    As always, your help is always appreciated,
    Rick

    Hi Tesserax,
    Thanks for getting back to me.
    Sorry about the confusion. My goal is to get online wirelessly with my MacBook Pro and be able to use the ethernet connection for my MacPro.
    My DSL modem is a Westell WireSpeed model A90-210015-04, the Linksys router, and the AirPort Extreme.
    Rick

  • Do I need to get a different docking system to fit the Iphone 5?

    Do I need to get a different docking system for the iphone 5 than what I currently have?

    The question is, what do you currently have?  If a system for the older 30-pin dock connector, you will need a converter for the 30-pin dock to Lighning connector.  See the Apple store for the adapter.
    Such as: http://store.apple.com/us/product/MD823ZM/A/lightning-to-30-pin-adapter?fnode=3c

  • Chart not getting columns from the SQL Query with InlineTransform(xsl)

    Hi All,
    I am using MII 12.0 . I tried to use the mii standard xsl for converting rows into columns by  Inline Transform in a SQL Query.
    while executing the Query it is giving me the correct output but i tried to load the same Query in a IChart there it is not showing me the available columns that i can able to see in simple executiion and chart is also not plotting it keeps on loading.
    Thanks in Advance.

    Hi LinoVaz,
    Some things to try for testing purposes -
    1. Don't do any Data Mapping of the query columns
    2. If a SQL Query, you may need to change the Server Scaling to use Global AutoScale.
    I found that when I mapped the inline-transformed query into a bar chart display template, and hit the Refresh button, only the first column name show in the Column Names area.  If I mapped it, I got only that column.  If I didn't map any columns, I got them all.
    Let me know if you find similar results.  I think this is likely a bug, so you may consider using a Business Logic Transaction and an XacuteQuery to accomplish the same result.
    Kind Regards,
    Diana Hoppe
    Edited by: Diana Hoppe on Mar 25, 2011 11:46 AM

  • How to use a Formula Column in the main query?

    Hi All,
    I've tried to use a formula columns defined in some query in the condition of that query like this:
    where (:cf_ex - :cf_ex2) >= 5
    but when I run the report no data returned! Why? and how to use it the condition of the query?
    Note: I'm using Forms 6i

    where (:cf_ex - :cf_ex2) >= 5You cannot do that. Formula columns are not part of the select statement (which runs in the database), but are processed in the report.
    When you created this query, my guess is that you got the message "Note: the query Q1 has created the bind parameter(s) cf_ex, cf_ex2". Check these User Parameters in your data model. So, you are actually referencing user parameters in the query, not formula columns.
    I made a computations and things using PL/SQL that can't be done in the select statement in the data model!If it's pl/sql you can probably use that in your query. Create some database functions for cf_ex and cf_ex2 and use these in your query.

Maybe you are looking for