SQL & PL/SQL :: Write Outer Query Which Will Bring Individual Records Which Don't Sum Up To Zero

May 9, 2011

I have to write a sub query / build a logic for the below.

There are several accounts which should have a zero balance i.e sum of all the amoutns in that account should be zero. If they are non zero , i have to report which amounts make up non zero balance.

If i have amts as +20 , -20 , -30,-10 i.e the sum is -40 indicating a non zero amount. I need the entire details of the records which makes up non zero sum. So in above case details related to -30 aand -10.

I'm using a sum group clause on several fields at which sum is required to be checked ie. date , account , currency . query that will bring individual records that don't make the sum zero.

Is it possible to write a outer query which will bring individual records which don't sum up to zero.

View 14 Replies


ADVERTISEMENT

SQL & PL/SQL :: Write Query To Delete Similar Records In Particular Fields (columns) In Different Tables

Jul 17, 2012

write a query to delete similar records in particular fields(columns) in different tables.

View 2 Replies View Related

SQL & PL/SQL :: Sequence Into Individual Records

Feb 23, 2010

create table x (
field1 varchar2(10) );
insert into x values ('001-002');
insert into x value ('0150-0152');
insert into x value ('0100-0101');

create table y (
field varchar2(6));

recortd in table y
001
002
0150
0151
0152
0100
0101

View 15 Replies View Related

SQL & PL/SQL :: Distinct And Individual Records In Single Or Minimum Pass(es)

Feb 21, 2012

I have following data

select rowid,object_name,object_type from do;

ROWID OBJECT_NAME OBJECT_TYPE
------------------ ------------------------------ ------------------
AAA/wuAAHAAAW73AAA CON$ TABLE
AAA/wuAAHAAAW73AAB I_COL2 INDEX
AAA/wuAAHAAAW73AAC I_USER# INDEX
AAA/wuAAHAAAW73AAD C_TS# CLUSTER
AAA/wuAAHAAAW73AAE I_OBJ# INDEX
AAA/wuAAHAAAW73AAF I_CON2 INDEX

6 rows selected.

I want it in the following manner

select rowid,object_name,object_type from do;

ROWID OBJECT_NAME OBJECT_TYPEGROUP
------------------ ------------------------------ ---------------------------
AAA/wuAAHAAAW73AAA CON$ TABLE2
AAA/wuAAHAAAW73AAB I_COL2 INDEX1
AAA/wuAAHAAAW73AAC I_USER# INDEX1
AAA/wuAAHAAAW73AAD C_TS# CLUSTER1
AAA/wuAAHAAAW73AAE I_OBJ# INDEX1
AAA/wuAAHAAAW73AAF I_CON2 INDEX1

6 rows selected.

Here the GROUP is changing when the data type is changing and thus for same data type the group shall remain the same As of now this is achieved by - first selecting distinct object_type, then it's mod(rownum,<input variable) and this result of 'mod' is doing the grouping which is the retrieved along with rowid of all individual record

Present query is as following and it is not much efficient

SELECT DO.ROWID RWID, RID
FROM DO,
(
SELECT OT,CASE MOD(ROWNUM,:v) WHEN 0 THEN :v ELSE MOD(ROWNUM,:v) end as RID
FROM(
(SELECT DISTINCT OBJECT_TYPE OT

[code]....

I tried using sequence with cycle but it gave different results. Even I tried following but it did not gave satisfactory results

select d.rowid,d.object_type,x.x1 from do d,(select distinct object_type,mod(rownum,:v) x1 from do where
created>'01-jan-2008')x where d.object_type=x.object_type and created>'01-jan-2008';

In short the query needs Distinct with mod(rownum) and individual records in a single pass The mod(rownum) i.e. group shall change when the object_type changes but then shall remain constant through out the particular object_type.

View 9 Replies View Related

Force Query To Always Bring Back Certain Amount Of Rows

Jun 24, 2010

Is there a way to force a query to ALWAYS bring back a certain amount of rows, even if some of the rows are blank?

I know there's a way in MSSQL but not sure how to in SQL+

View 7 Replies View Related

How To Calculate Individual Sums Of Multiple Columns In Single Query

May 13, 2013

Using Oracle 11gR2 on windows 7 client. I have a question on calculating sum() on multiple columns on different columns and store the results in a view. Unfortunately I could not post the problem here as it keeps on giving error "Sorry, this content is not allowed", without telling where or what it is! So I had to post it in the stack-overflow forum, here is the link: [URL] .........

View 6 Replies View Related

SQL & PL/SQL :: Query Without Outer Join

Nov 2, 2012

I have an attendance table in which we have empno, time_in, time_out..etc.

I want to create a matrix report that should shows all dates of any specific required month in columns and present empno in rows and time_in in cells.

I did it with using a temporary table by filling all the required dates and outer join with attendance table, it works fine, but it takes so long, is there any other better fast way to do it?

View 7 Replies View Related

SQL & PL/SQL :: Sub Query Using Outer Parameter?

Apr 10, 2010

How to give table1 column to subquery with table2 :
(select t1.*, sq.*

from table1 t1,
(select a,b,c from table2 where col1= t1.col1) sq
where ...

View 4 Replies View Related

SQL & PL/SQL :: How To Use Outer Join Condition In A Query

Jun 27, 2013

How to use outer join condition in my below query. In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.

I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh including other conditions. I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.

SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
[code].......

View 10 Replies View Related

SQL & PL/SQL :: How To Refer Result Of Inner Query (analytic Function) In Outer One

Feb 23, 2012

How can I refer the result of inner query - max(t.col3) in the outer query. I tried the 'group by' but it is not performing well

select
t1.col5, t1.col6
from t1,
(select t.col1
t.col2
[code].......

View 8 Replies View Related

PL/SQL :: Code_combination_id Doesn't Exist In Outer Query Table

Aug 20, 2013

I have query in which having some issues with outer join.When I run the inner query, I am getting 121 rows and when i put outer query and run it, I am getting 69 rows coz the code_combination_id does not exist in the outer query table.But even when I say ( + ) , its not giving 121 rows..  

SELECT  DISTINCT t1.* --hr3.NAME prj_org --, p.segment1 prj_no, p.org_id --pt.task_number, pt.task_name,  --paei.expenditure_type, pacdl. acct_ currency_code functional_curr from        (    SELECT DISTINCT gll.ledger_id, gljeh.period_name "Fiscal Period", gll.NAME "Company Name", gljeh.NAME "Journal Name ",  gljeh.je_source "Accounting Document Source",  gljeb.NAME "Journal batch name", gljel. accounted_ dr,glcc.code_ combination_ id,glcc.segment1,glcc.segment2,glcc.segment3,glcc.segment4,glcc.segment5,glcc.segment6,glcc.segment7,glcc.segment8,gljel. accounted_ cr  FROM gl_je_headers gljeh, gl_je_batches gljeb,  gl_je_lines gljel,gl_code_combinations glcc, gl_ledgers gll  WHERE gll.ledger_id =
[code]....

View 5 Replies View Related

Server Utilities :: Sql Loader Do Not Load Records And Write Them Into Badfile

Oct 18, 2012

My loader start and say commit reach logical records 8 as there are 8 records but donot load them and write them into badfile. there is no logs file generation happing so unable to trace.

table
CREATE TABLE ERS_NRT_SRC
(
POLL_ID NUMBER(10) NULL,
TIME_OF_POLL DATE NULL,
SERVICE_DESC VARCHAR2(50 BYTE) NULL,
LOCATION_AGENT VARCHAR2(30 BYTE) NULL,
TRANSACTION_NAME VARCHAR2(50 BYTE) NULL,

[code]...

View 6 Replies View Related

SQL Server Query - Oracle Does Not Support OUTER APPLY Statement

Feb 1, 2012

DECLARE @MainTable TABLE (UniqueID INTEGER, Category VARCHAR(200), WeekDate DATETIME, VALUE INTEGER)
INSERT INTO @MainTable VALUES(123, 'Shirts', '10/07/2011', 5000)
INSERT INTO @MainTable VALUES(123, 'Shirts', '10/14/2011', 8000)
INSERT INTO @MainTable VALUES(124, 'Pants', '10/07/2011', 4000)
INSERT INTO @MainTable VALUES(125, 'Shorts', '10/14/2011', 8000)
INSERT INTO @MainTable VALUES(126, 'Shoes', '10/21/2011', 9000);
--select * from @MainTable;
[code]...

The query works with all the CTEs up to the last select statement. Oracle does not support the OUTER APPLY statement, how should the last piece be written to make it work in Oracle?

View 1 Replies View Related

SQL & PL/SQL :: How To Write Correlated Sub Query

Sep 13, 2010

I have employee, location, city tables, I have written following code to use joins

select ename from employee e, location l, city c
where e.c_locationid= l.locationid and l.cityid= c.cityid and c.cityname='XYZ';

The same can be written by using non- correlated sub query as follow..

select ename
from employee
where c_locationid in (select locationid from location where
cityid in (select cityid from city where cityname='XYZ'))

I need to implement the same concept using correlated sub query...

View 15 Replies View Related

SQL & PL/SQL :: How To Write Column To Row In A Query

Nov 17, 2005

How to write column to row...in a SQL query?

For example..

SQL> select empno,deptno from emp where empno = 7369;
EMPNO DEPTNO
---------- ----------
7369 20
7369 10
7369 40

The above output to be written in a single row like given below.

7369 20 10 40

1) Actually it may change dynamically...It may be 2 records for some values and there may be 10 records for some value and different for some other

2) It should be in SQL query only..Not in procedures or functions.

View 9 Replies View Related

Forms :: How To Write Query For ADD Button

Jul 23, 2010

Without using any templates, i created a customized sample form....now i want to add data thru that form....i dont know where to write code and what is code if i want to add data?

View 9 Replies View Related

SQL & PL/SQL :: How To Write Query To Convert XML To Table

Oct 15, 2012

I have table xx_xml_test m which have row single entry

<logentry
revision="3">
<author>MA111300</author>
<date>2012-10-03T12:42:40</date>
<paths>
<path
[code].......

i want convert the table like below

Revision author date kind action path
3 MA111300 2012-10-03 12:42:40 file A /root.txt
3 MA111300 2012-10-03 12:42:40 file A /sample2/test_2.txt

View 2 Replies View Related

SQL & PL/SQL :: Write Query To Show Monthly Salary?

Jul 12, 2012

i have table structure (emp_no, emp_sal,emp_startwork)

i want query to show the monthly salary such as jan month salary Feb month salary

View 2 Replies View Related

SQL & PL/SQL :: Write A Query To See How Many (no) Employees Getting Salary 3000?

Dec 21, 2010

write a query to see how many(no) employees getting salary 3000 & what are their names respectively.

View 2 Replies View Related

SQL & PL/SQL :: Write A Query In Order To Receive A New Table?

Apr 23, 2012

i need to write a query in order to receive a new table.

select table_name,col1, null col2
from
(SELECT b.table_name, b.col1 col1, a.CountPrimaryKeys
from
(SELECT user_constraints.table_name,
COUNT(user_cons_columns.column_name) CountPrimaryKeys

[code].......

View 21 Replies View Related

SQL & PL/SQL :: Write A Single Query Showing Number Of Requests

Jan 15, 2011

I need to write a single query showing the number of requests (job_no) in my organization sections (1A,3A,4C,9Z....etc) based on these conditions..Less than 2 months & between 2 and 6 & between 6 and 12month & more than 12 months in my organization sections.

--Table structure

SQL> desc job_transfer
Name
----------------------
JOB_NO (Request number)
IN_SECT (name of entered section)
IN_DATE (date entered the section)
OUT_SECT
OUT_DATE (date went out from section)

I tried using UNION ALL but it didnt work fine.

View 3 Replies View Related

SQL & PL/SQL :: Write Select Query To Get Sum Of Quantity For Each Type Of Item?

May 26, 2010

I want to write select query to get sum of quantity for each type of item ,in the table I have itemnum,itemtype and quantity ,type have value(A,B,C,....)

the result will be like that ex:

item.No A B C D ....

10 50 60 80 20

--- 50 will be sum(quantity) for item type A

how can I do that, I mean how can I retrieve many column from the same field?

View 17 Replies View Related

Client Tools :: Possible To Write Select Query O/p In HTML Tag?

Jan 24, 2011

is it possible to write select query o/p in html tag?

View 6 Replies View Related

SQL & PL/SQL :: Write A Query Which Shows Data Of One Table Not Present In Other?

Apr 3, 2011

I am writing following query
SELECT DISTINCT a.list_type_code, a.list_type_name
FROM jls_list_type a, jls_list_control b
WHERE b.jalsa_srl = :jalsa_srl
AND b.list_no != a.list_type_code
ORDER BY list_type_code

I just want to display only those records from JLS_LIST_TYPE which is not present in other table JLS_LIST_CONTROL ... for this i wrote above query but it is not working.

View 9 Replies View Related

Client Tools :: Write Sql Query O / P In HTML Page?

May 31, 2012

is it possible to write sql query o/p in HTML page?

View 3 Replies View Related

SQL & PL/SQL :: Write Single Row Sub-query Which Returns ID_2 Value Of Row With Del_flag As N

Feb 13, 2012

In my main query, There is a single row sub query which returns row with del_flag as N. Now in my table, there are 2 rows getting added from the incoming feed with del_flag as Y & N.

Here is my Table:

ID_1 DEL_F ID_2
-------------------------------
16643162 Y 49696
16643162 N 16643162
16612344 Y 98888

So how can i write a single row sub-query which returns ID_2 value of a row with del_flag as N. If there is no row with DEL_F as N, it should return ID_2 value of row with DEL_F as Y.i have tried below query, but it showing the error.

select
(case
when min(del_f)='N' then to_number(ID_2)
when min(del_f)='Y' then to_number(ID_2)
end ) ID_2 from table where ID_1=?

Here, im passing ID_1 value from main query

View 8 Replies View Related

PL/SQL :: Write Dynamic SQL To Query Unknown Number Of Columns

Jun 6, 2012

I need to write a dynamic SQL in PL SQL to query an unknown number of columns. Let me take a simple example query here:

SELECT FIRST_NAME, LAST_NAME FROM VENDOR_CONTACTS

If I have known the number of columns, e.g. querying two columns: "FIRST_NAME" and "LAST_NAME", I can write a DYNAMIC SQL based on the template in table 8-2 of URL....

DECLARE
stmt_str varchar2(200);
cur_hdl int;
rows_processed int;
FIRST_NAME varchar2(200);
LAST_NAME varchar2(200);
BEGIN
cur_hdl := dbms_sql.open_cursor; -- open cursor
stmt_str := 'SELECT FIRST_NAME, LAST_NAME FROM VENDOR_CONTACTS';
[code]....

However, if I wish to write a dynamical sql to query these two columns for a more general purpose (which should meet the requirement to query different number of columns, e.g. three columns, FIRST_NAME, LAST_NAME, BIRTHDAY instead of two columns FIRST_NAME and LAST_NAME). To do this I first try to query the same two columns but using a different method, following URL.....My code for the same query has error, and I cannot solve it.

DECLARE
stmt_str varchar2(200);
cur_hdl int;
rows_processed int;
l_columns dbms_sql.desc_tab;
l_dummy NUMBER;
l_value NUMBER;
[code]....

View 7 Replies View Related

Export/Import/SQL Loader :: How To Write The Query Option In Expdp

Jun 5, 2012

how to write the query option in expdp ....in expdp by using query option...

where columnname between '05-May-12 02:57:00.000 AM' and '6-May-12 02:59:59.999 AM';

View 4 Replies View Related

Write A Query Based On Inventory On Hand Packed Quantity

Jul 18, 2013

which table do I have to use to get the Inventory On Hand Packed Quantity  based on Oracle EBS Suite using backend? 

View 2 Replies View Related

SQL & PL/SQL :: Returning List Of Records That Do Not Have Associated Records From A Sub-query

Sep 6, 2010

I am running a query in our Clarity PPM database to return a list of all Support projects. This returns a simple list of project code and project name:

The query has the project resource tables associated with it, so I am able to list all resources allocated to the project. But for now i am only selecting a DISTINCT list of projects.

Query for anyone interested:

Select distinct
Project_code,
project_name
from
niku.nbi_project_current_facts nbip,
niku.odf_ca_project cst,
niku.prtask t,
[code]........

I have a separate query which returns a list of support resources.

select res.full_name, res.unique_name , dep.description
from niku.srm_resources res,
niku.pac_mnt_resources pac,
niku.departments dep
where res.unique_name = pac.resource_code
and pac.departcode = dep.departcode
and res.is_active = 1
and description like 'IMS%'
and UPPER(dep.description) like '%SUP%'

What I need to be able to do in the first query, is return only projects that do NOT have a resource that appears in the resource list in the second query.

(the res.unique_name field in the second query can be linked to the same in the first query)

Logically, the process would be:
1. Identify Support Project
2. Identify Resources allocated to the project team
3. Compare with List of Support Resources
4. If any Resources in that list do NOT appear on the project, then return project.

View 18 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved