JPA: order by sum
hi,
i'd like to order the rows by the sum:
select p.kauf.einkaufer, sum(p.betrag) from Posten p where p.kauf.datum between :von and :bis group by p.kauf.einkaufer order by sum(p.betrag) desc
this leads to a syntax error: Internal Exception: line 1:130: expecting IDENT, found 'sum'
another thing i tried is to set an alias for the sum:
select p.kauf.einkaufer, sum(p.betrag) as summe from Posten p where p.kauf.datum between :von and :bis group by p.kauf.einkaufer order by summe desc
but this also didn't work. syntax error: Internal Exception: line 1:40: expecting "from", found 'as'
jakob
what i did in this case was, in criteria add the metric again and change the code to
sum(metricname by dimcolumn)
your dim column is where the A,B,C is coming from, then sort by that column. In pivot exclude that column.
if it does not work then add that column to pivot rows, sort by it and hide it.
Similar Messages
-
JPQL, howTo order by sum() ?
I have a query:
select new model.stateless.cd.helperobject.PersonWithAccessCount(personCounters.person, sum(personCounters.count))
from PersonAccessCounter personCounters
where personCounters.date>= :startPeriodDate and
personCounters.date<= :endPeriodDate
group by personCounters.person
order by sum(personCounters.count)'If I put away last order by sum(personCounters.count), it works fine. Otherway exception is thrown:
<openjpa-1.0.3-SNAPSHOT-r420667:649224 nonfatal user error> org.apache.openjpa.persistence.ArgumentException error while analysing query: 'select new model.stateless.cd.helperobject.PersonWithAccessCount(personCounters.person, sum(personCounters.count)) from PersonAccessCounter personCounters where personCounters.date>= :startPeriodDate and personCounters.date<= :endPeriodDate group by personCounters.person order by sum(personCounters.count)'. Сообщение об ошибке: <openjpa-1.0.3-SNAPSHOT-r420667:649224 nonfatal user error> org.apache.openjpa.kernel.jpql.ParseException: found "sum" in symbol 298, but expected: [<IDENTIFIER>]
I'm using WebSphere App Server 6.1 EJB feature pack + fix 19.+
Now, JPA implementation is 1.0.3
As I understood, I can use functions in order by statement. Am I right?
Edited by: Holod on 05.11.2008 14:01Seems like you are wrong:
[JPQL extension: aggregates in ORDER BY |http://n2.nabble.com/-jira--Created:-(OPENJPA-490)-JPQL-extension:-aggregates-in-ORDER-BY-td216766.html]
Seems like I'm wrong too. It is allowed to do starting from version 1.1.0 not from 1.0.1 as I thought before.
Ok, I'll wait for IBM... :(
Edited by: Holod on 05.11.2008 14:37 -
Having trouble wrapping query as subquery in order to sum a column
I have a query whose first column in the "select" is something like "count(distinct t.id)", and the query has a "group by" for several columns.
This generates a number of rows with a number in the first column representing the number of distinct id values in the resulting group, and several other columns.
I need to create a modified query that produces the sum of that first column.
I figured this would look something like:
select sum(total) from (select count(distinct t.id) as "total", ... from ... ... where)
I'm not able to get this to work. It appears I can't refer to the alias from the parent query, but I've tried other ways of referencing that column value, and I just can't figure it out.
I'd prefer not to have to provide the original query here. I'm hoping that I've provided enough information that someone could use to give me a useful response.sb92075 wrote:
How do I ask a question on the forums?
SQL and PL/SQL FAQ
Handle: david.karr
Status Level: Pro (560)
Registered: Mar 14, 2003
Total Posts: 911
Total Questions: 67 (50 unresolved)
I extend my condolences to you since you rarely get answers to your questions here.What would be the point of asking easy questions? :) -
Calculation of open orders and shipped not billed orders amount
Hi All,
I have a requirement to arrive at the values of Open Order and Shipped not billed .
This is an interface program and the output will be sent to a target server.
Input : Company code, Customer Code , Document date.
Output Fields are:
Customer Code
Sum of all open orders value
Sum of all shipped not billed orders value
To give an example
A Customer has 50 orders and the number of line items are 200 .
Overall order amount for 200 line items is 10,000.
70 line items have been delivered (amounting to 5,000) and
30 line items among the 70 delivered have been invoiced. (amounting to 3,000).
I need to know the best way to get to:
(1) Total "Open order" amount for the customer which is 5,000 in this example.
(2) Total "Shipped not billed" amount for the customer which is 2,000 in this example.
(3) Total "Invoiced" amount for the customer which is 3,000 in this example.
We are looking for the tables to access and the sequence of access
Since the interface is to be executed more than once in a day ,
the execution time should be optimum
Please suggest
Thanks
Venucheck table VBUK
GBSTK ne 'C' "over all processing status
and FKSTK ne 'C' "open billing orders
at header level
and
for item level check
Vbup tbale
make a join on Vbrk and VBuk in the where condition in addition to the selection criteria add the above two conditions and check the same.
once you have all the open orders enable the items and do the subtotalling and grand total on the item loop.
regards,
vijay -
Sum duplicate values in crystal reports XI
Post Author: Stuart
CA Forum: Formula
Hi All
As you probably know I'm very new to crystal reports.
Apologies but it seems my previous question was unclear as no one has been able to respond.
What I need is a formula that can recognise a name in field1 is a duplicate and then the amount in field2 for both rows should be sum together thus creating only one row with the same name in field1 but with the two values sum in field2.
I've had a look around and I can see how to remove the duplicates but I want to sum the duplicates into one row not two or three, etc.
Hope to hear from you,
Kind Regards,
StuartPost Author: Stuart
CA Forum: Formula
Hi
Thanks for your assistance,
There could be several duplicates,
My data will look like as follows;
Firstname Surname Amount
Thomas Brown $100
Thomas Brown $200
Andrew Slater $400
Andrew Brown $100
Kelly Smith $50
With the formula which I hope you can help me with I would expect the results to be;
Firstname Surname Amount
Thomas Brown $300
Andrew Slater $400
Andrew Brown $100
Kelly Smith $50
Notice in the above the first and surname have to be unique in order to sum.
There are alot more names hence I cannot list everything,
hope you can help me further,
Kind Regards,
Stuart -
Folks,
I have given up....Really need some advice....
I need a report example: Order Number, Order Type, Order Date, Customer number, Net Price, Total order cost
I can get all I need from file VBAK, EXCEPT total order cost, which is at the line level (VBAP). Now I need to show one line per order and sum the cost field (VBAP/WAVWR)...
How can I accomplish this in SAP Query? IS this even possible?Hi,
I am sure about SAP Query...
But check this program which might satisfy your requirement..
Declarations.
TYPE-POOLS: slis.
DATA: BEGIN OF wa_data,
vbeln LIKE vbak-vbeln,
auart LIKE vbak-auart,
audat LIKE vbak-audat,
kunnr LIKE vbak-kunnr,
netwr LIKE vbak-netwr,
wavwr LIKE vbap-wavwr,
waerk LIKE vbak-waerk,
posnr LIKE vbap-posnr,
END OF wa_data.
DATA: itab LIKE wa_data OCCURS 0 WITH HEADER LINE.
DATA: itab_final LIKE wa_data OCCURS 0 WITH HEADER LINE.
DATA: v_tabix TYPE sytabix.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv.
Selection-screen.
PARAMETERS: p_erdat LIKE vbak-erdat OBLIGATORY.
START-OF-SELECTION.
Get the data
SELECT avbeln aauart
aaudat akunnr
anetwr bwavwr
awaerk bposnr
INTO TABLE itab
FROM vbak AS a INNER JOIN vbap AS b
ON avbeln = bvbeln
WHERE a~erdat = p_erdat.
IF sy-subrc <> 0.
MESSAGE s208(00) WITH 'No data found'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT itab BY vbeln.
Sum the cost.
LOOP AT itab.
Store the tabix.
v_tabix = sy-tabix.
wa_data = itab.
AT END OF vbeln.
SUM.
modify the cost.
MOVE wa_data TO itab_final.
MOVE itab-wavwr TO itab_final-wavwr.
APPEND itab_final.
CLEAR itab_final.
ENDAT.
ENDLOOP.
SHow the report.
DATA: v_repid TYPE syrepid.
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'WA_DATA'
i_inclname = v_repid
CHANGING
ct_fieldcat = t_fieldcat.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = t_fieldcat
TABLES
t_outtab = itab_final.
Thanks,
Naren -
Tuning Oracle Applicatons Order Management Query
Hi
We are trying to build a Order Management related workbench for this I have created below query as per the client requirement.
And I have to use one package function to get Available_qty based on client defination. Package Function name is "xx_eg_calculated_onhand".
User will query this view based on Customer_id and Salesperson_id. When this view executed with these two values its taking long time.
But, if user queries with order_number it is getting executed fastly. Could somebody let me know what should I do to get this query execute fast when
user query with either customer_id or salesrep_id OR both.
CREATE OR REPLACE VIEW xxrelease_sales_orders_v (row_id,
sales_oder,
cust_po_number,
line_id,
carrier,
segment1,
customer_item_number,
description,
ship_from,
ship_to,
request_date,
order_quality,
available_qty,
shipped_quality,
uom,
customer_name,
sales_person_name,
delivery_detail_id,
cust_hold,
release_check,
line_status,
organization_code,
org_id,
order_number,
tolerance,
delivery_id,
organization_id,
salesrep_id,
party_id,
inventory_item_id,
header_id,
cust_account_id,
location_id,
cust_acct_site_id
AS
SELECT a.row_id,
a.Sales_Order,
a.Cust_Po_Number,
a.Line_ID,
a.Carrier,
a.segment1,
a.Customer_Item_Number,
a.description,
a.Ship_From,
a.ship_to,
a.request_date,
a.order_quality,
DECODE(SIGN(a.Available_qty),-1, 0, a.available_qty) Available_Qty,
DECODE(SIGN(LEAST(a.order_quality, a.Available_qty)), -1,0, LEAST(a.order_quality, a.Available_qty)) Shipped_Qty,
a.uom,
a.Customer_Name,
a.Sales_Person_Name,
a.delivery_detail_id,
a.cust_hold,
a.release_check,
a.Line_status,
a.organization_code,
a.org_id,
a.order_number,
a.tolerance,
a.delivery_id,
a.organization_id,
a.salesrep_id,
a.party_id,
a.inventory_item_id,
a.header_id,
a.cust_account_id,
a.location_id,
a.cust_acct_site_id
From (
SELECT ooh.ROWID row_id,
ooh.order_number||'-'||ool.line_number||'.'||ool.shipment_number Sales_Order,
ool.cust_po_number,
ool.line_id,
NVL (ool.freight_carrier_code, 'NA') carrier,
msi.segment1,
ool.ordered_item Customer_Item_Number,
msi.description,
haou.name Ship_From,
hl.city || ' ' || hl.state || ' ' || hl.postal_code ship_to,
NVL (ool.request_date, SYSDATE) request_date,
NVL (ool.ordered_quantity, 0) order_quality,
xxeg_releaseworkbench_form_pkg.xx_eg_calculated_onhand(ool.line_id) Available_qty,
ool.order_quantity_uom uom,
hp.party_name Customer_Name,
hca.account_number Customer_Number,
jrs.name Sales_Person_Name,
wdd.delivery_detail_id,
0 cust_hold,
0 release_check,
oe_line_status_pub.Get_Line_Status(ool.line_id, ool.flow_status_code) Line_status,
ool.org_id,
ooh.order_number,
NVL (ool.ship_tolerance_above, 0) tolerance,
wda.delivery_id,
ool.ship_from_org_id organization_id,
jrs.salesrep_id,
hp.party_id,
msi.inventory_item_id,
ooh.header_id,
hca.cust_account_id,
hps.location_id,
hcsu.cust_acct_site_id,
ooh.ship_to_org_id site_use_id,
hcas.party_site_id,
'0' organization_code
FROM oe_order_headers_all ooh,
oe_order_lines_all ool,
wsh_delivery_details wdd,
wsh_delivery_assignments wda,
mtl_system_items_b msi,
hz_cust_accounts hca,
hz_parties hp,
jtf_rs_salesreps jrs,
hz_cust_site_uses_all hcsu,
hz_cust_acct_sites_all hcas,
hz_party_sites hps,
hz_locations hl,
hr_all_organization_units haou
WHERE ooh.header_id = ool.header_id
AND ooh.header_id = wdd.source_header_id
AND ool.line_id = wdd.source_line_id
AND wdd.delivery_detail_id = wda.delivery_detail_id
AND ool.inventory_item_id = msi.inventory_item_id
AND ooh.ship_from_org_id = msi.organization_id
AND ooh.sold_to_org_id = hca.cust_account_id
AND hca.party_id = hp.party_id
AND ool.salesrep_id = jrs.salesrep_id
AND ool.org_id = jrs.org_id
AND ooh.ship_to_org_id = hcsu.site_use_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcas.party_site_id = hps.party_site_id
AND hps.location_id = hl.location_id
AND ool.ship_from_org_id = haou.organization_id
AND wdd.released_status = 'R'
AND hcsu.site_use_code = 'SHIP_TO'
AND ool.flow_status_code = 'AWAITING_SHIPPING'
--and hca.cust_account_id = 1531 and jrs.salesrep_id = 100000060
--AND ooh.order_number = '361130'
) a
Function
FUNCTION xx_eg_calculated_onhand (p_so_line_id IN NUMBER) RETURN NUMBER IS
--CREATE OR REPLACE PROCEDURE xx_eg_calculated_onhand (p_so_line_id IN NUMBER) IS
-- Steps Involved to calculate the onhand availability
-- 1. Get Inventory Item ID and Warehouse from given sales order line ID
-- Local Variable Declration
l_inventory_item_id apps.oe_order_lines_all.inventory_item_id%TYPE := 0;
l_organization_id apps.oe_order_lines_all.ship_from_org_id%TYPE := 0;
l_order_quantity_uom apps.oe_order_lines_all.order_quantity_uom%TYPE := '';
l_primary_uom_code apps.mtl_system_items_b.primary_uom_code%TYPE := '';
l_onhand_reserve NUMBER(15,2) := 0;
l_hard_reservation NUMBER(15,2) := 0;
l_so_soft_reservation NUMBER(15,2) := 0;
l_wo_soft_reservation NUMBER(15,2) := 0;
l_so_released_ware_qty NUMBER(15,2) := 0;
-- Cursor declrations
-- Get inventory item, warehouse and order UOM Details
CURSOR Get_inv_and_org_details IS
SELECT ool.inventory_item_id,
ool.ship_from_org_id,
ool.order_quantity_uom,
msi.primary_uom_code
FROM apps.oe_order_lines_all ool,
apps.mtl_system_items_b msi
WHERE ool.line_id = NVL(p_so_line_id,0)
AND ool.inventory_item_id = msi.inventory_item_id
AND ool.ship_from_org_id = msi.organization_id;
-- Get Hard Reservation details for given item and warehouse
CURSOR Get_Hard_reservation(p_inventory_item_id IN NUMBER, p_organization_id IN NUMBER) IS
SELECT SUM(reservation_quantity)
FROM apps.mtl_reservations
WHERE inventory_item_id = NVL(p_inventory_item_id,0)
AND organization_id = NVL(p_organization_id, 0)
AND demand_source_line_id <> p_so_line_id;
-- Get Soft reservation details for given item and warehouse for Sales order
CURSOR Get_so_soft_reservation (p_inventory_item_id IN NUMBER, p_organization_id IN NUMBER) IS
SELECT SUM(mlqv.onhand_qty)
FROM xxapps.xx_eg_lot_reservations xelr,
xxapps.mtl_lot_qty_vw mlqv,
apps.oe_order_lines_all ool
WHERE xelr.lot_no = mlqv.lot_no
AND xelr.so_line_id = ool.line_id
AND mlqv.org_id = ool.ship_from_org_id
AND mlqv.item_id = ool.inventory_item_id
AND mlqv.org_id = p_organization_id
AND mlqv.item_id = p_inventory_item_id;
-- Get Soft reservation details for given item and warehouse for work orders
CURSOR Get_wo_soft_reservation (p_inventory_item_id IN NUMBER, p_organization_id IN NUMBER) IS
SELECT SUM(mlqv.onhand_qty)
FROM xxapps.xx_eg_lot_reservations xelr,
xxapps.mtl_lot_qty_vw mlqv,
wip.wip_requirement_operations wro
WHERE xelr.lot_no = mlqv.lot_no
AND xelr.wip_entity_id = wro.wip_entity_id
AND mlqv.org_id = wro.organization_id
AND mlqv.item_id = wro.inventory_item_id
AND mlqv.org_id = p_organization_id
AND mlqv.item_id = p_inventory_item_id;
-- Get Sales order lines quantity for the shipment status 'Released to Wareshoue'
CURSOR Get_so_qty (p_inventory_item_id IN NUMBER, p_organization_id IN NUMBER) IS
SELECT SUM(requested_quantity)
FROM apps.wsh_deliverables_v
WHERE released_status='S'
AND inventory_item_id = p_inventory_item_id
AND organization_id = p_organization_id;
BEGIN
Dbms_output.put_line('Function Started with so_line_id = '||p_so_line_id);
-- Get the inventory_item_id and warehouse id and
-- ordered quantity uom details
-- By opening the cursor Get_inv_and_org_details
OPEN Get_inv_and_org_details;
FETCH Get_inv_and_org_details INTO l_inventory_item_id,l_organization_id,l_order_quantity_uom,l_primary_uom_code;
CLOSE Get_inv_and_org_details;
Dbms_output.put_line('Inventory item id = '||l_inventory_item_id||' and warehouse id = '||l_organization_id);
IF (l_inventory_item_id = 0 OR l_inventory_item_id IS NULL) OR
(l_organization_id = 0 OR l_organization_id IS NULL) THEN
dbms_output.put_line('No inventory/wareshouse details available for given sales order line');
RETURN 0;
END IF;
-- Get onhand available to reserve quantity using API
-- passing inventory item id and organization id as
-- a parameters.
l_onhand_reserve := apps.xx_utility_pkg.Get_Available_to_Reserve_org(l_inventory_item_id,l_organization_id);
Dbms_output.put_line('Onhand availability to Reserve quantity = '||l_onhand_reserve);
-- Get hard reservation quantity by
-- passing inventory item id and organization id as
-- a parameters to cursor Get_Hard_reservation
OPEN Get_Hard_reservation(l_inventory_item_id,l_organization_id);
FETCH Get_Hard_reservation INTO l_hard_reservation;
CLOSE Get_Hard_reservation;
Dbms_output.put_line('Hard Reserve quantity = '||l_hard_reservation);
-- Get Soft reservation quantity by
-- passing inventory item id and organization id as
-- a parameters to cursor
-- Get_so_soft_reservation for sales lines
OPEN Get_so_soft_reservation(l_inventory_item_id,l_organization_id);
FETCH Get_so_soft_reservation INTO l_so_soft_reservation;
CLOSE Get_so_soft_reservation;
-- Get Soft reservation quantity by
-- passing inventory item id and organization id as
-- a parameters to cursor
-- Get_wo_soft_reservation for work orders
OPEN Get_wo_soft_reservation(l_inventory_item_id,l_organization_id);
FETCH Get_wo_soft_reservation INTO l_wo_soft_reservation;
CLOSE Get_wo_soft_reservation;
-- Get Sales order line sum quantity for those
-- lines which has a status of 'Released to Warehouse'
-- at their shipment level for given parameters
OPEN Get_so_qty(l_inventory_item_id,l_organization_id);
FETCH Get_so_qty INTO l_so_released_ware_qty;
CLOSE Get_so_qty;
INSERT INTO xxapps.xxeg_calculated_onhand_tbl
order_line_id,
inventory_item_id,
organization_id,
available_to_reserve,
hard_reservation,
soft_reservation_so,
soft_reservation_wo,
other_so_lines_qty,
run_date
VALUES
p_so_line_id,
l_inventory_item_id,
l_organization_id,
NVL(l_onhand_reserve,0),
NVL(l_hard_reservation,0),
NVL(l_so_soft_reservation,0),
NVL(l_wo_soft_reservation,0),
NVL(l_so_released_ware_qty,0),
sysdate
Commit Work;
Create table xxapps.xxeg_calculated_onhand_tbl
order_line_id NUMBER,
inventory_item_id NUMBER,
organization_id NUMBER,
available_to_reserve NUMBER,
hard_reservation NUMBER,
soft_reservation_so NUMBER,
soft_reservation_wo NUMBER,
other_so_lines_qty NUMBER,
run_date DATE
RETURN (NVL(l_onhand_reserve,0) + NVL(l_hard_reservation,0) - (NVL(l_so_soft_reservation,0) + NVL(l_wo_soft_reservation,0)) - NVL(l_so_released_ware_qty,0));
EXCEPTION
WHEN others THEN
RETURN (0);
END xx_eg_calculated_onhand;
KiranHi
I have gathered a explain plan. Could somebody let me know whats going on.
plan_table_output
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 1 | 404 | 87 |
| 1 | NESTED LOOPS | | 1 | 404 | 87 |
| 2 | NESTED LOOPS | | 1 | 374 | 86 |
| 3 | NESTED LOOPS | | 1 | 323 | 85 |
| 4 | NESTED LOOPS | | 1 | 300 | 84 |
| 5 | NESTED LOOPS | | 1 | 290 | 83 |
| 6 | NESTED LOOPS | | 1 | 280 | 80 |
| 7 | NESTED LOOPS | | 1 | 261 | 79 |
| 8 | NESTED LOOPS | | 1 | 209 | 78 |
| 9 | NESTED LOOPS | | 1 | 192 | 75 |
| 10 | NESTED LOOPS | | 1 | 164 | 74 |
| 11 | NESTED LOOPS | | 1 | 76 | 72 |
| 12 | NESTED LOOPS | | 1 | 46 | 3 |
| 13 | TABLE ACCESS BY INDEX ROWID| HZ_CUST_ACCOUNTS | 1 | 16 | 2 |
|* 14 | INDEX UNIQUE SCAN | HZ_CUST_ACCOUNTS_U1 | 1 | | 1 |
| 15 | TABLE ACCESS BY INDEX ROWID| HZ_PARTIES | 1 | 30 | 1 |
|* 16 | INDEX UNIQUE SCAN | HZ_PARTIES_U1 | 1 | | |
| 17 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_HEADERS_ALL | 1 | 30 | 69 |
|* 18 | INDEX RANGE SCAN | OE_ORDER_HEADERS_N2 | 1 | | 1 |
|* 19 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_LINES_ALL | 1 | 88 | 2 |
|* 20 | INDEX RANGE SCAN | OE_ORDER_LINES_N1 | 6 | | 1 |
| 21 | TABLE ACCESS BY INDEX ROWID | JTF_RS_SALESREPS | 1 | 28 | 1 |
|* 22 | INDEX UNIQUE SCAN | JTF_RS_SALESREPS_U1 | 1 | | |
|* 23 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_DETAILS | 1 | 17 | 3 |
|* 24 | INDEX RANGE SCAN | WSH_DELIVERY_DETAILS_N3 | 4 | | 2 |
| 25 | TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B | 1 | 52 | 1 |
|* 26 | INDEX UNIQUE SCAN | MTL_SYSTEM_ITEMS_B_U1 | 1 | | |
|* 27 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 19 | 1 |
|* 28 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | |
| 29 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_ASSIGNMENTS | 1 | 10 | 3 |
|* 30 | INDEX RANGE SCAN | WSH_DELIVERY_ASSIGNMENTS_N3 | 1 | | 2 |
| 31 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 10 | 1 |
|* 32 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | |
|* 33 | TABLE ACCESS BY INDEX ROWID | HZ_PARTY_SITES | 1 | 23 | 1 |
|* 34 | INDEX UNIQUE SCAN | HZ_PARTY_SITES_U1 | 1 | | |
|* 35 | TABLE ACCESS BY INDEX ROWID | HZ_LOCATIONS | 1 | 51 | 1 |
|* 36 | INDEX UNIQUE SCAN | HZ_LOCATIONS_U1 | 1 | | |
| 37 | TABLE ACCESS BY INDEX ROWID | HR_ALL_ORGANIZATION_UNITS | 1 | 30 | 1 |
|* 38 | INDEX UNIQUE SCAN | HR_ORGANIZATION_UNITS_PK | 1 | | |
Predicate Information (identified by operation id):
14 - access("HCA"."CUST_ACCOUNT_ID"=1531)
16 - access("HCA"."PARTY_ID"="HP"."PARTY_ID")
18 - access("OOH"."SOLD_TO_ORG_ID"=1531)
filter("OOH"."SOLD_TO_ORG_ID"="HCA"."CUST_ACCOUNT_ID")
19 - filter("OOL"."FLOW_STATUS_CODE"='AWAITING_SHIPPING' AND "OOL"."SALESREP_ID"=100000060)
20 - access("OOH"."HEADER_ID"="OOL"."HEADER_ID")
22 - access("JRS"."SALESREP_ID"=100000060 AND "OOL"."ORG_ID"="JRS"."ORG_ID")
filter("OOL"."SALESREP_ID"="JRS"."SALESREP_ID")
23 - filter("OOH"."HEADER_ID"="WDD"."SOURCE_HEADER_ID" AND "WDD"."RELEASED_STATUS"='R')
24 - access("OOL"."LINE_ID"="WDD"."SOURCE_LINE_ID")
26 - access("OOL"."INVENTORY_ITEM_ID"="MSI"."INVENTORY_ITEM_ID" AND
"OOH"."SHIP_FROM_ORG_ID"="MSI"."ORGANIZATION_ID")
27 - filter("HCSU"."SITE_USE_CODE"='SHIP_TO')
28 - access("OOH"."SHIP_TO_ORG_ID"="HCSU"."SITE_USE_ID")
30 - access("WDD"."DELIVERY_DETAIL_ID"="WDA"."DELIVERY_DETAIL_ID")
32 - access("HCSU"."CUST_ACCT_SITE_ID"="HCAS"."CUST_ACCT_SITE_ID")
33 - filter("HZ_PARTY_SITES"."ACTUAL_CONTENT_SOURCE"<>'DNB' AND
"HZ_PARTY_SITES"."ACTUAL_CONTENT_SOURCE"<>'SST')
34 - access("HCAS"."PARTY_SITE_ID"="HZ_PARTY_SITES"."PARTY_SITE_ID")
35 - filter(NVL("HZ_LOCATIONS"."ACTUAL_CONTENT_SOURCE","HZ_LOCATIONS"."CONTENT_SOURCE_TYPE")<>'DNB'
AND NVL("HZ_LOCATIONS"."ACTUAL_CONTENT_SOURCE","HZ_LOCATIONS"."CONTENT_SOURCE_TYPE")<>'SST')
36 - access("HZ_PARTY_SITES"."LOCATION_ID"="HZ_LOCATIONS"."LOCATION_ID")
38 - access("OOL"."SHIP_FROM_ORG_ID"="HAOU"."ORGANIZATION_ID")
Note: cpu costing is off
Regards
Kiran -
Sum function on Sql display on a Jtable
Hi,
I'm trying to add up the values of a column on a Jtable and somehow display the Total. I have been trying to do the query by using a join on sql. Here is the code:
private void getTotal() { Connection con = getConnection(); try{ String sql = "SELECT Item.Item_price" + "FROM Item INNER JOIN [Order] ON Item.Item_ID = Order.Item_ID" + "SUM(Item_price) Where Order.Table_number = " + Integer.parseInt(tableNumber)+";"; PreparedStatement pStmt = con.prepareStatement( sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ); ResultSet rs = pStmt.executeQuery( ); DefaultTableModel tableModel = new DefaultTableModel(); tableModel.addColumn("Item_price"); Object [] row = { rs.getObject(1)}; tableModel.addRow(row); con.close(); jTable1.setModel(tableModel); } catch(Exception e) { System.out.println(e); } }
Does anyone know a good method of doing this?
Thanks.Dear Antony Gitonga
It's not Table sum.
Plaese see the where condition, it will take only the current father and sum the quantity.
Plaese save the query in query manager and assign it in formated search and try.
select sum(T1.U_Base_Qty) From OITT T0,ITT1 T1
where
T0.code=T1.father and
T0.code = $[OITT.Code]
Regards,
Thanga Raj.K
Edited by: Thanga Raj K on Jun 1, 2009 12:15 PM
Edited by: Thanga Raj K on Jun 1, 2009 12:18 PM -
Sum 2 columns in alv report (not separately)
Hi,
I have an alv report and I use do_sum = 'X' in order to sum separately 2
columns.
The demand here is that at the end of the report there will also be
a total of the 2 columns together.
I tried to implement it but so far - no success.
Mayby someone has an idea ??
Promise to award points...
Thanks.
Ruthie.Hi,
For summing say column EBELN, MATNR for eg.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-outputlen = 10.
<b>fieldcatalog-do_sum = 'X'.</b>
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
<b>fieldcatalog-do_sum = 'X'.</b>
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
You will get the sum at the end also, try this. -
Query Builder - sort order causing ORA-00979 error
Hello,
I'm having an issue with the "sort order" clause in the query builder tool when using a function on the same column.
I've build a simple query in the gui and the following statement is displayed in the SQL Window
select "DEMO_ORDER_ITEMS"."ORDER_ID" as "ORDER_ID",
sum(DEMO_ORDER_ITEMS.QUANTITY) as "QUANTITY"
from "DEMO_ORDER_ITEMS" "DEMO_ORDER_ITEMS"
group by DEMO_ORDER_ITEMS.ORDER_ID
and if I add a sort order of "1" on the quantity field, the following query is changed to
select "DEMO_ORDER_ITEMS"."ORDER_ID" as "ORDER_ID",
sum(DEMO_ORDER_ITEMS.QUANTITY) as "QUANTITY"
from "DEMO_ORDER_ITEMS" "DEMO_ORDER_ITEMS"
group by DEMO_ORDER_ITEMS.ORDER_ID
order by DEMO_ORDER_ITEMS.QUANTITY DESC
When running this query I get an error
failed to parse SQL query:
ORA-00979: not a GROUP BY expression
It is quite obvious what is wrong with the query but I don't know how to get the query builder tool to generate the correct statement. The order by clause should be order by sum(DEMO_ORDER_ITEMS.QUANTITY) DESC.
I've tried to do some searching and haven't found much documentation on this issue. Any assistance is appreciated.
Thanks,
TonyWhile this statement is generally certainly true and should also be remembered, it is not really helpful for the specific case.
I think the behaviour described is a bug. However this might be one a little difficult to solve. The user unfortunatly can't influence much of the query builder results directly.
Either put 1 into the order by clause or use the column alias name without table alias name ("QUANTITY" only).
My personal solution would be NOT TO use any sort criteia in the query builder. This makes sense in so far as the generated SQL is often basis for some report. If that is an interactive report you won't add a sort order anyway. This is a layout thing and layout will be handled by the end user itself. he can choose whatever sorting he wants.
Edited by: Sven W. on Jul 22, 2009 11:43 AM -
Sum the value of look up table based on two filter criteria
Hello Everyone
I am new to Powerpivot and would appreciate if someone could help me on the following problem.
You can download the example of this excel file form the following DropBox link:
Dropbox Link
The first table is tOrders
Week number
Work center
order number
Production time in minutes
2
a
111
60
2
a
112
70
2
b
113
60
3
b
114
50
3
a
115
40
3
b
116
60
4
a
117
90
4
b
118
40
The second is dLookupList
Week number
Work center
mantenace in minutes per week
Break dows in minutes per week
2
a
10
10
2
b
20
5
3
a
15
12
3
b
30
10
4
a
20
10
4
b
10
10
I’m trying to create Pivot that has filter on Week number to show the number of orders, Sum of Production time in minutes and the total of the values form the lookup table dLookupList that matches the work center and the selected week
numbers. So that I can calculate the total time for each work center. Filter criteria is Week number and Work center.
For example if someone select all weeks numbers the result sould look like this
Week number
(All)
Work center
Count of order number
Sum of Production time in minutes
mantenace in minutes per week
Break dows in minutes per week
Total time
a
4
260
45
32
337
b
4
210
60
25
295
Grand Total
8
470
Result for week 2
Week number
2
Work center
Count of order number
Sum of Production time in minutes
mantenace in minutes per week
Break dows in minutes per week
Total time
a
2
130
10
10
150
b
1
60
20
5
85
Grand Total
3
190
How can I relate these two tables to get the above result?
Any help is highly appreciated.
Regards
PriyanHi Recio
Thank you very much for the swift response. I was able to get it work.
I got two questions:
How do you add a total time column to the pivot table like you did? Because there are no calculated field in power pivot.
I prefer that the filter is based on the Orders table. So that if you select all Week numbers in the filter, that pivot will show result for all orders and relevant sums from the lookup list.
Link download the example file
For example: I add Week number 5 to the work center “a”
Week number
Work center
WNandWC
mantenace in minutes per week
Break dows in minutes per week
2
a
WN2WCa
10
10
2
b
WN2WCb
20
5
3
a
WN3WCa
15
12
3
b
WN3WCb
30
10
4
a
WN4WCa
20
10
4
b
WN4WCb
10
10
5
a
WN5WCa
1
1
In the orders table there are no records for week number 5
Week number
Work center
WNandWC
order number
Production time in minutes
2
a
WN2WCa
111
60
2
a
WN2WCa
112
70
2
b
WN2WCb
113
60
3
b
WN3WCb
114
50
3
a
WN3WCa
115
40
3
b
WN3WCb
116
60
4
a
WN4WCa
117
90
4
b
WN4WCb
118
40
4
a
WN4WCa
119
50
But the pivot sums up the week number 5 also.
Do you have any idea how to solve it?
Thank you very much.
Regards
Priyan -
Getting top 9, aggregating the rest - challenge with SUM
Dear,
I'd like to get the top 9 customers and aggregate the remaining to one number.
My query is:
select k.kundenid, k.KDNR, k.FIRMA_1, sum(a.auftrag_total)
from auftrag a, kunden k
where a.kunde_id=k.kundenid and
TO_CHAR(a.DATUM,'YYYY')=TO_CHAR(sysdate,'YYYY')
group by k.kundenid, k.KDNR, k.FIRMA_1
order by 4 desc
I have tried with DENSE_RANK() but it gets complicated to combine this with SUM()
Can someone help?
Kind regards..........LorenzI seem to have hit a bug in XE on windows XP. The following query should work but the 10th record only includes the 10th ranked total, not the total of 10 thru 16.
If I change the with statement to a create table, the query works. Also, if I just use the second half of the union all I get the correct results. The combination of with and union/union all seems to fail.
create table auftrag(kunde_id number, kdnr varchar2(20), datum date, auftrag_total number);
insert into auftrag (select 1 kunde_id, 'cust1' kdnr, sysdate datum, 1200 auftrag_total from dual);
insert into auftrag (select 1 kunde_id, 'cust1' kdnr, sysdate datum, 600 auftrag_total from dual);
insert into auftrag (select 2 kunde_id, 'cust2' kdnr, sysdate datum, 1600 auftrag_total from dual);
insert into auftrag (select 2 kunde_id, 'cust2' kdnr, sysdate datum, 700 auftrag_total from dual);
insert into auftrag (select 3 kunde_id, 'cust3' kdnr, sysdate datum, 500 auftrag_total from dual);
insert into auftrag (select 3 kunde_id, 'cust3' kdnr, sysdate datum, 1300 auftrag_total from dual);
insert into auftrag (select 4 kunde_id, 'cust4' kdnr, sysdate datum, 200 auftrag_total from dual);
insert into auftrag (select 5 kunde_id, 'cust5' kdnr, sysdate datum, 1500 auftrag_total from dual);
insert into auftrag (select 6 kunde_id, 'cust6' kdnr, sysdate datum, 800 auftrag_total from dual);
insert into auftrag (select 7 kunde_id, 'cust7' kdnr, sysdate datum, 1400 auftrag_total from dual);
insert into auftrag (select 8 kunde_id, 'cust8' kdnr, sysdate datum, 300 auftrag_total from dual);
insert into auftrag (select 9 kunde_id, 'cust9' kdnr, sysdate datum, 2000 auftrag_total from dual);
insert into auftrag (select 10 kunde_id, 'cust10' kdnr, sysdate datum, 1900 auftrag_total from dual);
insert into auftrag (select 11 kunde_id, 'cust11' kdnr, sysdate datum, 400 auftrag_total from dual);
insert into auftrag (select 12 kunde_id, 'cust12' kdnr, sysdate datum, 1800 auftrag_total from dual);
insert into auftrag (select 13 kunde_id, 'cust13' kdnr, sysdate datum, 900 auftrag_total from dual);
insert into auftrag (select 14 kunde_id, 'cust14' kdnr, sysdate datum, 1000 auftrag_total from dual);
insert into auftrag (select 15 kunde_id, 'cust15' kdnr, sysdate datum, 1700 auftrag_total from dual);
insert into auftrag (select 16 kunde_id, 'cust16' kdnr, sysdate datum, 100 auftrag_total from dual);
create table kunden(kundenid number, firma_1 varchar2(20));
insert into kunden (select 1 kundenid, 'desc1' firma_1 from dual);
insert into kunden (select 2 kundenid, 'desc2' firma_1 from dual);
insert into kunden (select 3 kundenid, 'desc3' firma_1 from dual);
insert into kunden (select 4 kundenid, 'desc4' firma_1 from dual);
insert into kunden (select 5 kundenid, 'desc5' firma_1 from dual);
insert into kunden (select 6 kundenid, 'desc6' firma_1 from dual);
insert into kunden (select 7 kundenid, 'desc7' firma_1 from dual);
insert into kunden (select 8 kundenid, 'desc8' firma_1 from dual);
insert into kunden (select 9 kundenid, 'desc9' firma_1 from dual);
insert into kunden (select 10 kundenid, 'desc10' firma_1 from dual);
insert into kunden (select 11 kundenid, 'desc11' firma_1 from dual);
insert into kunden (select 12 kundenid, 'desc12' firma_1 from dual);
insert into kunden (select 13 kundenid, 'desc13' firma_1 from dual);
insert into kunden (select 14 kundenid, 'desc14' firma_1 from dual);
insert into kunden (select 15 kundenid, 'desc15' firma_1 from dual);
insert into kunden (select 16 kundenid, 'desc16' firma_1 from dual);
commit;
with t_rank as (
select to_char(kunde_id) kunde_id, kdnr, firma_1, sum(auftrag_total) sum_at,
row_number() over (order by sum(auftrag_total) desc) rn
from auftrag, kunden
where kunde_id = kundenid
and trunc(datum,'y') = trunc(sysdate,'y')
group by kunde_id, kdnr, firma_1)
select *
from t_rank
where rn <= 9
union all
select 'Rest', 'Rest', 'Rest', sum(sum_at), 10
from t_rank
where rn > 9
order by 5 -
Hi Experts
I stuck with small problem ,any one please solve the problem i appreciate ur help
Below is my table , i need to get maximum operation i..e from order 10 the maxi operation is #/02 and for order 20 operation is #/01 . and i need to sum it up for respective operations Actual qty values ..
Ext material grp Order Number Operation key Actual Qty
100 A.H 10 #/01 200
100A.H 10 #/02 300
100 A.H 20 #/o1 100
100 A.H 30 #/02 400
i want to show the table like
Operation Keys
Ext material grp 10 20
100A.H 100 700(300+400 )
All Objects from same dataprovider,
Please help me on this .Hello,
I am having some difficulty interpreting your requirement. You say:
I need to get maximum operation i..e from order 10 the maxi operation is #/02 and for order 20 operation is #/01
Is the output you described more likely to look like that below?
Ext material grp..... Order Number.....Operation key.....Actual Qty
100 A.H.........................10....................... #/02.............. 500 (200 + 300)
100 A.H........................ 20....................... #/01...............100
100 A.H........................ 30....................... #/02...............400
If so, you could use extended syntax to pull back the max operation key and actual qty sum in the context of each ext material grp, order number combination (or whatever dimensions are needed to give you the grain needed). EG
max operation key = max (operation key) in (ext material grp; order number)
sum actual qty = sum(actual qty) in (ext material grp; order number)
Hope this helps
Jacqui -
Hi all
Just found an annoying bug in Oracle.
(perhaps I should say that the bug is most likely more in Oracle clients, like TOAD and APEX).
I'm not sure if this has been pointed out already, but it's really quite poor.
Say you have a query, like this:
select member_name, member_points
from member_tableIn TOAD or APEX you can then sort the columns however you want (not using an order by, but by using their in-built sort functions).
Now, if you include an order by...
select member_name, member_points
from member_table
order by member_pointsYou can no longer do a column sort in TOAD or APEX.
This seems to make sense, given the results are already sorted.
And the only method used to detect if results can be sorted or not is by the presence or absence of the "order by" clause.
Now, normally that would be fine - if your query orders it's results, then you probably don't want to sort them, right?
The problem?
Instead of analysing the query properly, all that's done is that the exact string "order by" (not case-sensitive) is checked.
If this string is in your query, you cannot sort your results.
Example:
If you have the following query:
select member_name "Member Name", member_points "Order By"
from member_tableYou cannot sort your results.
This is obviously completely stupid, as the "order by" string is only being used as a title!!
In fact, the detection is so bad that while this won't work...
select member_name, member_points
from member_table
order by member_pointsThis will...
select member_name, member_points
from member_table
order
by member_pointsor this...
select member_name, member_points
from member_table
order by member_points(2 spaces between "order" and "by")
Buggy!
Anyone else encountered this problem?
So far it happens in TOAD and APEX.Not an Oracle RDBMS bug, but an APEX bug. (and no, I do not give a damn for TOAD ;-) ).
The problem as you've identified is caused by APEX scanning the SQL, detecting an "ORDER BY" clause, and then assuming the results are already sorted and not allowing you enable APEX's column sort feature on the results.
I ran into it using analytical SQL. My work around is to simply add gunk in between the ORDER and BY tokens.. e.g. (actual snippet from an APEX report query)
row_number() over (order /*--*/ by SUM(bytes) desc) as ORDER_BY_BYTES,
This results in the APEX parser not thinking that the result set is sorted.
You should however raise this issue on the APEX forum here - not really applicable to PL/SQL or SQL or the Oracle RDBMS at all. -
Historicize - Incoming Sales Orders
Hallo,
I extract SD Sales: Document Item data from DataSource 2LIS_11_VAITM into a DSO Document Items.
I should historicize the Incoming Sales Orders.Therefore, I add an additional key (0CALMONTH) (u201CStatistics dateu201D in DS) in the DSO.
New key: order number |item number| 0CALMONTH
In the start-routine I should distinguish the follow cases:
1. New item
If there is a new item (0RECORDMODE=empty), then the fields are mapped 1:1 to DSO. Incoming Sales Order value = Net value of billing item (NTWR).
2. Modify an existing Item
In this Case I get 2 Items from the Source. A Before- image (0RECORDMODE=X), and an After-Image (0RECORDMODE=empty). To determine the Incoming Sales Order value (positive or negative), I must calculate a delta between new and old Incoming Sales Order value.
In addition I have to look, whether it is already a changing in the actual month.
Incoming Sales Order value = Incoming Sales Order value (actual month) + delta( Net value After_image / Net value Before_image).
3. Delete item (0RECORDMODE=R).
Incoming Sales Order value = - Sum (all net values of existing item)
Example:
DSO before:
Order| Item | Calendar month | Net value | Currency
4711 |10__|02.2008________|1.000, 00__| EUR
4711 |10__|03.2008________|200, 00___| EUR
DataPackage:
Record Mode| Order| Item | Statistic date | Net value | Currency
X__________|4711 |10__|02.2008________|1.200, 00__| EUR
empty______|4711 |10__|02.2008________|1.500, 00__| EUR
DSO after:
Order| Item | Calendar month | Net value | Currency
4711 |10__|02.2008________|1.000, 00__| EUR
4711 |10__|03.2008________|500, 00____| EUR
Have anyone a idea, how could i realize it. (Steps).
Thanx CaroAs already described above the KE4F does not solve the problem.
The incompleteness check still shows missing segments, even if they have been created via KE4F.
The only thing that resolves the problem at the moment is the manual change of each position, after KE4F with deleting the segment and creating a new one. But we have many orders with a high number of positions so the manual effort is much too high.
Maybe you are looking for
-
Trying to do a Dynamic Column in a Cursor
So, for lack of a better way to explain it, I need to do the following. I need a EXECUTE IMMEDIATE to be able to use a CURSOR but its saying its not declared. Is their a way to pass the cursor so a Execute Immediate can use it... V_SQL := 'REPLACE(V_
-
Macbook won't recognize iomega back-up drive or camera.
Suddenly, my Macbook will no longer recognize my iomega back-up hard drive or my Canon camera in either USB port. It does, however, recognize a flash drive I use in either port. When I try to do an iomega back up, I get a message that reads: "Time
-
N8 - Why is there no on-screen directional or nump...
Good day, I would like to bring to Nokia's attention a setting that was available in previous units such as the X6, which is the on-screen directional keypad that could be set on or off in the apllications settings under suite settings. Settings>Appl
-
Hi everyone, I bought an iBook G4 (with Airport Card) about 10 months ago. I have dial-up internet with Optus but want to move up to broadband. Specifically "mobile broadband". I want to be able to connect to the internet where ever I am, even on the
-
Transfer of material from RG1 to RG23A Part1
Hi Gurus , here I have a complicated scenario , actually this is client req regarding to captive consumption the scenario is as following they have one finished material say F01( FERT ) , normally they do sell of that material and sometimes they use