Urgent help in sql plz
hi
i need to genarate sql query for 1 table
X id Yid Day
1 a 11/12/2006
1 a 11/12/2006
1 p 11/12/2006
1 a 3/12/2006
1 p 3/12/2006
2 a 11/12/2006
2 p 11/12/2006
I need to genearte report in follwoing format
X_id y_id Day day count
1 a 11/12/2006 2
1 p 11/12/2006 1
toal count for x_id 3
2 a 3/12/2006 1
2 p 3/12/2006 1
totla count for x_id 2
3 a 11/12/2006 1
3 p 11/12/2006 1
totla count for x_id 2
i am not very good at rollup and grouping :-(, but i used analytics hope this can give you some hints and you can accommodate "break" in there,
Create Table test As
Select 1 X_id , 'a' y_id, to_date('11/12/2006','dd/mm/rrrr') "Day" From dual Union All
Select 1, 'a', to_date('11/12/2006','dd/mm/rrrr') From dual Union All
Select 1, 'p', to_date('11/12/2006','dd/mm/rrrr') From dual Union All
Select 1, 'a', to_date('3/12/2006','dd/mm/rrrr') From dual Union All
Select 1, 'p', to_date('3/12/2006','dd/mm/rrrr') From dual Union All
Select 2, 'a', to_date('11/12/2006','dd/mm/rrrr') From dual Union All
Select 2, 'p', to_date('11/12/2006','dd/mm/rrrr') From dual
SQL>
SQL> Select x_id, y_id, "Day", cnt , Sum(cnt) over (Partition By x_id,"Day" Order By x_id) tot_cnt From
2 (
3 Select Unique x_id, y_id, "Day", Count(*) over (Partition By x_id, y_id, "Day") cnt
4 From test
5 );
X_ID Y_ID Day CNT TOT_CNT
1 a 12/3/2006 1 2
1 p 12/3/2006 1 2
1 a 12/11/2006 2 3
1 p 12/11/2006 1 3
2 p 12/11/2006 1 2
2 a 12/11/2006 1 2
6 rows selected
SQL>
My first try at break and compute command,
SQL> break on x_id
SQL> compute sum of cnt on x_id
SQL> Select Unique x_id, y_id, "Day", Count(*) over (Partition By x_id, y_id, "Day") cnt
2 From test
3 /
X_ID Y Day CNT
1 p 03-DEC-06 1
a 03-DEC-06 1
sum 2
2 a 11-DEC-06 1
p 11-DEC-06 1
sum 2
1 a 11-DEC-06 2
p 11-DEC-06 1
X_ID Y Day CNT
sum 3
6 rows selected.Message was edited by:
Nicloei W
Similar Messages
-
I have two tables a and b with one column each (data type number) with NO relationship between them.I want to create anew table with two coloumns with data from table a in the first column and data from table b in the second column.like below:
Table A
366
42
88
Table B
99
100
2345
table c
366 99
42 100
88 2345
This is very urgent and I request anyone to help me.
Thanks
SrichakraGoing by your description (and not your posted example) I get this:
SQL> select a.only_col a_only_col
2 ,b.only_col b_only_col
3 from
4 (select only_col
5 ,row_number() over (order by only_col) rn
6 from A
7 ) A
8 ,
9 (select only_col
10 ,row_number() over (order by only_col DESC) rn
11 from B
12 ) B
13 where A.rn = B.rn
14 order by a.only_col
15 ;
A_ONLY_COL B_ONLY_COL
42 2345
88 100
366 99 -
Very Urgent Help , ABAP SQL Query
Guys,
Please suggest.I have a table(custom_table1) with a field say A which is of date type = c and length = 9. And i want to query this table.Following is the query.
Select substr(A,0,5) B C into itab From table custom_table1
where b = ( select b from cusstom_table2 )
and substr(A,0,5) = Input_A.
That is i want to equate an Input_A (which is of 5 character length) with field A (only first 5 character of the 9 length). But it seems the query is wrong. Kindly help ,very urgent
ThanksThanks guys, U have helped me to fill up the where condition as
but what about the column A in the select query ?I need only 5 characters from the field populated into Itab.
CONCATENATE srch_str '%' INTO srch_str. -- bcos i want it to be 'InputA%'
Select Substr(A,0,5) , B C Into Itab From CustomTable 1 where B = (Select B from customtable2) and A Like SrchStr
Is there any means i can populate only the 5 characters from the select field A into Itab without using Substr (becos it doesnt work) ? Please help. -
URgent: Help regarding SQL Query
Hi ,
I need help regarding an sql query.
Sample Data:
ITEM_TYPE ITEM_NUM UNIT_PRICE QUANTITY LINE_TOTAL
ITEM 1 5 10 50
ITEM 2 10 5 50
ITEM 1 5 5 25
ITEM 2 10 20
TAX 16.5
TAX -3.5I would like to display the data as
ITEM_TYPE ITEM_NUM UNIT_PRICE QUANTITY LINE_TOTAL
ITEM 1 5 15 145
2 10 5
2 10
TAX 13.0
Line_total = unit_price * QuantityThanks in Advance
G.Vamsi Krishna
Edited by: user10733211 on Aug 5, 2009 7:42 AM
Edited by: user10733211 on Aug 5, 2009 7:49 AM
Edited by: user10733211 on Aug 5, 2009 8:12 AM
Edited by: user10733211 on Aug 5, 2009 8:22 AM
Edited by: user10733211 on Aug 5, 2009 8:24 AMHi,
Try this, use some analytics:
SQL> with t as (
2 select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
3 select 'item', 2, 10, 5, 50 from dual union all
4 select 'item', 1, 5, 5, 25 from dual union all
5 select 'item', null, 2, 10, 20 from dual union all
6 select 'tax', null, null, null, 16.5 from dual union all
7 select 'tax', null, null, null, -3.5 from dual
8 ) -- actual query starts here:
9 select item_type
10 , item_num
11 , unit_price
12 , sum_qty
13 , case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
14 then null
15 else sum_lt
16 end sum_lt
17 from ( select item_type
18 , item_num
19 , unit_price
20 , quantity
21 , sum(quantity) over ( partition by item_type, item_num ) sum_qty
22 , sum(linetotal) over ( partition by item_type ) sum_lt
23 , row_number() over ( partition by item_type, item_num order by item_type, item_num ) rn
24 from t
25 )
26 where rn=1;
ITEM ITEM_NUM UNIT_PRICE SUM_QTY SUM_LT
item 1 5 15 145
item 2 10 5
item 2 10
tax 13
4 rows selected.
edit
And please use the code tag, instead of clunging with concats.
Read:
http://forums.oracle.com/forums/help.jspa
Edited by: hoek on Aug 5, 2009 5:15 PM
edit2
Also nulls for item_type:
ops$xmt%OPVN> with t as (
2 select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
3 select 'item', 2, 10, 5, 50 from dual union all
4 select 'item', 1, 5, 5, 25 from dual union all
5 select 'item', null, 2, 10, 20 from dual union all
6 select 'tax', null, null, null, 16.5 from dual union all
7 select 'tax', null, null, null, -3.5 from dual
8 ) -- actual query starts here:
9 select case when item_type = lag(item_type) over ( order by item_type, item_num )
10 then null
11 else sum_lt
12 end item_type
13 , item_num
14 , unit_price
15 , sum_qty
16 , case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
17 then null
18 else sum_lt
19 end sum_lt
20 from ( select item_type
21 , item_num
22 , unit_price
23 , quantity
24 , sum(quantity) over ( partition by item_type, item_num ) sum_qty
25 , sum(linetotal) over ( partition by item_type ) sum_lt
26 , row_number() over ( partition by item_type, item_num order by item_type, item_num ) rn
27 from t
28 )
29 where rn=1;
ITEM_TYPE ITEM_NUM UNIT_PRICE SUM_QTY SUM_LT
145 1 5 15 145
2 10 5
2 10
13 13
4 rows selected.If you really need a space instead of nulls, then simply replace the nulls by a space....
Edited by: hoek on Aug 5, 2009 5:18 PM -
URGENT HELP ON SQL LOADER CONTROL FILE
Dear All,
Please find my control file below. I need two leading zeros for the coulmn DDA_CLEARING_NUMBER. Presently its loading 18 characters. position is (0791:0808). Now i need this to be loaded with two leading zeros to the left. I need padding two zeros in front of the 18 characters. HOW CAN I DO THAT? PLEASE HELP ME IN IT.
OPTIONS (DIRECT=FALSE,
ROWS=30000,
BINDSIZE=3000000,
READSIZE=3000000,
SKIP_UNUSABLE_INDEXES=TRUE)
LOAD DATA
INFILE '/xxx/xxx/xxx.dat'
BADFILE '/xxx/xxx/xxx.bad'
DISCARDFILE '/dev/null'
APPEND
INTO TABLE AAA
WHEN MONTH_END_STATUS = 'O'
TIME_PERIOD POSITION (0079:0086) DATE "YYYYMMDD",
SERVICE_TYPE POSITION (0077:0078) CHAR,
ACCOUNT_NUMBER POSITION (0001:0020) CHAR,
MONTH_END_STATUS POSITION (0060:0060) CHAR,
CIF_BANK POSITION (0066:0069) CHAR,
CIF_BRANCH POSITION (0070:0074) CHAR,
PLAN_CODE POSITION (0075:0076) CHAR,
DDA_CLEARING_NUMBER POSITION (0791:0808) CHAR,
TAX_ID POSITION (0516:0524) CHAR)Dear peterson,
When i do what you said, its inserting nothing. not even space. Please help me in it what to do?
thanks and regards -
Need urgent help in SQL *PLUS
I downloaded Oracle10g on my computer it was workink fine until I opened my registry editor then I couldn't open SQL PLUS for Oracle10g I receive this massages Error6 initializing SQLPLUs , Massage file sp1<lang>.msb not found
and sp2-0750: you may need to set Oracle_Home to your Oracle software directory.Try to use the Windows System Restore to repair the registry:
start->All Programs->Accessories->System Tools->System Restore.
You need to log in as administrator.
Jack
路漫漫其修远兮,吾将上下而求索。
The way ahead is long; I see no ending, yet high and low Ill search with my will unbending. -
Hi All
I have used the Case statement in my select query which is as:
SELECT LOTNO,CHIPTYPE,QUANTITY,CASE WHEN (LOTSIZE-QUANTITY)>=0 THEN to_char(LOTSIZE-QUANTITY) ELSE 'Error in Lot Size Entry' END AS REMAINING FROM TEMP_QTYCHIPWISE ORDER BY LOTNO
This query is working fine in Oracle9i but giving error in 8i.
What could be reason behind it.
Regards
ManpreetThis is pasted direct from my sqlplus window:
Connected to:
Oracle8i Release 8.1.7.0.0 - Production
JServer Release 8.1.7.0.0 - Production
SQL> select case when dummy = 'X' then 1 end from dual;
CASEWHENDUMMY='X'THEN1END
1
What error are you getting ?
Is your sql embedded in another tool ? Tools do not always support the latest database features. -
Urgent HELP required on forming the Matrix of data using PL/SQL
Hi All,
I'm new to this thread and require your urgent help in this regard.
I've got a requirement for building a 5000 X 5000 matrix using PL/SQL. My original data tables have 5000 rows each and I need to do a correlation analysis using this data and need to store in a physical table and not in-memory. Is this feat achievable using mere PL/SQL? I understand that Oracle DB has a limitation of 1000 columns(but not sure) and hence I'd like to know whether there is any work-around for such scenarios. If not, what are the other alternative method(s) to achieve this feat? Do I need to use any 3rd party tools to get this done? An early reply from the experts is highly appreciated.
Thanking you all Gurus in advance.
Rgds
SaiWelcome to OTN!
I'll get to your quesiton in a moment, but first some welcome information. Many OTN posters consider it impolite to mark threads as "urgent". We are volunteers and have jobs of our own to do without people we don't know making demands. You are brand new and deserve some patience but please understand this. It is very likely before I finish this post someone will complain about the word "urgent" in your subject.
On to more interesting things :)
You can do the matrix, but are out of luck with a 5000 x 5000 table because Oracle only allows 1000 columns per table. There are ways to work around this.
How do do the matrix depends on what you want to do. You can do this different ways. You can create a table beforehand and use PL/SQL or simple SQL to populate it, or use the CREATE TABLE AS syntax to create and populate it in one step if you can get the underlying SQL to work the way you want, something like
create table my_table as
select a.*, b.*
from table1 a, table2 bcan populate a matrix from 2 tables with an intentional cartesian join (the WHERE clause was left out intentionally, provided your data is already in the data base.
If not you can use a PL/SQL routine to populate the data.
There are a couple of ways to solve the 1000 column limit. The easiest way might be to have 5 collections of 1000 columns each. A more complicated but more elegant soltion would be to have nested collections, allowing 2 colliections that you can loop through - a collection of collections. Nested collections can be hard to work with. A third way would be to use nested tables in the database but I personally do not like them and the insert, update, and delete statements for nested tables are hard to use.
I'm not going to give a code example because I am not sure which solution is best for you. If you have further questions post them. -
LASERJET M1217 nfw MFP urgent help plz
HAY GUYS, NEED URGENT HELP!!!!!!!!!
My printer M1217 nfw MFP had a problem with the scanner and it was fixed bu updating the firmware and the scanner works fine and offcourse i printed the config. report befor updating the firmware , the problem is that i lost the report and i cant config. the fax or the wirless connection . any help plz guyskelsaeed wrote:
HAY GUYS, NEED URGENT HELP!!!!!!!!!
My printer M1217 nfw MFP had a problem with the scanner and it was fixed bu updating the firmware and the scanner works fine and offcourse i printed the config. report befor updating the firmware , the problem is that i lost the report and i cant config. the fax or the wirless connection . any help plz guys -
Urgent help needed... PL/SQL Insert statement
Hi...
I need some urgent help on this project. I have a 2 column table with values that need to be inserted into another existing table which has a sequence.
This is the 2 column table:
FUND YEAR
29587 05
29587 07
Existing table:
Name Null? Type
LIST_ID NOT NULL NUMBER(6) -- This is a sequence
WEB_USER_ID NOT NULL VARCHAR2(10)
RESOURCE_TYPE NOT NULL VARCHAR2(8)
LIST_TYPE NOT NULL VARCHAR2(10)
LIST_NAME NOT NULL VARCHAR2(50)
LIST_CODE_1 NOT NULL VARCHAR2(6) -- FUND from table above
LIST_CODE_2 NOT NULL VARCHAR2(6) -- YEAR from table above
LIST_CODE_3 NOT NULL VARCHAR2(6)
LAST_UPDATED_DT NOT NULL DATE
LAST_UPDATED_BY NOT NULL VARCHAR2(10)
LIST_CODE_4 NOT NULL VARCHAR2(20)
The columns from table 1 (FUND, YEAR) correspond to columns (LIST_CODE_1, LIST_CODE_2) in table 2. The column LIST_ID is a sequence. I can put in sysdate for LAST_UPDATED_DT and my initials SN for LAST_UPDATED_BY. This is going to be for 2 unique WEB_USER_IDs which would be in the WHERE clause. I will be inserting 2200 rows for each id. A single insert statement would look like this -
INSERT INTO EXISTING_TBL (list_id,web_user_id,resource_type,list_type,list_name,list_code_1,list_code_2,list_code_3,list_code_4,last_updated_dt,last_updated_by) VALUES ('470027','WEBUSER','GL','FUNDFYF',' FUND BALANCE SUM','12010','01',' ',' ',{ts '2010-5-19 10:16:9'},'SN')
How would I do this to insert the 2200 values from my 2 column table to the existing table?
All help is greatly appreciated!!
SNHello ,
I think this will work
INSERT INTO TABLE2
LIST_ID,
WEB_USER_ID,
RESOURCE_TYPE,
LIST_TYPE,
LIST_NAME,
LIST_CODE_1,
LIST_CODE_2,
LIST_CODE_3,
LIST_CODE_4,
LAST_UPDATED_DT,
LAST_UPDATED_BY
SELECT
SEQ.NEXTVAL,
FUND,
YEAR,
<VALUE FOR RESOURCE_TYPE>,
<VALUE FOR LIST_TYPE>,
<VALUE FOR LIST_NAME>,
<VALUE FOR LIST_CODE_1>,
<VALUE FOR LIST_CODE_2>,
<VALUE FOR LIST_CODE_3>,
<VALUE FOR LIST_CODE_4>,
SYSDATE,
'SN'
FROM
TABLE1
REGARDS
Rahul Sharma -
****URGENT HELP NEEDED**** unable to print on metalic silver paper
I am in DESPERATE need of help.
I am trying to print on silver metalic paper using my Photomart C3180, but it wont print. It will printon white paper but not this stuff. I need urgent help as I am trying to make my own wedding invitations that i have to post out at the end of the month.
ANY help would be so greatfully received.
Thank ou
Kateplz try to download the following set of drivers from the link below :::\
http://gimp-print.sourceforge.net/MacOSX.php3
This is a new set of default drivers and mayhelp u in resolving the issue.
Plz do run disk first aid after installing the driver....might suggest even before installaing.
Thanx !! for trying. -
Urgent help needed for XML Tags using XMLForest()
Folks
I need some urgent help regarding getting use defined tag in your
XML output.
For this I am using XMLElement and XMLForest which seems to work fine
when used at the SQL prompt but when used in a procedure throws and error
SQL> Select SYS_XMLAGG(XMLElement("SDI",
XMLForest(sdi_num)))
From sdi
where sdi_num = 22261;- WORKS FINE
But when used in a procedure,doesnt seem to work
Declare
queryCtx DBMS_XMLQuery.ctxType;
v_xml VARCHAR2(32767);
v_xmlClob CLOB;
BEGIN
v_xml:='Select SYS_XMLAGG(XMLElement("SDI",
XMLFOREST(sdi_num)))
From sdi
where sdi_num = 22261';
queryCtx :=DBMS_XMLQuery.newContext(v_xml);
v_xmlClob :=DBMS_XMLQuery.getXML(queryCtx);
display_xml(v_xmlClob);
End;
CREATE OR REPLACE PROCEDURE display_xml(result IN OUT NOCOPY CLOB)
AS
xmlstr varchar2(32767);
line varchar2(2000);
BEGIN
xmlstr:=dbms_lob.SUBSTR(result,32767);
LOOP
EXIT WHEN xmlstr is null;
line :=substr(xmlstr,1,instr(xmlstr,chr(10))-1);
dbms_output.put_line('.'||line);
xmlstr := substr(xmlstr,instr(xmlstr,chr(10))+1);
END LOOP;
end;
SQL> /
.<?xml version = '1.0'?>
.<ERROR>oracle.xml.sql.OracleXMLSQLException: Character ')' is not allowed in an
XML tag name.</ERROR>
PL/SQL procedure successfully completed.
SQL>HELP is appreciated as to where I am going wrong?Hi,
if you want to transform something to something else, you should declare, what is your source.
I would prefer to use plain XSL-Transformations, because you have a lot more options to transform your source and you can even better determine, how your output should looks like.
Kind regards,
Hendrik -
Guys i have a v simple question but i cnat get my head around it.....i have a running environment (cluster) of call managers....now i want to relplicate it in my lab same topology....now i m using BARS as well....i have already build the call managers (in lab)...now i dont remenber the SQL passwords or other passwords for the live CCM cluster....now if i take a back up and put it in the lab will it work??? or the the passwords have to be same on lab to th elive environment......guys urgent help is needed.....reagrds
You can restore the node in the lab with the tar file you got from the back up. The restore will override the passwords and assign the ones taken from the back up. I hope that helps!
-
Urgent help needed; Database shutdown issues.
Urgent help needed; Database shutdown issues.
Hi all,
I am trying to shutdown my SAP database and am facing the issues below, can someone please suggest how I can go about resolving this issue and restart the database?
SQL> shutdown immediate
ORA-24324: service handle not initialized
ORA-24323: value not allowed
ORA-01089: immediate shutdown in progress - no operations are permitted
SQL> shutdown abort
ORA-01031: insufficient privileges
Thanks and regards,
IqbalHi,
check SAP Note 700548 - FAQ: Oracle authorizations
also check Note 834917 - Oracle Database 10g: New database role SAPCONN
regards,
kaushal -
I am having problems implementing a username validaion bean for my login system. Every time I click my login icon on my main JSP page the login JSP page does not appear except one of the error JSP pages.
How can I correct this problem?
Does the code below look correct?
Below is the codes for the Username Validation Bean :
LOGIN.JSP
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.mysql.jdbc.*"%>
<%@ page errorPage="badLogin.jsp"%>
<%@ page import="gcd.UserNameValidationBean"%>
<%
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection connection=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/gcdBB_db");
java.sql.Statement statement = connection.createStatement();
Enumeration parameters = request.getParameterNames();
if(parameters.hasMoreElements())
String usernameValue = request.getParameter("username");
String passwordValue = request.getParameter("password");
statement.executeUpdate("INSERT INTO users (username,password) VALUES ('"+usernameValue+"','"+passwordValue+"')");
%>
GOODLOGIN.JSP
<%@ page errorPage="badLogin.jsp"%>
<%@ page import="gcd.UserNameValidationBean"%>
<% UserNameValidationBean validationBean = new UserNameValidationBean();
if(request.getParameter("username")!=null)
validationBean.validateUserNameBean(request.getParameter("username"));
%>
<%=request.getParameter("username")%>
USERNAMEVALIDATIONBEAN.JAVA
package gcd;
public class UserNameValidationBean
public UserNameValidationBean(){}
public boolean validateUserName(String userName) throws InvalidUserNameException
if(userName.length() < 32)
throw new InvalidUserNameException("User Name Invalid: " + userName);
return true;
INVALIDUSERNAMEEXCEPTION.JAVA
package gcd;
public class InvalidUserNameException extends Exception
public InvalidUserNameException(String message)
super(message);
I need urgent help to get this working!Here is code for badLogin.jsp and badLoginWithExceptonObject:
BADLOGIN.JSP
<HTML><HEAD><TITLE>Login Failure</TITLE></HEAD>
<BODY bgcolor="#FF9900">
<H1></H1>
<font face="Arial" size="3">Sorry but you either entered an incorrect username
or password </font>
<P><font face="Arial" size="3">Try Again</font>
</BODY></HTML>
BADLOGINWITHEXCEPTIONOBJECT.JSP
<HTML><HEAD><TITLE>Check User Login Against Parameters</TITLE></HEAD>
<BODY bgcolor="#FF9900">
<%@ page isErrorPage = "true"%>
<P><font face="Arial" size="3">Error =</font> <%= exception.getMessage()%> <% PrintWriter writer = new PrintWriter(out); %>
<P><font face="Arial" size="3">Stack =</font> <% exception.printStackTrace(writer); %>
<P><font face="Arial" size="3">Try Again</font>
</BODY></HTML>
Maybe you are looking for
-
Oracle 10g Enterprise Manager Control for Database
Hi, I have a question. I have installed Oracle 10g Application server and Database server. Now, I am able to start OEM for database using "emctl start dbconsole". And I am able to browse it on port 5500. But everytime it shows me database "orcl". I h
-
Time Machine Fills up my startup Disk
Hi all. I'm running Time Machine on 10.5.5. My startup disk has around 80 gigs free (out of 300 total). Problem: when I've been away from the computer for a while (overnight or a couple of hours) I will wake it up from sleep and see the warning that
-
Java Caching techniques..
How can any one please provide me the pointers for Java caching techniques for performance enhancement of a a code. Thanks Naxy
-
Hey got this Problem for homework that's not working: we're supposed to do a program that ends up looking like this... Celsius Fahrenheit Fahrenheit Celsius 40.0 105.0 120.0 48.89 39.0 102.2 110.0 43.33 32.0 89.6 40.0 5.44 31.0 87.8 30.0 -1.11 but he
-
Hi SAP Gurus, I just finish to execute the Material Ledger by tx CKMLCP but I have some doubts about the accounting.The posting of ML only show me accounting from level and multilevel price differences to materials, but what about accounting compleme