Retruning rows which have same value return by RANK function
Hi, what I wanna acheive is to use a DENSE RANK function to identify the same value of the data, if rank values are same then extra out. Here is the code
WITH CTE AS
SELECT SalesPersonID,
SalesQuota,
DENSE_RANK() OVER (ORDER BY SalesQuota DESC) as DENSE_RANK
FROM Sales.SalesPersonQuotaHistory
WHERE SalesQuota BETWEEN 266000.00 AND 319000.00
)This retrun
SalesPersonID SalesQuota DENSE_RANK
280 319000.00 1
287 304000.00 2
280 301000.00 3
282 288000.00 4
283 284000.00 5
287 281000.00 6
278 280000.00 7
283 280000.00 7
283 267000.00 8
278 266000.00 9How could I select those rank value which are same value ??
The result should be
278 280000.00 7
283 280000.00 7
with cte as
select salespersonid,
salesquota,
dense_rank() over (order by salesquota desc) as dr
from sales.salespersonquotahistory
where salesquota between 266000.00 and 319000.00
select *
from (
select cte.*, count(*) over(partition by dr) ct
from cte
where ct > 1
Similar Messages
-
SQL to find grouped rows which have changed values?
Hi,
I am wondering if there is an efficient pure SQL way to do this...?
I have a table that has a number of columns:
InsertionDate
Indentity
Col-a to Col-z - some data.
the pair (InsertionDate, Identity) are unique.
The rows represent the same values as they change over time, for example:
Select * from <mytable> order by Identity, InsertionDate;
InsertionDate Identity Balance
10-Feb-01 1001 -100
11-Feb-01 1001 1
12-Feb-01 1001 50
10-Feb-01 1002 10
11-Feb-01 1002 10
12-Feb-01 1002 76
I want to do the following:
Select from <mytable> where InsertionDate and the next InsertionDate have a different value for Balance 'grouped by' Identity and InsertionDate = "10-Feb-01";
[I use 'grouped by' very cautiously - I cannot explain in "pseudo sql" without using the misleading grouped by term]
To produce the output:
InsertionDate Identity Balance
10-Feb-01 1001 -100
11-Feb-01 1001 1
Select from <mytable> where InsertionDate and the next InsertionDate have a different value for Balance 'grouped by' Identity and InsertionDate = "11-Feb-01";
InsertionDate Identity Balance
11-Feb-01 1001 1
12-Feb-01 1001 50
11-Feb-01 1002 10
12-Feb-01 1002 76
There may be many columns in addition to Balance which also need to be checked for changes.
Cheers,
Karl.Hi, Karl,
One way is to self-join two copies of the table, so you can compare any number of columns from adjacent rows.
For example:
WITH got_r_num AS
SELECT insertiondate, identity, balance
, ROW_NUMBER () OVER ( PARTITION BY identity
ORDER BY insertiondate
) AS r_num
FROM mytable
SELECT a.insertiondate, a.identity, a.balance
FROM got_r_num a
JOIN got_r_num b ON a.identity = b.identity
AND a.r_num IN ( b.r_num + 1
, b.r_num - 1
WHERE a.balance != b.balance
AND TO_DATE ( '11-Feb-2001' -- Use a bind variable if you don't want to hard-code this parameter
, 'DD-Mon-YYYY'
) = LEAST ( a.insertiondate
, b.insertiondate
ORDER BY identity
, insertiondate
;Here, table a is the one to be displayed, and table b contains either the previous or the next row with the same identity.
By the way, whenever you post a question, it really helps if you provide the sample data in a form that people can use to re-create the problem and test their solutions. CREATE TABLE and INSERT statements are best, for example:
CREATE TABLE mytable
( insertiondate DATE
, identity NUMBER (4)
, balance NUMBER
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('10-Feb-2001', 'DD-Mon-YYYY'), 1001, -100);
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('11-Feb-2001', 'DD-Mon-YYYY'), 1001, 1);
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('12-Feb-2001', 'DD-Mon-YYYY'), 1001, 50);
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('10-Feb-2001', 'DD-Mon-YYYY'), 1002, 10);
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('11-Feb-2001', 'DD-Mon-YYYY'), 1002, 10);
INSERT INTO mytable (insertiondate, identity, balance) VALUES (TO_DATE ('12-Feb-2001', 'DD-Mon-YYYY'), 1002, 76);
COMMIT;I'm not sure what you mean by "There may be many columns in addition to Balance which also need to be checked for changes."
Why not post an example that has 1 or 2 columns like balance, and the results you want for that.
At first, this problem sounds like a job for the analytic LAG and/or LEAD functions, but depending on your answer to the last question, that may be very tedious: you'd need a separate function call (maybe even two) for each column, because a function can only return one value, but a join gets all the values at once.
Edited by: Frank Kulash on Jun 11, 2010 10:43 AM -
Please give me idea how I highlight the gird row which have
Sir
I have gird with 5 column
Vno
Code
Dept
Date
Amount
Sir my need is which record have above 5000 amount that color read and other color blue
It means above 5000 highlight in grid
Please give me idea how I highlight the gird row which have above 5000 maount
Thank
aamirPROCEDURE pr_Set_VA (p_VA IN VARCHAR2) IS
v_Feld VARCHAR2 (30);
v_Item VARCHAR2 (61);
v_Block VARCHAR2 (30);
BEGIN
v_Block := :SYSTEM.CURSOR_BLOCK;
v_Feld := Get_Block_Property (v_Block, FIRST_ITEM);
WHILE (v_Feld IS NOT NULL) LOOP
v_Item := v_Block || '.' || v_Feld;
Set_Item_Instance_Property (v_Item, CURRENT_RECORD, VISUAL_ATTRIBUTE, p_VA);
v_Feld := Get_Item_Property (v_Item, NEXTITEM);
END LOOP;
END; -
How can i compare 2 internal table's data which have same structure ?
hi friends,
i want to know how to compare 2 internal table's data which have same structureDATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA: ITAB LIKE TABLE OF LINE,
JTAB LIKE TABLE OF LINE.
DO 3 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
MOVE ITAB TO JTAB.
LINE-COL1 = 10. LINE-COL2 = 20.
APPEND LINE TO ITAB.
IF ITAB GT JTAB.
WRITE / 'ITAB GT JTAB'.
ENDIF.
APPEND LINE TO JTAB.
IF ITAB EQ JTAB.
WRITE / 'ITAB EQ JTAB'.
ENDIF.
LINE-COL1 = 30. LINE-COL2 = 80.
APPEND LINE TO ITAB.
IF JTAB LE ITAB.
WRITE / 'JTAB LE ITAB'.
ENDIF.
LINE-COL1 = 50. LINE-COL2 = 60.
APPEND LINE TO JTAB.
IF ITAB NE JTAB.
WRITE / 'ITAB NE JTAB'.
ENDIF.
IF ITAB LT JTAB.
WRITE / 'ITAB LT JTAB'.
ENDIF.
The output is:
ITAB GT JTAB
ITAB EQ JTAB
JTAB LE ITAB
ITAB NE JTAB
ITAB LT JTAB
This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.
regards,
srinivas
<b>*reward for useful answers*</b> -
How to get the values returned by a function in a drop down?
Hi All,
Can anyone please help in getting the values returned by a function into a drop down? I have a java class file where in i have written a function called getWeeks() which give all the week dates and i want to display these week dates in a drop down box in a JSP page.
Please help me in this regard.
Thanks in Advance!!
Lakshman.Hi Lakshman,
the following code can help you do what you want :
<hbj:dropdownListBox id="calendar" tooltip="Calendar" selection="<%= selected %>">
<%
String[] weeks = myObjectBean.getWeeks();
for (int i = 0; i < weeks.length; i++) {
%>
<hbj:listBoxItem key="<%= i %>" value="<%= weeks<i> %>"/>
<%
%>
</hbj: dropdownListBox>
The <%= selected %> snippet allows you to pre-select one of the options (provided that the variable 'selected' is equal to one of the listBoxItem keys).
You can also add onSelect to the tag (e.g. = "setSelectedItem"). It corresponds to a method in the corresponding JSPDynPage class. This means that when you select another item in the dropdown list, the method in your Java class is performed (allowing you to save the selected value and performing actions with it)
I hope this helped you enough,
kind regards,
Frederic
Edited seven times by: Frederic Taes on Nov 5, 2008 11:24 AM -> the onSelect element was in the hbj tag and in the text with "='setSelectedItem'" next to it and when I tried to post my message, I got a 501 error all the time ! Seems like a SDN bug to me ... -
How to find different rows in two tables which have same schema.
There are two tables t1 and t2, they have same schema. Table t1 includes the informtion of students last month,table t2 incude the information of the students this month. I want to find the difference of the same student between two months. What should I do and How to do?
Look a the following example:
Table TEST_1 TEST_2
ID ID_TX ID ID_TX
1 a 1 a
2 b 2 b
4 d 4 d
6 f 6 f
7 g 7 g
10 j 10 j
10 Z 10 x --- DIFFERENT
12 x --- DIFFERENT
20 x ---- DIFFERENT
Query:
Select * FROM
( (SELECT '1', ID, ID_TXT FROM TEST_1 MINUS SELECT '1', ID, ID_TXT FROM TEST_2)
UNION
(SELECT '2', ID, ID_TXT FROM TEST_2 MINUS SELECT '2', ID, ID_TXT FROM TEST_1) )
Order By ID
RESULTS:
' ID ID_TXT
1 10 Z
2 10 x
1 12 x
2 20 x -
In a XSD, can a element's name & type attributes have same value ?
Hi,
Can i have a same value for the name & type attributes of an Element. For ex: in below XSD, the element 'ChildEL' has the same value('ChildEL') for the type attributes as the name('ChildEL') ?
I am asking this because when i generate Java Classes using Castor Source Code generator using this XSD has input, the output classes do NOT compile since the class ChildEL inherits itself and which causes the cyclic inheritance. Please help.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="ParentEL" type="ParentELType"/>
<xs:complexType name="ParentELType">
<xs:sequence>
<xs:element name="ChildEL" type="ChildEL" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="CreationDate" type="xs:dateTime"/>
</xs:complexType>
<xs:complexType name="ChildEL">
<xs:sequence>
<xs:element name="Type" type="xs:string/>
<xs:element name="ID" type="xs:string/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Thanks,
ManojI figured out that this is possible and to avoid the compilation error in Castor source code generator is to set the property org.exolab.castor.builder.javaclassmapping=type in castorbuilder.properties config file.
-
How to all those set of records for which a given field have same value.
Hi,
I've a table
T1 as
id val
1 A
2 B
3 A
4 C
5 D
6 A
7 D
Now i want to write a query that'll return only those val for which there r more than one existence of val.
result desired is:
val count(val)
A 3
D 2
Thanks
AmiteshThis?
SQL> select * from t;
ID VAL
1 A
2 B
3 A
SQL> select val,count(*) c
2 from t
3 group by val
4 having count(*) > 1;
VAL C
A 2
Message was edited by:
jeneesh -
Column is summing up all the rows and displaying same value in all rows.
Hi,
Kindly see the below query. I have a problem in this query to fetch the abs_qty when the parameter P:item ie)msib.segment1 is not given as the input parameter. Its just summing up the entire quantity for all the items.When I pass P:item ie)msib.segment1 as input parameter, It fetches the exact value for abs_qty. Kindly help me to resolve this.
Note only : Manufacturing plant ,Start date and End Date are Mandatory(required) parameters. Others like Item,Base Model and Planner code are optional.
SELECT mmt.transaction_date date_produced, msib.segment1 item,
cic.cost_type_id, msib.description item_description,
mc.segment6 base_model, mc.segment7 trade_brand,
mmt.subinventory_code subinventory,
mil.segment1 || '.' || mil.segment2 || '.' || mil.segment3 LOCATOR,
ood.organization_code
|| '-'
|| ood.organization_name manufacturing_plant,
mmt.transaction_quantity quantity_produced,
mtt.transaction_type_name transaction_type, msib.inventory_item_id,
msib.organization_id, cic.material_cost COST,
cic.material_overhead_cost freight, csc.standard_cost,
*(select (NVL((SELECT SUM (mmt.transaction_quantity) total_NET_qty*
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND mmt.organization_id = ood.organization_id
AND mtt.transaction_type_name = 'WIP Completion'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date
AND :p_end_date ),0)
*(NVL((SELECT SUM (mmt.transaction_quantity) total_NET_qty*
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND mmt.organization_id = ood.organization_id
AND mtt.transaction_type_name = 'WIP Issue'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date
AND :p_end_date
*),0))) abs_qty from dual) AS ABS_qtyy,*(select (NVL((SELECT SUM (mmt.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND mmt.organization_id = ood.organization_id
AND mtt.transaction_type_name = 'WIP Completion'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date
AND :p_end_date ),0)
(NVL((SELECT SUM (mmt.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND mmt.organization_id = ood.organization_id
AND mtt.transaction_type_name = 'WIP Issue'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date
AND :p_end_date
),0))) abs_qty from dual)*csc.standard_cost AS abs_val
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_item_locations mil,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts,
mtl_categories mc,
mtl_item_categories mic,
mtl_category_sets mcs,
cst_item_costs cic,
cst_standard_costs csc,
cst_cost_types ct,
mfg_lookups mlo
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.locator_id = mil.inventory_location_id
AND mil.organization_id = msib.organization_id
AND mil.subinventory_code = mmt.subinventory_code
AND mmt.transaction_type_id = mtt.transaction_type_id
AND msib.organization_id = ood.organization_id
AND mic.category_set_id = mcs.category_set_id
AND mc.category_id = mic.category_id
AND mc.structure_id = mcs.structure_id
AND mic.inventory_item_id = msib.inventory_item_id
AND mic.organization_id = msib.organization_id
AND mcs.category_set_id = 52487965
AND msib.inventory_item_id = cic.inventory_item_id
AND msib.organization_id = cic.organization_id
AND ct.cost_type_id = cic.cost_type_id
AND cic.organization_id = ood.organization_id
AND mil.inventory_location_id = mmt.locator_id
AND mmt.transaction_source_type_id = mtt.transaction_source_type_id
AND mmt.transaction_action_id = mtt.transaction_action_id
AND mmt.transaction_source_type_id = mts.transaction_source_type_id
AND mmt.transaction_action_id = mlo.lookup_code
AND mmt.inventory_item_id = csc.inventory_item_id
AND mmt.organization_id = csc.organization_id
AND csc.last_update_date >=
(SELECT MAX (csc1.last_update_date)
FROM cst_standard_costs csc1
WHERE csc1.inventory_item_id = mmt.inventory_item_id
AND csc1.organization_id = mmt.organization_id)
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND NVL (mc.segment6, 'X') = NVL (:p_base_model, NVL (mc.segment6, 'X'))
AND NVL (msib.planner_code, 'Y') =
NVL (:p_planner_code, NVL (msib.planner_code, 'Y'))
AND UPPER (mlo.meaning) = 'ASSEMBLY COMPLETION'
AND mtt.transaction_type_name = 'WIP Completion'
AND ct.cost_type = 'Frozen'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date AND :p_end_dateIf <tt>abs_qty</tt> and consequently <tt>abs_val</tt> should not be the same for all rows returned, you'll have to rewrite your query so that the <tt>abs_qty</tt> won't be computed in isolation (separately) with no interaction with data from the main from table list.
Your query is treated the same as the one below (note the changed table aliases by appending numbers to the originals of yours)
SELECT mmt.transaction_date date_produced,
msib.segment1 item,
cic.cost_type_id,
msib.description item_description,
mc.segment6 base_model,
mc.segment7 trade_brand,
mmt.subinventory_code subinventory,
mil.segment1 || '.' || mil.segment2 || '.' || mil.segment3 LOCATOR,
ood.organization_code || '-' || ood.organization_name manufacturing_plant,
mmt.transaction_quantity quantity_produced,
mtt.transaction_type_name transaction_type,
msib.inventory_item_id,
msib.organization_id,
cic.material_cost COST,
cic.material_overhead_cost freight,
csc.standard_cost,
(select (NVL(
(SELECT SUM (mmt1.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt1,
mtl_system_items_b msib1,
mtl_transaction_types mtt1,
org_organization_definitions ood1,
mtl_txn_source_types mts1
WHERE mmt1.organization_id = msib1.organization_id
AND msib1.inventory_item_id = mmt1.inventory_item_id
AND mmt1.transaction_type_id = mtt1.transaction_type_id
AND mmt1.organization_id = ood1.organization_id
AND mtt1.transaction_type_name = 'WIP Completion'
AND mts1.transaction_source_type_name = 'Job or Schedule'
AND msib1.segment1 = NVL (:p_item, msib1.segment1)
AND ood1.organization_code = :p_manufacturing_plant
AND TRUNC (mmt1.transaction_date) BETWEEN :p_start_date AND :p_end_date
),0
) - NVL(
(SELECT SUM (mmt2.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt2,
mtl_system_items_b msib2,
mtl_transaction_types mtt2,
org_organization_definitions ood2,
mtl_txn_source_types mts2
WHERE mmt2.organization_id = msib2.organization_id
AND msib2.inventory_item_id = mmt2.inventory_item_id
AND mmt2.transaction_type_id = mtt2.transaction_type_id
AND mmt2.organization_id = ood.2organization_id
AND mtt2.transaction_type_name = 'WIP Issue'
AND mts2.transaction_source_type_name = 'Job or Schedule'
AND msib2.segment1 = NVL (:p_item, msib2.segment1)
AND ood2.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.2transaction_date) BETWEEN :p_start_date AND :p_end_date
),0
) abs_qty
from dual
) AS ABS_qtyy,
(select (NVL(
(SELECT SUM (mmt3.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt3,
mtl_system_items_b msib3,
mtl_transaction_types mtt3,
org_organization_definitions ood3,
mtl_txn_source_types mts3
WHERE mmt3.organization_id = msib3.organization_id
AND msib3.inventory_item_id = mmt3.inventory_item_id
AND mmt3.transaction_type_id = mtt3.transaction_type_id
AND mmt3.organization_id = ood3.organization_id
AND mtt3.transaction_type_name = 'WIP Completion'
AND mts3.transaction_source_type_name = 'Job or Schedule'
AND msib3.segment1 = NVL (:p_item, msib3.segment1)
AND ood3.organization_code = :p_manufacturing_plant
AND TRUNC (mmt3.transaction_date) BETWEEN :p_start_date AND :p_end_date
),0
) - NVL(
(SELECT SUM (mmt4.transaction_quantity) total_NET_qty
FROM mtl_material_transactions mmt4,
mtl_system_items_b msib4,
mtl_transaction_types mtt4,
org_organization_definitions ood4,
mtl_txn_source_types mts4
WHERE mmt4.organization_id = msib4.organization_id
AND msib4.inventory_item_id = mmt4.inventory_item_id
AND mmt4.transaction_type_id = mtt4.transaction_type_id
AND mmt4.organization_id = ood4.organization_id
AND mtt4.transaction_type_name = 'WIP Issue'
AND mts4.transaction_source_type_name = 'Job or Schedule'
AND msib4.segment1 = NVL (:p_item, msib4.segment1)
AND ood4.organization_code = :p_manufacturing_plant
AND TRUNC (mmt4.transaction_date) BETWEEN :p_start_date AND :p_end_date
),0
) abs_qty
from dual
) * csc.standard_cost AS abs_val
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_item_locations mil,
mtl_transaction_types mtt,
org_organization_definitions ood,
mtl_txn_source_types mts,
mtl_categories mc,
mtl_item_categories mic,
mtl_category_sets mcs,
cst_item_costs cic,
cst_standard_costs csc,
cst_cost_types ct,
mfg_lookups mlo
WHERE mmt.organization_id = msib.organization_id
AND msib.inventory_item_id = mmt.inventory_item_id
AND mmt.locator_id = mil.inventory_location_id
AND mil.organization_id = msib.organization_id
AND mil.subinventory_code = mmt.subinventory_code
AND mmt.transaction_type_id = mtt.transaction_type_id
AND msib.organization_id = ood.organization_id
AND mic.category_set_id = mcs.category_set_id
AND mc.category_id = mic.category_id
AND mc.structure_id = mcs.structure_id
AND mic.inventory_item_id = msib.inventory_item_id
AND mic.organization_id = msib.organization_id
AND mcs.category_set_id = 52487965
AND msib.inventory_item_id = cic.inventory_item_id
AND msib.organization_id = cic.organization_id
AND ct.cost_type_id = cic.cost_type_id
AND cic.organization_id = ood.organization_id
AND mil.inventory_location_id = mmt.locator_id
AND mmt.transaction_source_type_id = mtt.transaction_source_type_id
AND mmt.transaction_action_id = mtt.transaction_action_id
AND mmt.transaction_source_type_id = mts.transaction_source_type_id
AND mmt.transaction_action_id = mlo.lookup_code
AND mmt.inventory_item_id = csc.inventory_item_id
AND mmt.organization_id = csc.organization_id
AND csc.last_update_date >= (SELECT MAX (csc1.last_update_date)
FROM cst_standard_costs csc1
WHERE csc1.inventory_item_id = mmt.inventory_item_id
AND csc1.organization_id = mmt.organization_id
AND msib.segment1 = NVL (:p_item, msib.segment1)
AND NVL (mc.segment6, 'X') = NVL (:p_base_model, NVL (mc.segment6, 'X'))
AND NVL (msib.planner_code, 'Y') = NVL (:p_planner_code, NVL (msib.planner_code, 'Y'))
AND UPPER (mlo.meaning) = 'ASSEMBLY COMPLETION'
AND mtt.transaction_type_name = 'WIP Completion'
AND ct.cost_type = 'Frozen'
AND mts.transaction_source_type_name = 'Job or Schedule'
AND ood.organization_code = :p_manufacturing_plant
AND TRUNC (mmt.transaction_date) BETWEEN :p_start_date AND :p_end_dateRegards
Etbin -
How to determine how many times result set columns have same value
Hi -
I'm doing a report which will be used for payment trend analyses.
My initial result set looks like this:
HOUSEHOLD_ID JAN_PMT FEB_PMT MAR_PMT APR_PMT MAY_PMT JUN_PMT JUL_PMT AUG_PMT SEP_PMT OCT_PMT NOV_PMT DEC_PMT
90026845409 1 1 1 1 2 1 1 1 1 0 1 0(many rows, of course; result set pivoted)
I need to determine the households that have a > 0 value in three or more consecutive months.
I'm hoping someone will have some suggestions because the only solutions I'm coming up with right now would be a coding nightmare (lots of "OR's"), and I'm assuming (hoping) there's a better solution out there.
Thanks!
ChristineHi Frank,
I'm not sure I'm understanding how I would use those analytic functions. Here is my select statement:
SELECT HOUSEHOLD_ID,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS JAN_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS FEB_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS MAR_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS APR_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS MAY_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS JUN_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS JUL_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS AUG_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS SEP_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS OCT_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS NOV_PMT,
SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6 )
THEN 1 ELSE 0 END) AS DEC_PMT
FROM MONETARY_TRANS
WHERE MONETARY_TRANS_TYPE_ID = 1 --payment
--TESTING
AND HOUSEHOLD_ID = 90026845409
AND RESPONSIBLE_PARTY_TYPE_ID = 1 --household
AND RECEIVED_DATE > '01-JAN-2008'
AND ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6
OR TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 )
AND PREMIUM_AMOUNT > 0
AND BILLING_TRANS_TYPE_ID = 6
AND MONETARY_TRANS_TYPE_ID = 1
AND RESPONSIBLE_PARTY_TYPE_ID = 1
GROUP BY HOUSEHOLD_IDAnd from this I get the results originally posted. From there I need to figure out the households that have values greater than 0 for three or more consecutive months.
Thanks for your help........
-Christine -
Different tables' column have same value
Hi,
How to find out which coulmns in database are stoing a value. ex: 'Tier'
I need to know different table's column in database have value 'Tier'.
table1.col1 ='Tier'
table2.col16='Tier'
table3.col21='Tier'Thanks
SandyOne possible solution is below. Take care with the performance, as the procedure is checking every schema.table.column VARCHAR ou CHAR. The number of columns can easily go to thousands and affect the overall performance of your DBMS.
The example is explicitlly avoiding tables in schema SYS and SYSDBA.
set serveroutput on size 999999
declare
cnt number;
sql_comm varchar2(1000);
begin
for TRec in (select owner, table_name, column_name, data_length
from all_tab_columns
where data_type IN ('VARCHAR2', 'CHAR')
and owner not in ('SYS', 'SYSTEM')
and data_length >= 4
order by 1, 2, 3) loop
sql_comm := 'select count(*) from '||TRec.owner||'.'||TRec.table_name||' where '||TRec.column_name||'= ''Tier''';
execute immediate sql_comm into cnt;
if cnt>0 then
dbms_output.put_line(TRec.owner||'.'||TRec.table_name||'.'||TRec.column_name||' has '||cnt||' rows.');
end if;
end loop;
end;
Miguel -
Parallel process with reentrant VI have same value in both threads
Has it been so long since I programmed LabVIEW that I forgot some basic stuff??
I have a main VI which originally called dynamic processes in parallel.
I then called the sub-vi's dirtectly and still run them in parallel, but thwey now have seperate names.
I use a QSM. Each parallel thread now has it's own QSM, because although I was using a Queue Name for each dynamic queue, the data that was being extracted was shared or done between the two threads. If I confused everyone with the statement, I shall explain.
Two parallel processes, calling a QSM (re-entrant). They have the same number of elements and matching sets.
EX:
Process 1 Process 2
Task1 Task1
Task2 Task2
Task3 Task3
Task4 Task4
Task5 Task5
Task6 Task6
I was expecting each thread (each process) to extract from the queue the list of tasks as entered (from Task1 to Task6). What the processes were getting was the following:
Process 1 Process 2
Task1 Task1
Task2 Task3
Task4 Task5
Task6 default
Each Process was sending a different Queue Name to the QSM. Each queue should have it's own name.
I need to get this running by tomorrow with no excuse! So I decided to do a lame workaround by also having 2 QSMs. That fixed it..
In each parallel process (which are a copy of each other with different names) there is a call to open a telnet session. I probed and placed breakpoints in the code. Although each process has a different name and the call to the function that opens the telnet session is re-entrant, the very same telnet reference number is assigned to both processes.
Why? Why would they get the same reference number? I made all vi's down to (and including) Telnet Open Connection as re-entrant (although it was not needed) and it still assigns the same reference number to each telnet session. Why? What I am not seeing? What am I missing?
Unfortunately, I cannot post the code.. But it is not complicated code. Just 2 sessions with different IP addresses. I would expect different telnet session references...
As a matter of fact, I need to try something silly..I should provide more details with the solution....
I just have to stop saying "D'Oh!!"
Okay... here goes...
In the LVOOP, I am using Notifiers and Semaphores to ensure that a race condition cannot occur. Works well with previously written code.
In this particular implementation, I have the same / similar object being created more than once (twice at this time).
Where I went wrong (D'Oh!!!!), was to have a static name for a given object when creating the Notifier and Semaphore references. Since the same name was given, so was the reference. SInce the references were the same, so was the data, and so on.
D'Oh!!!!!!
D'Oh!!!!!!
Now I know why a particular bird was called D'Oh-D'Oh bird...
D'Oh!!! Such a silly mistake...
D'Oh!!!
Hope it makes a few people laugh... or help another bird.... -
Consolidation between co. codes, which have same COA and controlling area
I have 4 co. codes, which is having same Chart of accounts, same controlling area. And all co. codes assigned to one company. What is the process of consolidation to make the consolidation.
Sorry,
You have all co codes under one company, why dont you try to run a GL report from that "one company"?
Did I got you wrong?
Regards
Lameck -
Doubt in the value return by the function based on given condition
Hi,
Below function should return the value based on the value of in_row_number_high variable.
I have used CASE but it does't return proper value.
How could I give that condition?
Please help.
FUNCTION gen_total_lane_count_pct
in_lane_id edr_rpt_by_ranges_output.lane_id%TYPE,
in_direction_id edr_rpt_by_ranges_output.direction_id%TYPE,
in_interval_start_date_time edr_rpt_by_ranges_output.interval_start_date_time%TYPE,
in_interval_end_date_time edr_rpt_by_ranges_output.interval_end_date_time%TYPE,
in_row_number edr_rpt_by_ranges_output.range_low%TYPE,
in_row_number_high edr_rpt_by_ranges_output.range_high%TYPE,
in_lane_min edr_lane_by_class_report_data.v_lane%TYPE,
in_lane_max edr_lane_by_class_report_data.v_lane%TYPE
RETURN NUMBER
IS
my_total NUMBER(18);
my_count_pct NUMBER(18);
my_total_pct NUMBER(18);
my_each_count_result NUMBER(18);
my_count_result NUMBER(18);
my_total_count NUMBER(18);
lane_start edr_rpt_tmp_report_lanes.site_lane_id%TYPE;
lane_end edr_rpt_tmp_report_lanes.site_lane_id%TYPE;
row_start NUMBER(12);
row_end NUMBER(12);
BEGIN
my_count_pct := 0 ;
SELECT MIN(site_lane_id)
INTO lane_start
FROM edr_rpt_tmp_report_lanes
WHERE edr_rpt_tmp_report_lanes.output_lane_id = in_lane_id
AND edr_rpt_tmp_report_lanes.output_direction_id = in_direction_id;
SELECT MAX(site_lane_id)
INTO lane_end
FROM edr_rpt_tmp_report_lanes
WHERE edr_rpt_tmp_report_lanes.output_lane_id = in_lane_id
AND edr_rpt_tmp_report_lanes.output_direction_id = in_direction_id;
SELECT MIN(range_low)
INTO row_start
FROM edr_rpt_by_ranges_output;
SELECT MAX(range_low)
INTO row_end
FROM edr_rpt_by_ranges_output;
my_each_count_result := edr_rpt_lane_by_class_package.gen_total_lane_count (
in_lane_id,
in_direction_id,
in_interval_start_date_time,
in_interval_end_date_time,
in_row_number,
in_row_number_high,
in_lane_min,
in_lane_max
my_count_result := edr_rpt_lane_by_class_package.gen_total_lane_count (
in_lane_id,
in_direction_id,
in_interval_start_date_time,
in_interval_end_date_time,
row_start,
row_end,
in_lane_min,
in_lane_max
my_total_count := edr_rpt_lane_by_class_package.gen_total_lane_count (
in_lane_id,
in_direction_id,
in_interval_start_date_time,
in_interval_end_date_time,
in_row_number,
in_row_number_high,
lane_start,
lane_end
IF (my_each_count_result > 0) THEN
my_total := edr_rpt_lane_by_class_package.gen_total_lane_count (
in_lane_id,
in_direction_id,
in_interval_start_date_time,
in_interval_end_date_time,
row_start,
row_end,
lane_start,
lane_end
CASE
WHEN in_row_number_high = row_end THEN
my_count_pct := ROUND((my_each_count_result / my_count_result ) * 100 );
WHEN in_row_number_high < row_end THEN
my_count_pct := ROUND((my_each_count_result / my_total ) * 100 ) ;
ELSE
RAISE_APPLICATION_ERROR(-20101, 'The row number specified is not recognized.');
END CASE;
END IF;
return my_count_pct;
END gen_total_lane_count_pct; Edited by: Indhu Ram on Jan 5, 2010 11:43 AMHi,
I have to find out the % value for each column value( For rx if there is only 2 columns).To calculate the % , each column value should get divided by the total of that column value.
To calculate the % for the total row , each column total should get divide by the sum of column ( sum of column 1 + sum of column 2)values.
ROUND((my_each_count_result / my_count_result ) * 100 ) ---- This calculaton gives me the % for the total row.
ROUND((my_each_count_result / my_total ) * 100 ) ------- This calculation gives the % for the data row.
The condition that I have tried is, if it reaches end of data row (to achieve that condition I have given this condition in_row_number_high < row_end )
Now my result returns only values based on this condition -- in_row_number_high < row_end .
It does't look for the first condition.
CASE
WHEN in_row_number_high = row_end THEN
my_count_pct := ROUND((my_each_count_result / my_count_result ) * 100 );
WHEN in_row_number_high < row_end THEN
my_count_pct := ROUND((my_each_count_result / my_total ) * 100 ) ;
ELSE
RAISE_APPLICATION_ERROR(-20101, 'The row number specified is not recognized.');
END CASE;
Hope , you have some good understanding now. Please help me how could I do this? -
How to compare a boolean value returned from a function in a sql query
Hi all
i have a function which return boolean true or false.
mean while i am writing a sql query which should check this function and will return a result set only when it is true. how will i use a function which returns boolean in a sql query..
thanks in advance'
HariI don't think this is possible - i'm not sure. Can you post your function script? The reason why am i asking this is --
satyaki>set serveroutput on
satyaki>
satyaki>
satyaki>
satyaki>create or replace function test_satf(emno in number)
2 return boolean
3 is
4 v_cnt number(5);
5 v_flg boolean;
6 begin
7 select count(*)
8 into v_cnt
9 from emp
10 where empno = emno;
11
12 if v_cnt = 1 then
13 v_flg := TRUE;
14 else
15 v_flg := FALSE;
16 end if;
17
18 return v_flg;
19 exception
20 when others then
21 v_flg := FALSE;
22 return v_flg;
23 end;
24 /
Function created.
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>desc emp;
Name Null? Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
satyaki>
satyaki>
satyaki>
satyaki>select count(*) from emp;
COUNT(*)
14
satyaki>
satyaki>select empno,test_satf(empno)
2 from emp;
select empno,test_satf(empno)
ERROR at line 1:
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-382: expression is of wrong type
satyaki>select to_char(test_satf(empno))
2 from emp;
select to_char(test_satf(empno))
ERROR at line 1:
ORA-06552: PL/SQL: Statement ignored
ORA-06553: PLS-382: expression is of wrong type
satyaki>
satyaki>create or replace function test_satf(emno in number)
2 return varchar2
3 is
4 v_cnt number(5);
5 v_flg varchar2(10);
6 begin
7 select count(*)
8 into v_cnt
9 from emp
10 where empno = emno;
11
12 if v_cnt = 1 then
13 v_flg := 'TRUE';
14 else
15 v_flg := 'FALSE';
16 end if;
17
18 return v_flg;
19 exception
20 when others then
21 v_flg := 'FALSE';
22 return v_flg;
23 end;
24 /
Function created.
satyaki>
satyaki>
satyaki>select test_satf(empno)
2 from emp;
TEST_SATF(EMPNO)
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TRUE
TEST_SATF(EMPNO)
TRUE
TRUE
TRUE
14 rows selected.Or, may be i'm missing something.
Regards.
Satyaki De.
Maybe you are looking for
-
Is lost data retrievable on a Solid-State Drive (SSD)?
Since a SSD is only RAM, I'm wondering if data is retrievable once a file is deleted just like on a conventional hard disk drive. Then if data is truly retrievable, how to make these deleted files for ever? Do you need to use the same techniques foun
-
Source Filename to XML with File Adapter
Hi, I need to insert the filename in the XML structure when the file is read by File Sender Adapter (FTP). Example <document> <filename>file_200602081000.dat</filename> <record> <row> <line>Line 1</line> <line>Line 2</line> </
-
ITunes 7 icon not showing in windows
I noticed that the iTunes 7 icon becomes a blank box as if the program is missing. However when I click it the program does start. I don't even have the option to investigate or assign an icon manually as in the properties dialog box unlike other pro
-
Pre-fader TRIM in logic?
pro tools has a pre-fader TRIM plug-in... with it, you can attenuate a track BEFORE it hits a plug in. does anyone know if there is an equivalent in Logic Express 7.1? just bringing the fader down a bit doesn't work, because (as I understand it) all
-
Working with 'nibbles' in java
Hi, Im storing values in bytes containing two nibbles (4 bits) packed into a vector of bytes. I have two values between 0 and 15 for each nibble, I create two bytes and set each value to these, I then shift the first byte 4 places and and add the res