Getting Top N Value using SQL
There are thousands of records in a table. The table has column TOTAL_NUMBER. I want to find the top 3rd using the column TOTAL_NUMBER. How can I do this using SQL?
Google:
Using RANK() to Obtain a Top-N Query
To obtain a top-N query, use RANK() in a subquery and then apply a filter condition outside the subquery:
SELECT Empno, Ename, Job, Mgr, Hiredate, Sal
FROM
(SELECT Empno, Ename, Job, Mgr, Hiredate, Sal,
RANK() OVER
(ORDER BY SAL Desc NULLS LAST) AS Emp_Rank
FROM Emp
ORDER BY SAL Desc NULLS LAST)
WHERE Emp_Rank < 6;
Similar Messages
-
How to Get Top 10 records using SQL select statement.
:-) Hiee E'body,
I want to generate a sql report in which I only want the top 10 records based on the numeric value of a column.
For Example,
To generate a Location Wise, Employee Wise Years of Service Report.
Here I need the Top 10 Employees according to their No. of Years of Service for all the existing locations using a single query.
eg.
Location Emp No. YOS
India - 22 30
212 28
819 24 ...
US 123 40
312 33
90 33
144 30 ...
UK 77 20
79 20
331 18
109 16 ...
Every Location should display their respective Top 10 Employees
regarding their No. of Years of Service.
Please let me the know the solution to this.
Have a nice day.
Thanking You,
Vivek Kapoor.For example if the table contained (India rows only shown) :
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
India 928 13
India 929 13
India 930 12
do you want to see
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
or
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
India 928 13
India 929 13
Also if the India rows were
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
India 928 30
India 929 30
do you want to see
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
or
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
India 928 30
India 929 30
Please clarify.
Thanks,
Partha -
Default form value using sql with bind variable
I wish to create a form based upon a table with a foreign key. I wish to add a field to the form that is an uneditable text field with a default value using sql of 'select name from other_table where other_table_id = ?' where ? is a bind variable defined by a hidden field which is the value of the foreign key identified at runtime. How can this be done?
nullI don't think that will work. I have multiple people accessing the Portal at the same time with the same login (or lack of as public will be the most common user). I could set it easily enough as the value is passed to the form by a link object, so I could add it to the before page plsql block and set the value. But I am uncertain how it will behave in a multi-user mutlitasking environment.
Maybe I should describe what I am looking to accomplish. I want to create a display above a form that will list static details from other tables (i.e. when editing a user's phone number, which is in one table, you want the user to see the person's name, which is in another table, and the form is based upon the phone table) ...
Just as I am thinking about it, I thought of an idea. I could put some specific code in the before displaying page plsql section to query the database and use htp to output the information for data not in the table the form is based upon. I will try this and see how it works. It would have been nice to have just created a field that is not editable and had a default value, but this should work as well.
Let me know if you see any problem with this or if you have any better suggestions.
Thanks for the fast response. -
How to get Metadata column values using powershell(CSOM)
Hi,
I am trying to get list column values using Powershell (CSOM), but I am getting for Metata data columns.
I am getting internal value as System.Collections.Generic.Dictionary`2[System.String,System.Object]
Can anybody let me know how to get the values for metadata columns?
Any help would be greatly appreciate.
Thank you.
AA.Hi
Go through the links. It'll help.
SharePoint 2013 Code Tips – Setting a Managed Metadata Field with the Client Object Model(CSOM and JSOM)
Indul Hassan
Microsoft Community Contributor
http://www.indulhassan.com
You Snooze.. You Lose !! -
How to get STPOV structure values using BOM number and Plant number
hello All,
could you please help me out
'How to get STPOV structure values using BOM number and Plant number'
is there any function module where can i give input as bom and plant number .
waiting for your response.
regards
srinivasI did a quick where-used lookup in SE11 on the structure STPOV in function module interfaces and came up with the following:
Function Module Short Description
CK_F_TOTALCOST_COMPUTE
CS_ALT_SELECT_COUPLED_PRODUCT
CS_WHERE_USED_CLA Bills of material; class use
CS_WHERE_USED_CLA_ANY Bills of material; direct class use or via other class
CS_WHERE_USED_CLA_VIA_CLA Bills of material; class use via classes
CS_WHERE_USED_COP
CS_WHERE_USED_DOC Bills of material; document use
CS_WHERE_USED_DOC_ANY:Bills of material; direct and (indirectly) document use via
CS_WHERE_USED_DOC_VIA_CLA Bills of material; document use via classes
CS_WHERE_USED_KNO Bills of material; use object dependency
CS_WHERE_USED_MAT Bills of material; where-used list
CS_WHERE_USED_MAT_ANY:Bills of material; where-used list as article or class item
CS_WHERE_USED_MAT_VIA_CLA Bills of material; where-used list via classes
EXIT_SAPMC29M_001 BOM; Article Where-Used List
It appears that this structure is primarily used for where-used look-ups for components within the BOM. I don't know if any of these are what you're in need of.
Hope this helps,
Mark Schwendinger -
How to get top 11 values per date range
I want to get the top 11 values by date range.
Sample Data
CREATE TABLE SAMPLE_DATA
DOMAIN_NAME VARCHAR2(100),
QTD NUMBER,
LOAD_DATE DATE
-- Insert
BEGIN
FOR lc IN 1..20
LOOP
FOR ld IN 1..30
LOOP
INSERT
INTO SAMPLE_DATA VALUES
'DM_'
||lc,
round(dbms_random.value(0,1000)),
SYSDATE-ld
END LOOP;
END LOOP;
COMMIT;
END;
SELECT *
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM SAMPLE_DATA
WHERE LOAD_DATE = TRUNC(SYSDATE-3)
ORDER BY QTD DESC
WHERE ROWNUM <=10
UNION ALL
SELECT 'Others' DOMAIN_NAME,
SUM(QTD) QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT rownum rn,
DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM SAMPLE_DATA
WHERE LOAD_DATE = TRUNC(SYSDATE-3)
ORDER BY QTD DESC
WHERE rn > 10
GROUP BY LOAD_DATE
ORDER BY QTD DESC
-- Result
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/13
DM_1 1000 24/03/13
DM_20 933 24/03/13
DM_11 913 24/03/13
DM_3 743 24/03/13
DM_13 572 24/03/13
DM_12 568 24/03/13
DM_9 564 24/03/13
DM_6 505 24/03/13
DM_5 504 24/03/13
DM_2 480 24/03/13
Please, Help me get in one query this result using a range of date.
e.g
using LOAD_DATE BETWEEN '24/03/13' AND '25/03/13'
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/13
DM_1 1000 24/03/13
DM_20 933 24/03/13
DM_11 913 24/03/13
DM_3 743 24/03/13
DM_13 572 24/03/13
DM_12 568 24/03/13
DM_9 564 24/03/13
DM_6 505 24/03/13
DM_5 504 24/03/13
DM_2 480 24/03/13
Others 1948 25/03/13
DM_1 807 25/03/13
DM_8 764 25/03/13
DM_7 761 25/03/13
DM_11 656 25/03/13
DM_18 611 25/03/13
DM_17 523 25/03/13
DM_14 467 25/03/13
DM_19 447 25/03/13
DM_15 437 25/03/13
DM_6 380 25/03/13 Thank you in advance.I got the solution. Just sharing.
I used analytic functions that make my job easy.
Sample Data
DOMAIN_NAME QTD LOAD_DATE
DM_1 807 25/03/2013
DM_1 1000 24/03/2013
DM_2 226 25/03/2013
DM_2 480 24/03/2013
DM_3 244 25/03/2013
DM_3 743 24/03/2013
DM_4 48 25/03/2013
DM_4 413 24/03/2013
DM_5 164 25/03/2013
DM_5 504 24/03/2013
DM_6 380 25/03/2013
DM_6 505 24/03/2013
DM_7 761 25/03/2013
DM_7 212 24/03/2013
DM_8 764 25/03/2013
DM_8 308 24/03/2013
DM_9 354 25/03/2013
DM_9 564 24/03/2013
DM_10 214 25/03/2013
DM_10 367 24/03/2013
DM_11 656 25/03/2013
DM_11 913 24/03/2013
DM_12 37 25/03/2013
DM_12 568 24/03/2013
DM_13 332 25/03/2013
DM_13 572 24/03/2013
DM_14 467 25/03/2013
DM_14 87 24/03/2013
DM_15 437 25/03/2013
DM_15 450 24/03/2013
DM_16 238 25/03/2013
DM_16 299 24/03/2013
DM_17 523 25/03/2013
DM_17 143 24/03/2013
DM_18 611 25/03/2013
DM_18 145 24/03/2013
DM_19 447 25/03/2013
DM_19 464 24/03/2013
DM_20 91 25/03/2013
DM_20 933 24/03/2013 Top 11 QTD of DOMAIN_NAME per Data Range.
SELECT *
FROM
(SELECT DOMAIN_NAME,
QTD,
LOAD_DATE
FROM
(SELECT LOAD_DATE,
DOMAIN_NAME ,
QTD,
(DENSE_RANK() OVER (PARTITION BY LOAD_DATE ORDER BY QTD DESC )) AS RANK_QTD
FROM SAMPLE_DATA
WHERE trunc(load_date) BETWEEN '24/03/2013' AND '25/03/2013'
WHERE RANK_QTD <= 10
UNION ALL
SELECT 'Others',
SUM(QTD) AS QTD,
LOAD_DATE
FROM
(SELECT LOAD_DATE,
DOMAIN_NAME ,
QTD,
(DENSE_RANK() OVER (PARTITION BY LOAD_DATE ORDER BY QTD DESC )) AS RANK_QTD
FROM SAMPLE_DATA
WHERE trunc(load_date) BETWEEN '24/03/2013' AND '25/03/2013'
WHERE RANK_QTD > 10
GROUP BY LOAD_DATE
ORDER BY LOAD_DATE ASC,
QTD DESC
DOMAIN_NAME QTD LOAD_DATE
Others 2888 24/03/2013
DM_1 1000 24/03/2013
DM_20 933 24/03/2013
DM_11 913 24/03/2013
DM_3 743 24/03/2013
DM_13 572 24/03/2013
DM_12 568 24/03/2013
DM_9 564 24/03/2013
DM_6 505 24/03/2013
DM_5 504 24/03/2013
DM_2 480 24/03/2013
Others 1948 25/03/2013
DM_1 807 25/03/2013
DM_8 764 25/03/2013
DM_7 761 25/03/2013
DM_11 656 25/03/2013
DM_18 611 25/03/2013
DM_17 523 25/03/2013
DM_14 467 25/03/2013
DM_19 447 25/03/2013
DM_15 437 25/03/2013
DM_6 380 25/03/2013 -
Hi
I'm trying to make a default value using Computations;
when I create computation,
I select
Computation item: PXX_TEST
computation type: SQL query
computation Point: I tried all
Computation: select X FROM Y WHERE X= '1'
This is the way to get Default Value ??
I need to display the value when the page is open
Thanks
MMMM,
You can use the default value attribute of the item to set a value if the item's source produces a null. A computation (before/after header) can work too, but it's possible that the item source and Source Used attribute (Always/Only) are interfering with your computation so you might want to try setting Source Used to 'Only...' if you have a computation setting the item.
Scott -
Defaulting DFF Segment Value using sql statement in SSHR gives error when using parameter
Dear All,
i am having an issue that i am making one segment in DFF (SEGMENT3) being defaulted by using sql statement
Select MAX(SEGMENT7) FROM PER_ANALYSIS_CRITERIA cri, PER_PERSON_ANALYSES ana where cri.Analysis_Criteria_id = ana.ANALYSIS_CRITERIA_ID and ana.PERSON_ID = :ANALYSES.PERSON_ID
The Above Select Statement is working fine on the PUI form and getting the Default value correctly but when opening the SSHR page that contain this DFF, it gives me the below error.
"No field listener is registered to resolve field ANALYSES.PERSON_ID referenced by the flexfield with application short name PER and name PEA. Please contact your system administrator. "
Any Help Please???Please see the following docs.
Cannot Add Salary:No Field Listener is Registered to Resolve Field Review.assignment_id (Doc ID 558295.1)
No Field Listener Is Registered To Resolve Field Assgt.Effective_start_date (Doc ID 889794.1)
List of Current Enhancement Requests (ER) for Oracle EBS Self Service Human Resource (SSHR) (Doc ID 1381936.1)
No field listener is registered to resolve field xxx.xxx referenced by the flexfield with application short name ASO... (Doc ID 1359270.1)
Customer Form, Address Error: No field listener is registered to resolve field GLOB.FLEX_COUNTRY_CODE referenced by the flexfield with application short name AR (Doc ID 1276934.1)
DFF issue : No Field Listener Is Registered To Resolve Field XXX Referenced By The Flexfield (Doc ID 555589.1)
Thanks,
Hussein -
Issue in getting current row value using getCurrent Value
Issue:When I call ththe method executeSearchVO from controller class
with Row row = personalActionSearchVO.first();
I am getting the corresponding value.
but my requirement is I have multiple record , If i press action on any of the record, I need to read SITName value for the particular record and need to pass it as parameter to other pager(i mean If i select any record, I need to get corresponding value in the attribute for the record.)
if i comment personalActionSearchVO.first(); i am getting null pointer exception.
Pl. helpme how to get current row instead of first row always.
AMIMPL Clause
public void executeSearchVO(String loginPersonId)
XXHRPersonalActionSearchVOImpl personalActionSearchVO =getXXHRPersonalActionSearchVO1();
personalActionSearchVO.initQuery(loginPersonId);
// Row row = personalActionSearchVO.first();
row = personalActionSearchVO.getFirstFilteredRow("action","1");
Row masterRow = row;
personalActionSearchVO.setCurrentRow(masterRow);
OARow Row1 = (OARow)personalActionSearchVO.getCurrentRow();
System.out.println("Org "+Row1.getAttribute("Organization"));
calling this method from controller clause
if("action".equals(pageContext.getParameter(EVENT_PARAM)) )
System.out.println("Person Id "+ pageContext.getParameter("XXHRPersonId"));
Serializable methodParams[] = {pageContext.getEmployeeId()+""};
applicationModule.invokeMethod("executeSearchVO",methodParams);
need it urgently. pl. help
thanks
sivaTimo,
I am new to Jdevloper. I will explain the issue in detail.
Version: Oracle 9i Jdeveloper
I have a query page with multiple records. when I perform action , I need to pass 2 parameters from query screen to my actual page.
1 parameter is Login person Id,. Now the issue is with getting current value for 2nd paramenter. 2nd Parameter will be changed depends upon record i am choosing in my query page: column is : Information Name.
when I use getcurrentrow , I am getting null pointer exception.
My controller class when I click action button :
if("action".equals(pageContext.getParameter(EVENT_PARAM)) )
Serializable methodParams[] = {pageContext.getEmployeeId()+""};
applicationModule.invokeMethod("executeSearchVO1",methodParams);
{color:#993300}
// Here I need to get InformationName value based on the record I am choosing{color}
HashMap hashMap = new HashMap(2);
hashMap.put("XXHRPersonId", pageContext.getParameter("XXHRPersonId"));
// hashMap.put("InformationName", methodParams);
pageContext.forwardImmediately(
"OA.jsp?page=/xxhr/oracle/apps/xxhr/selfservice/personalaction/webui/XXHRPersonalActionPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
hashMap,
true, // Retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO
my AMIMPL Clause :
I am just pasting whatever I have tried. Pl. suggest me If my code is wrong.
*{color:#993300}I need to get current row information value from the below method*
*{color}*
public void executeSearchVO1(String loginPersonId)
XXHRPersonalActionSearchVOImpl personalActionSearchVO =getXXHRPersonalActionSearchVO1();
personalActionSearchVO.initQuery(loginPersonId);
System.out.println("Row count "+personalActionSearchVO.getRowCount());
// Row row = personalActionSearchVO.first();
Row row = personalActionSearchVO.getCurrentRow();
System.out.println("Informaton Name "+row.getAttribute("InformationName");
In this , If i initialzie with Row row = personalActionSearchVO.first();I am able to get value for my column Information Name.
whereas, if I use directly Row row = personalActionSearchVO.getCurrentRow();, i am getting null pointer exception.
Pl. let me know how to get current row value for Information Name.
Looking for the reply at the earliest.
Thanks
siva -
Hi,
How do I set the 'initial value' property of a default value using an SQL statement?
Any help appreciated,
RobHi Kevin,
you are right. It is sometimes confusing for the users, but it is - as you said - like setting the initial value, of course you can do some more complexity there.
One big problem is. If you want to set the initial values in a detail record of a master-detail relatioship depending on the master-record, you CAN'T use it. If you change the master record to a record which doesn't have a detail, the WHEN-CREATE-RECORD trigger fires before the master-record really changes. That means, the detail will be initialized with data from the old master-record (the one you were in, before changing the master record). Stupid thing.
I never tried the WHEN-DATABASE-RECORD trigger, I even don't know how it works. I think I have to check what it is doing.
Regards,
Torsten -
How to read repeated tag values using sql query
Database version
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Question
How to get repeated tag values?
<TXLife>
<TXLifeRequest>
<TransRefGUID>10bc80e7d60e59b0:a134d0:10d7c4674ad:-7ffd</TransRefGUID>
<TransType tc="1203">OLI_TRANS_TRNHLD</TransType>
<TransExeDate>2011-02-27</TransExeDate>
<TransExeTime>15:06:35</TransExeTime>
<InquiryLevel tc="3">OLI_INQUIRY_OBJRELOBJ</InquiryLevel>
<InquiryView>
<InquiryViewCode>PLANUPDATE_CHBM_1203A</InquiryViewCode>
</InquiryView>
<OLifE>
<SourceInfo>
<SourceInfoName>CHBM Admin Tool</SourceInfoName>
</SourceInfo>
<Activity id="Activity1" HoldingID="Holding1">
<UserCode>User123</UserCode>
<LastUpdate>2011-02-27</LastUpdate>
<ActivityCode>CHBM10001</ActivityCode>
<OLifEExtension VendorCode="0098" ExtensionCode="Activity">
<ActivityExtension>
<SubActivityCode>CHBM20002</SubActivityCode>
<LastUpdateTime>15:06:35</LastUpdateTime>
</ActivityExtension>
</OLifEExtension>
</Activity>
<Holding id="Holding1">
<HoldingTypeCode tc="6">Group Master Contract</HoldingTypeCode>
<Purpose tc="36">Business Protection and Preservation</Purpose>
<Policy>
<CarrierAdminSystem>CHBM</CarrierAdminSystem>
<PolNumber>CHB0001234</PolNumber>
<OLifEExtension VendorCode="0098" ExtensionCode="Policy">
<PolicyExtension>
<BillingDetail>
<PaymentMode tc="3">Quarterly</PaymentMode>
<BillingOrder tc="1009800002">Employee ID</BillingOrder>
</BillingDetail>
<SalaryAllotment>12354333</SalaryAllotment>
</PolicyExtension>
</OLifEExtension>
</Policy>
<Attachment id="Attach1">
<DateCreated>2011-02-27</DateCreated>
<UserCode>System</UserCode>
<AttachmentBasicType tc="1">Text</AttachmentBasicType>
<Description>Event 4</Description>
<AttachmentData>Event Log</AttachmentData>
<AttachmentType tc="1009800001">Transaction Log</AttachmentType>
<AttachmentLocation tc="1">Inline</AttachmentLocation>
<OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
<AttachmentExtension>
<Sequence>2</Sequence>
<CreationTime>16:05:45</CreationTime>
</AttachmentExtension>
</OLifEExtension>
</Attachment>
<Attachment id="Attach2">
<DateCreated>2011-02-27</DateCreated>
<UserCode>System</UserCode>
<AttachmentBasicType tc="1">Text</AttachmentBasicType>
<Description>Event 3</Description>
<AttachmentData>Event Log</AttachmentData>
<AttachmentType tc="1009800001">Transaction Log</AttachmentType>
<AttachmentLocation tc="1">Inline</AttachmentLocation>
<OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
<AttachmentExtension>
<Sequence>1</Sequence>
<CreationTime>16:01:54</CreationTime>
</AttachmentExtension>
</OLifEExtension>
</Attachment>
<Attachment id="Attach3">
<DateCreated>2011-02-27</DateCreated>
<UserCode>P62350</UserCode>
<AttachmentBasicType tc="1">Text</AttachmentBasicType>
<Description>Note 2</Description>
<AttachmentData>Enter notes on changes or edits to plan</AttachmentData>
<AttachmentType tc="14">Note</AttachmentType>
<AttachmentLocation tc="1">Inline</AttachmentLocation>
<OLifEExtension VendorCode="0098" ExtensionCode="Attachment">
<AttachmentExtension>
<Sequence>2</Sequence>
<CreationTime>16:02:23</CreationTime>
</AttachmentExtension>
</OLifEExtension>
</Attachment>
</Holding>
</OLifE>
</TXLifeRequest>
</TXLife>
Expected output shoulb be like this
Description AttachmentType AttachmentData
Event 4 Transaction Log Event Log
Event 3 Transaction Log Event Log
Note 2 Note Enter notes on changes or edits to plan
Please help me any one on this
Edited by: LRAJESH on Apr 20, 2011 8:27 AMSELECT
t2. Description des,
t2.AttachmentType attty,
t2.DateCreated DateCreated,
t2.UserCode UserCode,
t1.Planid Planid,
t2.createdtime,
t1.Ausercode Ausercode
FROM (
SELECT xData doc
FROM dual
) temp_table,
XMLTable ( '/TXLife/TXLifeRequest/OLifE' passing doc
COLUMNS
Planid varchar2(20) path 'Holding/Policy/PolNumber',
AttachmentType xmltype path 'Holding//Attachment' ,
Ausercode varchar2(20) path 'Activity/UserCode'
) t1,
XMLTable
'/Attachment'
passing t1.AttachmentType
columns
Description varchar2(1000) path 'Description',
AttachmentType varchar2(1000) path 'AttachmentType/@tc',
DateCreated varchar2(20) path 'DateCreated',
createdtime varchar2(20) path 'OLifEExtension/AttachmentExtension/CreationTime',
UserCode varchar2(200) path 'UserCode'
) t2 -
Want to get id's value using xpath.
Hi all,
I want to get id attribute's value using xpath.
my xml file as follows:
<book>
<person id="1">
<first id="2">Kiran</first>
<last id="3">Pai
<name id="4">das</name>
</last>
<age id="5">22</age>
</person>
<person id="6">
<first id="7">Bill</first>
<last id="8">Gates</last>
<age id="9">46</age>
</person>
<person id="10">
<first id="11">Steve</first>
<last id="12">Jobs</last>
<age id="13">40</age>
</person>
</book>I want to get the id value of name. using xpath-->//book[0]/person[0]/last[0]/name[0]/[@id]..is this a valid xpath to get the id's value? my java code as follows:
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import javax.xml.parsers.*;
import javax.xml.xpath.*;
import org.w3c.dom.Document;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
public class Evaluate {
public static void main(String[] args) {
String xp = "//book[0]/person[0]/last[0]/name[0]"+"/[@id]";
String id="";
try{
// parse the XML as a W3C Document
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();// Create the parser
Document doc = docBuilder.parse(new File("book.xml"));
XPath xpath = XPathFactory.newInstance().newXPath();
doc.getDocumentElement().normalize();
XPathExpression xPathExpression = xpath.compile(xp);//-->getting error here
id=xPathExpression.evaluate(xp).toString();
id=xPathExpression.evaluate("person");
System.out.println("id=" +id);
System.out.println("xp=" +xp);
}catch(Exception err){
System.out.println("Errpr= "+ err);
can anyone please help me ?No, I believe that XPath indexes begin with 1, not with zero.
-
HOW TO GET TOP N RECORDS IN SQL , URGENT
Hi,
I want to get the TOP 2 and BOTTOM 2 records (TOP 2 SAL , BOTTOM 2 SAL) from the following query result for each department . How do I get it using a SQL statement ? Thanks
SQL> SELECT A.DNAME, B.ENAME, B.SAL FROM DEPT A, EMP B WHERE A.DEPTNO = B.DEPTNO ORDER BY DNAME, SAL
DNAME------------ENAME--------SAL
ACCOUNTING-------KING--------5000
----------------CLARK--------2450
---------------MILLER--------1300
RESEARCH--------SCOTT--------3000
-----------------FORD--------3000
----------------JONES--------2975
----------------ADAMS--------1100
----------------SMITH---------800
SALES-----------BLAKE--------2850
----------------ALLEN--------1600
---------------TURNER--------1500
-----------------WARD--------1250
---------------MARTIN--------1250
----------------JAMES---------950
14 rows selected.If Feroz is asking the TOP 2 Salaried employees and BOTTOM 2 Salaried employees
for ***EACH**** DEPARTMENT, then following SQL is one of the many ways(proves good with performance).Also brings top2+ bottom2 in one shot.SELECT dname, ename, sal FROM
(SELECT d.DNAME, e.ENAME, e.SAL,
dense_rank() over(PARTITION BY e.DEPTNO ORDER BY e.SAL) dr
FROM EMP e, DEPT d
WHERE e.DEPTNO = d.DEPTNO)
WHERE dr <= 2
UNION
SELECT dname, ename, sal FROM
(SELECT d.DNAME, e.ENAME, e.SAL,
dense_rank() over(PARTITION BY e.DEPTNO ORDER BY e.SAL DESC) dr
FROM EMP e, DEPT d
WHERE e.DEPTNO = d.DEPTNO)
WHERE dr <= 2
/Thx,
SriDHAR -
Get previous bill date using SQL
Hi,
I am table which holds records for bill generation. I have column name gene_bill_date which is date field and it holds a value the date on which the particular bill was generated.
Now I am trying to get previous bill date, not the current bill date. I can to Max(gene_bill_date) to get current bill date, but how do I get previous bill date?
thanksHi,
Sorry, it's unclear what you're asking.
You didn't post any sample data, so I'll use the scott.emp table to illustrate. Let's say we're interested in deptno=30 only, just to reduce the output from 14 rows to 6.
If, for every row, you need to know the most recent gene_bill_date before the one on that row, you can do something like this:
SELECT ename
, hiredate
, LAG (hiredate) OVER (ORDER BY hiredate) AS prev_hiredate
FROM scott.emp
WHERE deptno = 30
;Output:
ENAME HIREDATE PREV_HIREDA
ALLEN 20-Feb-1981
WARD 22-Feb-1981 20-Feb-1981
BLAKE 01-May-1981 22-Feb-1981
TURNER 08-Sep-1981 01-May-1981
MARTIN 28-Sep-1981 08-Sep-1981
JAMES 03-Dec-1981 28-Sep-1981Are you only interested in the 2 most recent dates in the whole result set?
If so, do a Top-N Query , like this:
WITH got_r_num AS
SELECT ename
, hiredate
, RANK () OVER (ORDER BY hiredate DESC) AS r_num
FROM scott.emp
WHERE deptno = 30
SELECT *
FROM got_r_num
WHERE r_num <= 2
;Output:
ENAME HIREDATE R_NUM
JAMES 03-Dec-1981 1
MARTIN 28-Sep-1981 2
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. -
Get form field value using an offset
I have a Form created using Perl that has a table with a row for each invoice in a large table. I display all the rows in a table and allow the user to edit some info for each record:
for ($item_cntr = 0; $cntr < $record_cnt; ++$item_cntr)
{ print qq(<tr>
<td><input type="text" name="c_freight_$item_cntr" value="$i_freight[$item_cntr]" onBlur="linetotal($item_cntr)" ></td>
<td><input type="text" name="c_miscamt_$item_cntr" value="$i_miscamt[$item_cntr]" ></td>
<td><input type="text" name="c_price_$item_cntr" value="$i_price[$item_cntr]" ></td>
</tr>);
I want to create a Function that is called when they change the Freight value and that causes the rows total Price (freight + miscamt = price) to be calculated again (without hitting a Submit button on the Form).
I created a Function:
function linetotal(whatline) {
var fixed_freight = "document.editform.c_freight_" + whatline;
var fixed_misc = "document.editform.c_miscamt_" + whatline;
var linetotal = parseFloat(fixed_freight.value) + parseFloat(fixed_misc.value);
document.editform.c_price_whatline.value = linetotal; } }
So, if the first row in the table is 0, then the Function is passed "0" and should get the value of the form fields:
'c_freight_0' and 'c_miscamt_0' and set 'c_price_0' to a new value in the form.
The fixed_freight is showing that the string it has is correct, but it does not get the value from the form. Any ideas?DrClap wrote:
DrLaszloJamf wrote:
DrClap wrote:
Although there are [Java sites|http://www.javaranch.com/] which do have an [HTML and Javascript forum|http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=forum&f=20].
Don't forget the free hugs forum there, too!
You must mean [this one|http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=forum&f=44].
Oh yeah. Are you a JavaRanch regular, Dr.C? I was for a while, but not recently.
Maybe you are looking for
-
How do I transfer music from a past library to a new one?
I have an Ipad that has music on it from a computer that has died. I want to make sure I keep the music on it when I plug it into my new computer. I wanted to know how to transfer music (not necessarily "purchased"...) from my ipad to my new computer
-
it all started with my missus daughter setting yahoo as the homepage when i had firefox as my hompage now i cant remember how to get it back to normal
-
How can i fix my home bouton?
i have a ipod touch 4 and the home boutton is stuck how can i fix it?
-
Ldconfig: /usr/lib/libMonoSupportW.so is not a symbolic link
I've noticed this error message came up after this week's general updates and wonder what is the issue? I can pacman -Syu fine and completed any updates, but the above message always shows up after the updates completed.
-
Multi-column report that repeats columns
I don't know if this is possible: COL A | COL B | COL C | COL A | COL B | COL C 1 | 2 | 3 | 4 | 5 | 6 7 | 8 | 9 | 10 | 11 | 12 So it would be a report being pulled from a single table, but the columns would be repeated across the page. Has anyone eve