Need help for sql statement
Hi,
Need help to write sql statement.
create table t_dt ( dt_start date, dt_end date, amount number);
insert into t_dt values('1-Jan-10','10-Feb-10',12);
insert into t_dt values('11-Feb-10','10-Mar-10',10);
insert into t_dt values('11-Mar-10','20-Apr-10',8);
insert into t_dt values('21-Apr-10','28-Jun-10',10);
insert into t_dt values('29-Jun-10','20-Sep-10',10);
insert into t_dt values('21-Sep-10','10-Oct-10',10);
insert into t_dt values('11-Oct-10','31-Dec-10',8);
insert into t_dt values('1-Jan-11','10-Feb-11',8);
insert into t_dt values('11-Feb-11','10-Mar-11',7);
insert into t_dt values('11-Mar-11','20-Apr-11',6);
insert into t_dt values('21-Apr-11','28-Jun-11',6);
insert into t_dt values('29-Jun-11','20-Sep-11',6);
insert into t_dt values('21-Sep-11','10-Oct-11',4);
insert into t_dt values('11-Oct-11','31-Dec-11',8);
Result should be like below..
dt_start dt_end Amount
1-Jan-10 10-Feb-10 12
11-Feb-10 10-Mar-10 10
11-Mar-10 20-Apr-10 8
21-Apr-10 10-Oct-10 10
11-Oct-10 10-Feb-11 8
11-Feb-11 10-Mar-11 7
11-Mar-11 20-Sep-11 6
21-Sep-11 10-Oct-11 4
11-Oct-11 31-Dec-11 8
Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
Thanks.
Hello
I think this gives yuo what you need....
SELECT
MIN(dt_start),
MAX(dt_end),
amount
FROM
( SELECT
dt_start,
dt_end,
MAX(marker) OVER(ORDER BY dt_start) marker,
amount
FROM
Select
dt_start,
dt_end,
amount,
CASE
WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
ROW_NUMBER() OVER(ORDER BY dt_start)
END marker
from t_dt
GROUP BY
amount,
marker
order by
MIN(dt_start)
MIN(DT_START) MAX(DT_END) AMOUNT
01-JAN-2010 00:00:00 10-FEB-2010 00:00:00 12
11-FEB-2010 00:00:00 10-MAR-2010 00:00:00 10
11-MAR-2010 00:00:00 20-APR-2010 00:00:00 8
21-APR-2010 00:00:00 10-OCT-2010 00:00:00 10
11-OCT-2010 00:00:00 10-FEB-2011 00:00:00 8
11-FEB-2011 00:00:00 10-MAR-2011 00:00:00 7
11-MAR-2011 00:00:00 20-SEP-2011 00:00:00 6
21-SEP-2011 00:00:00 10-OCT-2011 00:00:00 4
11-OCT-2011 00:00:00 31-DEC-2011 00:00:00 8
9 rows selected.HTH
David
Edited by: Bravid on Feb 23, 2012 12:08 PM
Beaten to it by Frank! :-)
Similar Messages
-
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
How do I specify a date or datetime in my query?
Thanks in advance.I execute the sql statement
select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
I got mix result. I got an error message "cannot convert 10375584 to a date.
Yet, he statistics window of the I-sql says
"estimated 493 rows in query (I/O estimate 87)
PLan> mytable (seq)"
It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
Any thought ? -
Hello all,
im working in hr schema
i need sql statement to answer my question
i need all employees information
where average salary = average salary department 50
sorry i can't speak english very well
thank's allThere is no need to do it in two queries. All you need is:
select *
from (
select e.*,
avg(case department_id when 50 then salary end) over() dept_50_avg_sal
from hr.employees e
where salary <= dept_50_avg_sal
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556
199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556
115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556
116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556
117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556
118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556
119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556
125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556
126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556
127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556
128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556
130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556
131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556
132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556
133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556
134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556
135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556
136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556
138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556
139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556
140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556
143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556
144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556
180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556
181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556
182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556
183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556
186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556
187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556
190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556
191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556
195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556
196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556
197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556
37 rows selected.
SQL> SY. -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
Hi,
I need to combine many table only in one select statement.
This is my table name
- L20060101
- L20060102
- L20060103
- L20060104
- L20060105
- L20060131
- L20060201
I dont how to do select statement to select all this table
This is the wrong select statement.
Select * from like '%L200601%
Can i do like that?
Can any body help me on how to solve my problem?You could do something like
create or replace procedure sp_create_monthly_tabs
(p_month in varchar2) is
v_sql varchar2(32767);
v_cnt number:=0;
begin
v_sql := null;
for c1 in (select table_name from user_tables
--- put in the condition to select the tables by the month
--- passed in as the parameters
) loop
if v_cnt = 0 then
v_sql := 'Create or replace VIEW Mon_Tab'||p_month ||
'AS Select * from '||C1.Table_Name ||' ' ;
else
v_sql := v_sql||'Union All '||'Select * from '||C1.Table_Name ||' ' ;
end if;
v_cnt := v_cnt + 1;
end loop;
execute immediate(v_sql)
end; -
I have a MERGE statement, I am executing it from shell script, I want to print that how many rows has been updated and Inserted.
Can any one give me some idea.
Thanks in AdvanceI want to print that how many rows has been updated and Inserted. If you really want/need to print that information, then don't use MERGE but INSERT and UPDATE statements.
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:35615502072484
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:122741200346595110 -
Need help for SQL Queries Tunning
hi all,
we have a procedure for search consumers, which using sql queries like:
SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
TRIM (connaddress) AS connaddress,
TRIM (CATEGORY) AS CATEGORY, TRIM (landmark) AS landmark,
SUBSTR (accno, 1, 3) AS subdivisionname
FROM consumermaster
WHERE LOWER (accno) LIKE
LOWER ('%' || NVL (caccno, '#noval#') || '%')
OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
OR LOWER (connaddress) LIKE
LOWER ('%' || NVL (cadd, '#noval#') || '%')
OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
OR accno = (SELECT accno
FROM requestregistration
WHERE requestid = creqid)
UNION
SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
TRIM (connaddress) AS connaddress, TRIM (CATEGORY)
AS CATEGORY,
TRIM (landmark) AS landmark,
SUBSTR (accno, 1, 3) AS subdivisionname
FROM scodetails
WHERE LOWER (accno) LIKE
LOWER ('%' || NVL (caccno, '#noval#') || '%')
OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
OR LOWER (connaddress) LIKE
LOWER ('%' || NVL (cadd, '#noval#') || '%')
OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
OR accno = (SELECT accno
FROM requestregistration
WHERE requestid = creqid);
it's ok for small tables but now data increase .......
searching method is very slow
now i want to tune this query for better performance
please sugg me best method
Thanks in advance
Regards
vij..The link given by Asif should get you on the right track for tuning this query.
I just formatted your SQL:
SELECT Trim(NAME) AS NAME,
Trim(accno) AS accno,
Trim(connaddress) AS connaddress,
Trim(category) AS category,
Trim(landmark) AS landmark,
Substr(accno,1,3) AS subdivisionname
FROM consumermaster
WHERE Lower(accno) LIKE Lower('%'
||Nvl(caccno,'#noval#')
||'%')
OR Lower(NAME) LIKE Lower('%'
||Nvl(cname,'#noval#')
||'%')
OR Lower(connaddress) LIKE Lower('%'
||Nvl(cadd,'#noval#')
||'%')
OR phone LIKE '%'
||Nvl(cphone,'#noval#')
||'%'
OR accno = (SELECT accno
FROM requestregistration
WHERE requestid = creqid)
UNION
SELECT Trim(NAME) AS NAME,
Trim(accno) AS accno,
Trim(connaddress) AS connaddress,
Trim(category) AS category,
Trim(landmark) AS landmark,
Substr(accno,1,3) AS subdivisionname
FROM scodetails
WHERE Lower(accno) LIKE Lower('%'
||Nvl(caccno,'#noval#')
||'%')
OR Lower(NAME) LIKE Lower('%'
||Nvl(cname,'#noval#')
||'%')
OR Lower(connaddress) LIKE Lower('%'
||Nvl(cadd,'#noval#')
||'%')
OR phone LIKE '%'
||Nvl(cphone,'#noval#')
||'%'
OR accno = (SELECT accno
FROM requestregistration
WHERE requestid = creqid); You are using some function on almost each and every column in the where clause. Try getting rid of them as they are hindering the use of indexes, if any, on any of the columns.
Also the guidelines in the link provided are the best starting point. -
Need Help: Complex SQL statement
select segment3, 0 "Other Income"
, 0 "Sales of Services"
, 0 "Personnel Costs"
, 0 "Other Staff Cost"
, 0 "General Admin"
, 0 "Travel"
, 0 "Collaborator"
, 0 "Training"
, 0 "Capital"
, nvl(round(sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)),0),0) "Overhead"
, 0 "Finance Charges"
from PAYMAN.SNP_OP_DETAIL@OFA
where segment3= x.new_cc and period_name = p_period
and segment2 in (select acc_t from CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
group by segment3
Please I don't understand select segment3, 0 "Other Income"....there's no column called 0, what is the 0s doing in the select statement?
Secondly, I don't understand from PAYMAN.SNP_OP_DETAIL@OFAHi,
OlaTunde wrote:
select segment3, 0 "Other Income"
, 0 "Sales of Services"
, 0 "Personnel Costs"
, 0 "Other Staff Cost"
, 0 "General Admin"
, 0 "Travel"
, 0 "Collaborator"
, 0 "Training"
, 0 "Capital"
, nvl(round(sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)),0),0) "Overhead"
, 0 "Finance Charges"
from PAYMAN.SNP_OP_DETAIL@OFA
where segment3= x.new_cc and period_name = p_period
and segment2 in (select acc_t from CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
group by segment3
Please I don't understand select segment3, 0 "Other Income"....there's no column called 0, what is the 0s doing in the select statement?Columns are one of the expressions that can be in a SELECT clause. There are many other kinds of expressions, including liteals (as in this example), pseudo-columns, functions, and compound expressions that are also allowed.
Consider the following query:
SELECT deptno AS raw_detpno
, 1 + deptno AS one_plus
, 0 + deptno AS zero_plus
, 0 AS zero
FROM scott.dept
ORDER BY deptno
;Output:
RAW_DETPNO ONE_PLUS ZERO_PLUS ZERO
10 11 10 0
20 21 20 0
30 31 30 0
40 41 40 0No doubt you're familiar with using table columns (such as deptno) by themselves as an expression, as in the output column raw_deptno.
You're probably familiar with using a table column and a numeric literal together, as in the ouptuput columns one_plus and zero_plus.
It's also allowed to use numeric literals by themselves, as in the output column called zero.
Expressions are part of the SQL language, so you can read about them in the SQL language manual:
http://docs.oracle.com/cd/E11882_01/server.112/e26088/expressions001.htm#sthref1844
Secondly, I don't understand from PAYMAN.SNP_OP_DETAIL@OFA@OFA is a database link. See
http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries010.htm#sthref2287 -
Hi Friends,
I am using below query to genearet one report.
{code}
distinct a.plan_id,
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = a.plan_id)
"EXT_PAN_REF",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = b.depends_on_ba_plan_id)
"EXT_PAN_REF1",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = c.drp_plan_id)
"EXT_PAN_REF2",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = d.srp_plan_id)
"EXT_PAN_REF3",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = e.DRP_TO_DRP_PLAN_ID)
"EXT_PAN_REF4",
(SELECT external_plan_ref
FROM bk9_t_plan
WHERE plan_id = f.srp_plan_id)
"EXT_PAN_REF5"
FROM BK9_T_BUSINESS_ACTIVITY a,
BK9_T_BA_DEPENDENCY b,
BK9_T_BA_DRP_DEP c,
BK9_T_BA_SRP_DEP d,
BK9_T_DRP_DEPENDENCY e,
BK9_T_SYSTEM_DEPENDENCY f
WHERE a.plan_id = b.ba_to_ba_plan_id
AND a.plan_id = c.ba_plan_id
AND a.plan_id = d.ba_plan_id
AND c.drp_plan_id = e.DRP_TO_DRP_PLAN_ID
AND e.DRP_TO_DRP_PLAN_ID = f.drp_plan_id
{code}
My output is like this :
{code}
22767 19093 19095 19049 19049 19059
22767 19093 19095 19049 19049 19060
22767 19093 19095 19062 19062 19060
22767 19093 19095 19062 19062 19061
22768 19094 19093 19062 19062 19060
22768 19094 19093 19062 19062 19061
{code}
But What i am looking is like this.
{code}
22767 19093 19095 19049 19049 19059
22767 19060
22767 19093 19095 19062 19062 19060
22767 19061
22768 19094 19093 19062 19062 19060
22768 19061
{code}
Please help.Hi,
Could you please illuminate our minds and spend a bit of time in explaining the logic? That will be much easier without reading the crystal ball which nobody has it here.
Please read: Re: 2. How do I ask a question on the forums?
And please provide sample data (create table and insert statement), description of the logic, database version and everything else which is specified in the FAQ
Regards.
Al -
Hi,
I want to generate material wise stock report.
Report must contain the following
CNT_DESC TOTAL_BAGS TOTAL_WEIGHT
I am getting the correct result. But i have a doubt. Is there any other efficient or optimal query for solving this?
The followings are the query to retrieve data.
SELECT CT.cnt_count,
NVL(
SELECT SUM(lvyp_weight)
FROM tb_lvm_yarnprod
WHERE lvyp_deleted= 'N'
AND lvyp_countno = CT.cnt_seqno
AND lvyp_proddate <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS PROD,
NVL
SELECT SUM(lvyp_nbags)
FROM tb_lvm_yarnprod
WHERE lvyp_deleted= 'N'
AND lvyp_countno = CT.cnt_seqno
AND lvyp_proddate <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS PRODBAGS,
NVL
SELECT SUM(lypd_weight)
FROM tb_lvm_yarnpurchase, tb_lvm_yarnpurchasedet
WHERE lyp_deleted='N'
AND lypd_seqno_fk= lyp_seqno_pk
AND lypd_countno = CT.cnt_seqno
AND lyp_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS PUR,
NVL
SELECT SUM(lypd_nbags)
FROM tb_lvm_yarnpurchase, tb_lvm_yarnpurchasedet
WHERE lyp_deleted='N'
AND lypd_seqno_fk= lyp_seqno_pk
AND lypd_countno = CT.cnt_seqno
AND lyp_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS PURBAGS,
NVL
SELECT SUM(lysrd_weight)
FROM tb_lvm_yarnsalesret, tb_lvm_yarnsalesretdet
WHERE lysr_deleted='N'
AND lysrd_seqno_fk=lysr_seqno_pk
AND lysrd_countno=CT.cnt_seqno
AND lysr_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS SALERET,
NVL
SELECT SUM(lysrd_nbags)
FROM tb_lvm_yarnsalesret, tb_lvm_yarnsalesretdet
WHERE lysr_deleted='N'
AND lysrd_seqno_fk=lysr_seqno_pk
AND lysrd_countno=CT.cnt_seqno
AND lysr_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS SALERETBAGS,
NVL
SELECT SUM(lyrkd_weight)
FROM tb_lvm_yarnretfromknit, tb_lvm_yarnretfromknitdet
WHERE lyrk_deleted='N'
AND lyrkd_seqno_fk = lyrk_seqno_pk
AND lyrkd_countno =CT.cnt_seqno
AND lyrk_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS RETKNIT,
NVL
SELECT SUM(lyrkd_nbags)
FROM tb_lvm_yarnretfromknit, tb_lvm_yarnretfromknitdet
WHERE lyrk_deleted='N'
AND lyrkd_seqno_fk = lyrk_seqno_pk
AND lyrkd_countno =CT.cnt_seqno
AND lyrk_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS RETKNITBAGS,
NVL
SELECT SUM(lysd_weight)
FROM tb_lvm_yarnsales, tb_lvm_yarnsalesdet
WHERE lys_deleted='N'
AND lysd_seqno_fk = lys_seqno_pk
AND lysd_countno=CT.cnt_seqno
AND lys_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS SALE,
NVL
SELECT SUM(lysd_bags)
FROM tb_lvm_yarnsales, tb_lvm_yarnsalesdet
WHERE lys_deleted='N'
AND lysd_seqno_fk = lys_seqno_pk
AND lysd_countno=CT.cnt_seqno
AND lys_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS SALEBAGS,
NVL
SELECT SUM(yissd_weight)
FROM tb_lvm_yarnissue, tb_lvm_yarnissuedet
WHERE yiss_deleted='N'
AND yissd_countno =CT.cnt_seqno
AND yiss_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS ISS,
NVL
SELECT SUM(yissd_nbags)
FROM tb_lvm_yarnissue, tb_lvm_yarnissuedet
WHERE yiss_deleted='N'
AND yissd_countno =CT.cnt_seqno
AND yiss_date <= TO_DATE('28/12/2008', 'dd/mm/yyyy')
0
)AS ISSBAGS
FROM tb_lvm_counts CT
ORDER BY CT.cnt_count;TOTAL_BAGS = (PROD + PUR + SALERET + RETKNIT) - (SALE + ISS)
TOTAL_WEIGHT = (PRODBAGS + PURBAGS + SALERETBAGS + RETKNITBAGS) - (SALEBAGS + ISSBAGS)
Will it get slow, while data gets increased? Is there any other efficient way for solving the above?
Thanks & RegardsHi,
Thank you for all your valuable replies....
See the followings are the table design... I hope now you can understand clearly...
SQL> desc tb_lvm_counts;
Name Null? Type
CNT_COUNT VARCHAR2(20)
CNT_SEQNO NOT NULL NUMBER
SQL> desc tb_lvm_yarnprod;
Name Null? Type
LVYP_SEQNO_PK NOT NULL NUMBER
LVYP_PRODDATE NOT NULL DATE
LVYP_COUNTNO NOT NULL NUMBER
LVYP_LOTNO VARCHAR2(5)
LVYP_NBAGS NUMBER
LVYP_WEIGHT NOT NULL NUMBER(13,3)
LVYP_BAGNO VARCHAR2(15)
LVYP_DELETED VARCHAR2(1)
SQL> desc tb_lvm_yarnpurchase;
Name Null? Type
LYP_SEQNO_PK NOT NULL NUMBER
LYP_INVNO NOT NULL VARCHAR2(15)
LYP_PARTYNO NOT NULL NUMBER
LYP_JOBNO NOT NULL VARCHAR2(10)
LYP_INVAMOUNT NUMBER(12,2)
LYP_RCPDATE NOT NULL DATE
LYP_DATE NOT NULL DATE
LYP_VEHNO VARCHAR2(15)
LYP_FREIGHT NUMBER
LYP_DELETED VARCHAR2(1)
SQL> desc tb_lvm_yarnpurchasedet;
Name Null? Type
LYPD_SEQNO_FK NOT NULL NUMBER
LYPD_COUNTNO NOT NULL NUMBER
LYPD_NBAGS NUMBER
LYPD_LOTNO VARCHAR2(5)
LYPD_WEIGHT NOT NULL NUMBER(13,3)
LYPD_SEQNO_PK NOT NULL NUMBER
SQL> desc tb_lvm_yarnsalesret;
Name Null? Type
LYSR_SEQNO_PK NOT NULL NUMBER
LYSR_INVNO NOT NULL VARCHAR2(10)
LYSR_PARTYNO NOT NULL NUMBER
LYSR_JOBNO NOT NULL VARCHAR2(15)
LYSR_RCPDATE NOT NULL DATE
LYSR_DATE NOT NULL DATE
LYSR_REMARKS VARCHAR2(100)
LYSR_DELETED VARCHAR2(1)
SQL> desc tb_lvm_yarnsalesretdet;
Name Null? Type
LYSRD_SEQNO_FK NOT NULL NUMBER
LYSRD_COUNTNO NOT NULL NUMBER
LYSRD_LOTNO VARCHAR2(5)
LYSRD_NBAGS NUMBER
LYSRD_WEIGHT NOT NULL NUMBER(13,3)
LYSRD_SEQNO_PK NOT NULL NUMBER
SQL> desc tb_lvm_yarnretfromknit;
Name Null? Type
LYRK_SEQNO_PK NOT NULL NUMBER
LYRK_DCNO NOT NULL VARCHAR2(15)
LYRK_DATE NOT NULL DATE
LYRK_REMARKS VARCHAR2(100)
LYRK_DELETED VARCHAR2(1)
SQL> desc tb_lvm_yarnretfromknitdet;
Name Null? Type
LYRKD_SEQNO_FK NOT NULL NUMBER
LYRKD_COUNTNO NOT NULL NUMBER
LYRKD_LOTNO VARCHAR2(5)
LYRKD_NBAGS NUMBER
LYRKD_WEIGHT NOT NULL NUMBER(13,3)
LYRKD_SEQNO_PK NOT NULL NUMBER
SQL> desc tb_lvm_yarnsales;
Name Null? Type
LYS_SEQNO_PK NOT NULL NUMBER
LYS_INVNO NOT NULL VARCHAR2(15)
LYS_PARTYNO NOT NULL NUMBER
LYS_JOBNO NOT NULL VARCHAR2(10)
LYS_DATE NOT NULL DATE
LYS_BAGNO VARCHAR2(10)
LYS_DELETED VARCHAR2(1)
SQL> desc tb_lvm_yarnsalesdet;
Name Null? Type
LYSD_SEQNO_FK NOT NULL NUMBER
LYSD_COUNTNO NOT NULL NUMBER
LYSD_LOTNO VARCHAR2(5)
LYSD_BAGS NUMBER
LYSD_WEIGHT NOT NULL NUMBER(13,3)
LYSD_SEQNO_PK NOT NULL NUMBER
SQL> desc tb_lvm_yarnissue;
Name Null? Type
YISS_PONO NOT NULL VARCHAR2(10)
YISS_DCNO NOT NULL VARCHAR2(10)
YISS_DATE NOT NULL DATE
YISS_SEQNO NOT NULL NUMBER
YISS_DATETIME DATE
YISS_DELETED VARCHAR2(1)
YISS_BAGNO VARCHAR2(15)
SQL> desc tb_lvm_yarnissuedet;
Name Null? Type
YISSD_SEQNO_FK NOT NULL NUMBER
YISSD_LOT VARCHAR2(5)
YISSD_COUNTNO NOT NULL NUMBER
YISSD_WEIGHT NOT NULL NUMBER(13,3)
YISSD_SEQNO_PK NOT NULL NUMBER
YISSD_NBAGS NUMBERThanks & Regards -
Need help for SQL Query last 5 mins Records.
I need the data between the last five minutes from a table which contains Timeid Column and data type is date.
select sysdate,(sysdate-((mod(extract(minutes from systimestamp),5)+5)/24/60)-((extract(second from systimestamp))/24/60/60)) Start_date,
(sysdate-((mod(extract(minutes from systimestamp),5))/24/60)-((extract(second from systimestamp))/24/60/60)) End_Date;
Suppose now the current time is 01:20:00PM then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:00 10/18/2007 01:10:01 10/18/2007 01:15:00
Suppose now the current time is 01:20:01 then the output should be from
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:15:01 10/18/2007 01:20:00
The output i am getting where as i need the output shown above.
Current Date & Time Start Date & Time End Date & Time
10/18/2007 01:20:01 10/18/2007 01:14:59 10/18/2007 01:19:59SQL> select sysdate,
2 sysdate -
3 (decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
4 mod(to_number(to_char(sysdate,'sssss')),300))+300)/(24*60*60 )
5 st_time,
6 sysdate -
7 decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
8 mod(to_number(to_char(sysdate,'sssss')),300))/(24*60*60 )
9 end_time
10 from dual;
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:46 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:39:59 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:00 18-oct-2007 16:30:00 18-oct-2007 16:35:00
SQL> /
SYSDATE ST_TIME END_TIME
18-oct-2007 16:40:01 18-oct-2007 16:35:00 18-oct-2007 16:40:00 -
Date formats for SQL statements used by recordset object
Hi,
Date formatting appears to be quite problematic for Business One. I did a forum search for date issues and I don't think I saw any of them with an "answered" status. I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005. I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine. We don't have a problem as long as our machines are localized as USA.
I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field. So this is a date that is not entered by the user. The result of this function is consistent with the localization parameters on my machine. We have two other date fields on the form where the user must type in the date.
As a test, I changed my machine to the UK parameters. I then set up the language parameters of Business One for English(United Kingdom). I changed the date format specifications in Business One so that its format is dd/mm/yy. I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy. I then typed in the two other dates in the same format and added the record to the database. The form's table is user-defined.
I dismissed the form then brought it back up loaded with the new record. The date that was entered by the function appeared in USA format (mm/dd/yy). The dates that were typed in appeared in the Business One format (dd/mm/yy). This of course is not consistent.
When I looked at what got into the database, the formats were the opposite. Weird! To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function. It didnt matter what format I used for the WHERE clause, the record came up. Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
Thanks,
MikeIan,
Here's what I'm concerned about: Im using the date in a WHERE clause.
Assume the date is Aug 3, 2007.
"SELECT * FROM Table WHERE StartDate > 8/3/2007"
OR
"SELECT * FROM Table WHERE StartDate > 3/8/2007"
If the client machine is set up as USA, the today function will provide the date as formatted in the first query. If the database server is setup as lets say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
If the client machine is set up as UK, the today function will provide the date as formatted in the second query. If the database server is setup as lets say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
In both cases it would be wrong.
I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine. I need to then be able to concatenate those date parts for the WHERE clause so that the localization specifications of the database server dont matter.
Thanks,
Mike -
Buffer size for SQL statement using JDBC calls
I need to find out the buffer size for SQL statements in jave/JDBC because I need to insert or update a field that could be up to 4KB in size.
I'm not sure that I follow the question; I'm not sure which buffer size you're referring to.
If you have a field that can store up to 4k worth of data, you would create a VARCHAR2(4000) column in the Oracle database (assuming it is character data) or a BLOB column (if the data is binary). Either of those two fields can be populated from JDBC.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De.
Maybe you are looking for
-
Difference between tRFC and RFC
Hi Experts, Can any one help me in details to differentiate tRFC from RFC in their application perspective. And also let me know the role of ALE and BAPI in both the connection log.ie,Where we have to use ALE and BAPI. Regards Kumar
-
Jumping to First & Last Pages of a PDF Doc.
I am using Acrobat 9 Pro with Windows XP Pro. In Acrobat 8 Standard, I was able to jump to the first or last pages of a documents without have to use the page navigation arrows. Can I jump to the first and last pages of a PDF doc. in Acrobat 9 Pro? I
-
I can't log into FaceTime any suggestions?
Having trouble logging into facetime. I get a message that I cannot connect with the FaceTime server. I can connect with everything else .
-
Hi , My requirement is -- i have to Bold the values which will start with "abc" for a dimension member "aaa" and values should be "n/a" if they are above or below >499 or < -499. In conditional format have written the condition for this like member n
-
How to maintain a flash web site
Hello everybody, I know about Java, Javascript, html but unfortunatly I don't know anything about Flash. A friend of mine is going to create a website for my jazz group. (the one I have created can be improved!! just have a look at my web page and yo