Query of mixed sort

I have written the below query asking for a list of customer's names and YTD Charter Costs for the customers whose YTD Charter Cost are greater than the average charter cost for all customers. I keep getting an error " Oracle>@U7Q3
Enter the four digit year:2008
(SELECT avg(sum(charter.char_distance * model.mod_chg_mile)*1.35,'$99,999.99'))
ERROR at line 13:
ORA-00936: missing expression"
[ACCEPT fiscal_year char PROMPT 'Enter the four digit year:'
SELECT cust.cus_fname, cust.cus_lname "Customer",
     sum(charter.char_distance*model.mod_chg_mile)* 1.35, '$99,999.99' "C\
harter"
FROM charter.customer JOIN charter.charter
ON customer.cus_code = charter.char_code
JOIN charter.aircraft
ON charter.ac_number = aircraft.ac_number
JOIN charter.model
ON aircraft.mod_code = model.mod_code
where exists
    (select distinct charter.char_date
      from charter.charter
where charter.char_date = ADD_MONTHS(TO_DATE(CONCAT('10-01', 'FISCAL_YEAR\
'), 'MM-DD-YYYY'), -12)
(SELECT avg(sum(charter.char_distance * model.mod_chg_mile)*1.35,'$99,999\
.99'))
   FROM charter.charter
GROUP BY customer.cus_lname))
Can someone help me. I have tried to figure it out but am stumped.
the tables related are as follows:
customer: pk-cus_code, cus_fname, cus_lname
charter: p-char_trip, char_date, char_distance, ac_number(fk), cus_code(fk)
aircraft: pk-ac_number, mod_code
model: pk-mod_code, mod_manufacturer, mod_name, mod_chg_mile.
The charges are calculated rate x miles flown plus 35% profit.
Thank you for who-ever can help me.
Barb

where exists
(select distinct charter.char_date
from charter.charter
ere charter.char_date =
ADD_MONTHS(TO_DATE(CONCAT('10-01', 'FISCAL_YEAR\
'), 'MM-DD-YYYY'), -12)
(SELECT avg(sum(charter.char_distance *
model.mod_chg_mile)*1.35,'$99,999\
.99'))any relation between these two selects? Probably missing relational operator or?

Similar Messages

  • SELECT query - problem with SORT

    Hi,
    Same select query behaves different way on development and quality server
    on Development it returns unsorted and Quality returns sorted
    it can be resolved by SORT but why does it behave differently
    Do you know what is setting in database
    thanks

    From F1 on SELECT:
    Orders the records in a SELECT statement. Without the ORDER-BY clause, the order
    in which the selected lines are supplied is undefined. This means that two similar SELECT
    statements may produce lines in a different order.
    Rob

  • ORA-06502 on  'SQL query' report with sort in 'Report Attributes'

    Hi All,
    We get the next error if we set sorting on a column in a 'Report' based on a 'SQL query'. Removing the sort, error disappeares:
    failed to parse SQL query:
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    Any suggestions?
    Erik

    Erik,
    Thanks, this explains it. By specifying the request as part of your URL you run into the recently uncovered issue. The request you're setting is REMFROMLIST and ADD2LIST. You probably either have links that include those requests or you have branches where you specify them. Either way, in order to get reports sorting to work, you'll have to make sure that the request strings are not part of your URL. This is a work-around and the upcoming HTML DB patch release will solve this issue.
    One way of avoiding this is to have computations on the previous pages that set a napplication level or page level item to the REMFROMLIST and ADD2LIST values and then you can use those items for your conditions that are currently evaluating those strings.
    Hope this helps and sorry for the inconvenience,
    Marc

  • Receivables - Query of Customers, sorted by Payment Terms?

    I'm looking for an easy way to run a query (through the Applications layer) of all customers, sorted by their Payment Terms (Net 30, Net 45, etc.)
    Any ideas?

    Hi Robert.......
    You can consider the Days of intervals as the payment temrs.
    For Example put 30 days it will give the report only for 30 days which is nothing but for 30 days payment terms.
    put 40 days it will give the report only for 30 days which is nothing but for 40 days payment terms.
    Hope this works for you.....
    Regards,
    Rahul

  • Query of Queries-  sorting issue

    I've discovered that when I get a query from the database and
    then try to sort it by QofQ the results are very strange.
    When using ' SELECT * FROM' the results differ from those
    when using 'SELECT Column1, Column2 FROM'
    I wonder if I did not include some parameters or it is a bug
    of Coldfusion.
    P.S. Attached code should illustrate what I mean.
    P.P.S. Can you implement 'upper(ColumnName)' in order by in
    QofQ?

    >> P.P.S. Can you implement 'upper(ColumnName)' in
    order by in QofQ?
    >It's always quite easy to TRY these things rather than
    asking someone else if it works ;-)
    Sorry :-) My mistake - it did not work because of the null in
    the column. It works perfectly fine when there are no nulls.
    Thanks for the response ;-)

  • Content Query Web Part - Sort Libraries by Name

    Hello,
    I created a Content Query Web Part that lists all Libraries under the current site (preferably it would be better to list only the Libraries on the current site but I couldn't manage to do it). However, the libraries are not sorted in any way.
    The query is the following:
    Path:{Site.URL}* contentclass:STS_List_DocumentLibrary  -Title:Assets  -Title:Templates 
    Whatever I select on the Sorting tab nothing happens, the results are displayed still in the same way, please see attached screenshot.
    PS: I also want to do the same things to lists the subsites - which I also couldn't do to list only one level *Below* the current site - any tips appreciated.
    path:"https://sharepointsite.com/sites/Test/Acquisitions/"  contentclass:STS_Web  Title<>Acquisitions

    Hi,
    Did you use the content search web part?
    I tried to reproduce the issue in my environment, it works well without any issue.
    Did you set the sort by Title in the SORTING section?
    I set the query just like yours:Path:{Site.URL}* contentclass:STS_List_DocumentLibrary  Title:docs  -Title:incoming 
    Then set the sort by Title in the sorting section.
    You can check whether you have configured the SORTING option, then check whether it works.
    Note: By default, the Title property is not enabled the sort option, you can configure it in
    Central Administration->Manage Service Application->Search Service Application->Search Schma
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Query result list sort order in the Service Manager Portal (2012).

    Hi there,
    I have a setup a user prompt for a request offering in which the values are based on a query results list.  When the user prompt is displayed in the portal the order of the items presented based on my query results list is in reverse
    alphabetical order (Z to A) instead of traditional A to Z.  I can clicked the column header to toggle the sort order, however having to do this is slightly annoying.
    My query results list is based on returning the Department field of a specific criteria of template AD user accounts (which are imported into the CMDB via the AD Connector).
    Where and how is the sort order defined?
    Thanks
    Bryan

    Hi Bryan,
    After a quick test I can see the query results is in a descending order based on the first display column of the query results configuration. In the Request offering wizard I don't see an option for sorting. I don't think it is possible to configure this
    out of the box. 
    But maybe it is possible from a Self Service Portal rendering point of view. Maybe there is a key for it in the settings.xml just like the maximum of query results:
    http://blogs.technet.com/b/servicemanager/archive/2011/11/08/advanced-query-results-customization-for-request-offerings.aspx
    If this is possible I'm also curious to know how! :)
    - Dennis

  • Query Required For sort

    CREATE TABLE COUNTRIES(CID INT,CNAME VARCHAR(100))
    INSERT INTO COUNTRIES VALUES(1,'AUSTRALIA')
    INSERT INTO COUNTRIES VALUES(2,'INDIA')
    INSERT INTO COUNTRIES VALUES(3,'FRANCE')
    INSERT INTO COUNTRIES VALUES(4,'BERLIN')
    SELECT * FROM COUNTRIES
    o/p
    CID CNAME
    2 INDIA
    1 AUSTRALIA
    4 BERLIN
    3 FRANCE
    here India should be always first position remaining countries values should be in sorted order

    You can use a conditional sorting =>
    SELECT *
    FROM COUNTRIES
    ORDER BY CASE WHEN CNAME = 'INDIA'
    THEN 0
    ELSE 1 END,
    CNAME
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Query needed for sorting by time value

    Hi Folks
    We have table it consists two columns like below
    Job_name varchar2(50)
    Scheduled_time date
    The filed scheduled time keep date and time value like below
    25-Jul-2009 4:00:10 AM
    26-Jul-2009 4:00:01 PM
    27-Jul-2009 4:00:00 PM
    28-Jul-2009 4:05:00 PM
    01-Jul-2009 4:06:00 PM
    02-Jun-2009 4:15:40 AM
    We need output as sorting by time value NOT date value. Expected output to be below
    25-Jul-2009 4:00:10 AM
    02-Jun-2009 4:15:40 AM
    27-Jul-2009 4:00:00 PM
    26-Jul-2009 4:00:01 PM
    28-Jul-2009 4:05:00 PM
    01-Jul-2009 4:06:00 PM
    I am using oracle 10G
    Thanks in Advance

    Here's how :
    SQL> create table job_table (job_name varchar2(50) not null, scheduled_time date);
    Table created.
    SQL> insert into job_table
      2  values ('Job_abc',to_date('25-JUL-2009 04:00:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_fdw',to_date('02-JUN-2009 04:15:40','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_fxj',to_date('27-JUL-2009 03:59:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> insert into job_table
      2  values ('Job_rjt',to_date('20-JUL-2009 14:59:00','DD-MON-YYYY HH24:MI:SS'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> alter session set nls_date_format='DD-MON-YYYY HH:MI:SS AM';
    Session altered.
    SQL> select job_name, scheduled_time from job_table
      2  order by to_char(scheduled_time,'HH24:MI:SS');
    JOB_NAME                                           SCHEDULED_TIME
    Job_fxj                                            27-JUL-2009 03:59:00 AM
    Job_abc                                            25-JUL-2009 04:00:00 AM
    Job_fdw                                            02-JUN-2009 04:15:40 AM
    Job_rjt                                            20-JUL-2009 02:59:00 PM
    SQL>

  • SQL query problem with sorting

    Hi,
    I have question regarding sql query . Right now I am getting the results like this if i use this sql query
    select ID,Name,Desc,Priority from emp order by Priority ;
    Priority is varchar field. I don't want to change the Priority field and cannot add a new column in the table. Because i don't have permission to do that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    9878 nate nate desc Medium
    3223 deb deb desc High
    ============================================
    I need a query to get the results like that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    3223 deb deb desc High
    9878 nate nate desc Medium
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    ============================================
    If any one knows about this one, please let me know.
    Thanks,
    Bala

    You are aware that there are differences in the SQL implementation between Sqlserver and Oracle? You could try something like this, if there's a INSTR function:
    ORDER BY INSTR('Highest,High,Medium,Low,', Priority || ',')You may have to change the "Priority || ," to a "Priority + ','), if string concatenation is done differently in sqlserver. Don't know about the ('), maybe you need (").
    C.

  • SQL Query report - how to evaluate the current sort column?

    Hi,
    I have a need to determine which column has been selected to sort the current report by. I need to pull this column name and pass it when a button is pressed so that the ensuing PDF report generated using PLPDF will be able to sort the data the same way.
    thanks in advance.

    Hi,
    As i think, you need to create report manually using SQL query and for sorting you can put a drop down box and user can select a field name and shorting type that is ASC or DESC from another drop down and than generate a report, additionally you can have another button for exporting to PDF that you can now manage through PLPDF and you can get the shorting column.
    hope this can help you.
    Thanks,
    Jaydip

  • Sort in the query (7.0)?

    Hi Experts,
    In the query it is sorting by Document number. I changed the properties of the individual characteristic to sort by posting date. But it is not working any idea?
    Thanks in advance.
    Sharat.

    Can anybody answer this question?
    Thanks.

  • Query slower due to sorting('order by')

    I have a query which when sorted is about 5 times slower.
    The 'order by' is on 3 different fields from 3 different tables, there are indexes present for all 3 columns. The number of records returned is about 5000.
    Any Ideas !!

    Sinantopuz was on to something -- but we could be talking about memory versus disk. Is SORT_AREA_SIZE too small? Or maybe you are using PGA_AGGREGATE_TARGET?
    If WORKAREA_SIZE_POLICY = AUTO, then reference PGA_AGGREGRATE_TARGET (show parameters pga_aggregate_target in SQL*Plus).
    Otherwise, review the SORT_AREA_SIZE.
    The SET AUTOTRACE will show disk sorts versus memory sorts. Disk sorts should be avoided by increasing your sort area (SORT_AREA_SIZE, PGA_AGGREGATE_TARGET, maybe even HASH_AREA_SIZE).
    Good luck.

  • Sort order of results in UOW Conformed Query ??

    We would like to know what is the expected behavior when a query with ascending ordering or descending ordering is run with UOW conformed.
    We know for sure that SQL generated and submit to the database with ORDER BY CLAUSES (which get the data in the database and sorted properly)
    However, with a confirm query, the database result will in turn, combine selected objects in the UNIT OF WORK.
    Will the combined collection of object be sorted in the prescribed ordering ?
    For example:
    If in UOW we have some uncommitted CAT object CAT-9, and CAT- 5
    In Database we return CAT-1, CAT-3, CAT-7 sorted in ascending order
    Will toplink return after the UOW conformed query, a collection in the following order ?
    CAT-1, CAT-3, CAT-5, CAT-7, CAT-9 ???
    Please advice.
    Thank you in advance.

    No, any new objects that conform to the query will be added to the end of the result set, so may not match the query's sort order.
    If you need the conformed results to maintain ordering you can either,
    - Sort the results in-memory after executing the query through Collections.sort(List).
    - Use a TreeSet as the query resultCollectionClass to sort the query results.

  • Sort orrder differance in query output on giving IN filter

    I have two simple tables Country and Status
    Their data are
    Country table
    C_ID     C_NAME
    1     INDIA
    2     USA
    3     UK
    4     JAPAN
    5     KOREA
    6     AUSTRALIA
    Status table
    STAT_ID     STAT_CD
    1     AAA
    2     BBB
    3     CCC
    4     DDD
    5     EEE
    6     FFF
    I have a third table Customer, with foreign keys to Country and Status
    Customer table
    Customer_ID
    Customer_Name
    Customer_code
    Country_id
    Customer_Stat
    100     Cust_100     AA     4     4
    101     Cust_101     AA     5     5
    119     Cust_119     AA     5     5
    118     Cust_118     AA     4     4
    117     Cust_117     AA     3     3
    116     Cust_116     AA     2     2
    115     Cust_115     AA     1     1
    114     Cust_114     AA     6     6
    113     Cust_113     AA     5     5
    112     Cust_112     AA     4     4
    111     Cust_111     AA     3     3
    110     Cust_110     AA     2     2
    First I query the Customer table with query
    SELECT * FROM (SELECT row_.*, rownum rownum_
    FROM (SELECT a.CUSTOMER_ID , a.CUSTOMER_CODE
    FROM CUSTOMER a, STATUS a1, COUNTRY a2
    WHERE a.CUTOMER_STAT = a1.STAT_ID(+)
    AND a.COUNTRY_ID = a2.C_ID(+)
    ORDER BY lower(trim(CUSTOMER_CODE)) ASC
    ) row_
    )WHERE rownum_ <= 20
    AND rownum_ > 0
    Now the data returned is in the given order
    100 AA
    101 AA
    119 AA
    118 AA
    117 AA
    116 AA
    115 AA
    114 AA
    113 AA
    112 AA
    Now with the primary key returned, I fire another query with same sort column
    SELECT
    a.CUSTOMER_ID , a.CUSTOMER_CODE
    FROM CUSTOMER a, STATUS a1, COUNTRY a2
    WHERE a.COUNTRY_ID = a1.C_ID(+) AND a.CUTOMER_STAT = a2.STAT_ID(+)
    AND (( a.CUSTOMER_ID ) IN ( 100,101,119,118,117,116,115,114,113,112) )
    ORDER BY lower(trim(CUSTOMER_7)) ASC
    But to my surprise I am getting data in a different order
    100 AA
    101 AA
    112 AA
    113 AA
    119 AA
    115 AA
    116 AA
    117 AA
    118 AA
    114 AA
    This is causing some issue in our application. What is the reason that we are getting result-set in different order though we have same sort given

    welcome to the forum, going forward if you could please share the create table and insert scripts. Also include you code in tag "{ code }" without quotes and space.
    create table country(c_id number, c_name varchar2(30));
    insert into country values(1, 'INDIA');
    insert into country values(2, 'USA');
    insert into country values(3, 'UK');
    insert into country values(4, 'JAPAN');
    insert into country values(5, 'KOREA');
    insert into country values(6, 'AUSTRALIA');
    create table status(stat_id number,stat_cd varchar2(30));
    insert into status values(1, 'AAA');
    insert into status values(2 ,'BBB');
    insert into status values(3 ,'CCC');
    insert into status values(4 ,'DDD');
    insert into status values(5 ,'EEE');
    insert into status values(6 ,'FFF');
    create table Customer(Customer_ID number,Customer_Name varchar2(30),Customer_code varchar2(30),Country_id number,
    Customer_Stat number);
    insert into customer values(100, 'Cust_100' ,'AA', 4 ,4);
    insert into customer values(101, 'Cust_101' ,'AA' ,5 ,5);
    insert into customer values(119, 'Cust_119' ,'AA' ,5 ,5);
    insert into customer values(118, 'Cust_118' ,'AA' ,4 ,4);
    insert into customer values(117, 'Cust_117' ,'AA' ,3 ,3);
    insert into customer values(116, 'Cust_116' ,'AA' ,2 ,2);
    insert into customer values(115, 'Cust_115', 'AA' ,1 ,1);
    insert into customer values(114, 'Cust_114', 'AA' ,6 ,6);
    insert into customer values(113, 'Cust_113', 'AA' ,5 ,5);
    insert into customer values(112, 'Cust_112', 'AA' ,4 ,4);
    insert into customer values(111, 'Cust_111', 'AA' ,3 ,3);
    insert into customer values(110, 'Cust_110', 'AA' ,2, 2);
    Your query below  has some issues customer_7 there's no column / alias like that, and country table should be a1 and status should be a2 to make sure your query works as column stat_id is not in country and c_id is not in status.
    SELECT
    a.CUSTOMER_ID , a.CUSTOMER_CODE
    FROM CUSTOMER a, STATUS a1, COUNTRY a2
    WHERE a.COUNTRY_ID = a1.C_ID(+) AND a.CUTOMER_STAT = a2.STAT_ID(+)
    AND (( a.CUSTOMER_ID ) IN ( 100,101,119,118,117,116,115,114,113,112) )
    ORDER BY lower(trim(CUSTOMER_7)) ASC
    Below changed query,the sort you were performing was on customer_code and I think you were trying to see the data sorted on customer_id. All the customers have some customer_code 'AA'. check out below hope it helps you in understanding.
    SELECT *
      FROM (SELECT row_.*, ROWNUM rownum_
              FROM (SELECT   a.customer_id, a.customer_code
                        FROM customer a, status a1, country a2
                       WHERE a.customer_stat = a1.stat_id(+)
                             AND a.country_id = a2.c_id(+)
                    ORDER BY LOWER (TRIM (customer_id)) ASC) row_)
    WHERE rownum_ <= 20 AND rownum_ > 0
    SELECT   a.customer_id, a.customer_code
        FROM customer a, status a2, country a1
       WHERE a.country_id = a1.c_id(+)
         AND a.customer_stat = a2.stat_id(+)
         AND ((a.customer_id) IN
                               (100, 101, 119, 118, 117, 116, 115, 114, 113, 112)
    ORDER BY LOWER (TRIM (customer_id)) ASC
    SELECT *
      FROM (SELECT row_.*, ROWNUM rownum_
              FROM (SELECT   a.customer_id, a.customer_code
                        FROM customer a, status a1, country a2
                       WHERE a.customer_stat = a1.stat_id(+)
                             AND a.country_id = a2.c_id(+)
                    ORDER BY LOWER (TRIM (customer_id)) ASC,customer_code) row_)
    WHERE rownum_ <= 20 AND rownum_ > 0
    SELECT   a.customer_id, a.customer_code
        FROM customer a, status a2, country a1
       WHERE a.country_id = a1.c_id(+)
         AND a.customer_stat = a2.stat_id(+)
         AND ((a.customer_id) IN
                               (100, 101, 119, 118, 117, 116, 115, 114, 113, 112)
    ORDER BY LOWER (TRIM (customer_id)) ASC,customer_code

Maybe you are looking for

  • Hp dv6-3032tx shut down and wont start again

    Hey guys, My HP laptop turned off and I cant start it anymore. If I press the power button it starts for 2-3sec, you can hear the fan, the LED is on but it goes out. The LED on the side for the charger is on if its plugged in. Already tried the reset

  • Power Point to Flash?

    Is it possible to either convert or somehow import a power point presentation into flash?

  • How do I get indesign to work

    I just bought creative cloud.  Everything downloaded except indesign.  Well, it downloaded but said I needed to update it.  Every time I tried I got the same error.  The adobe site said close creative cloud and reopen.  I did this but still didn't wo

  • Iweb & Leopard

    Hi all, When I publish a web page in Iweb it goes to preferences. I can't update the web page on the web like I did on Tiger?????????? [email protected]

  • Solaris 10 update 9 - live upgrade issues with ZFS

    Hi After doing a live upgrade from Solaris 10 update 8 to Solaris 10 update 9 the alternate boot environment I created is no longer bootable. I have completed all the pre-upgrade steps like: - Installing the latest version of live upgrade from the up