Sum(amount) from 4 tables in sql
Hi, Everyone,
I have 4 tables which has pr_code,amount in each table.
I need the sum(amount) for each pr_code from all the four tables?
How could i write a sql to achieve this?
Please help!
Regards
Su
one option would be:
select sum(cnt) sum_cnt
from (select count(*) cnt from user_tables
union all
select count(*) cnt from user_objects
union all
select count(*) cnt from user_indexes
SUM_CNT
151
Similar Messages
-
HI
there is no such column like po_amount in po_headers_all table then how can i get po total amount(including tax amount) from po_headers_all table or else tell me how to get data from views in R12
As we are using sql developer tool to build queries in our project
With regards
sivaPO line total is not included the tax, to View the tax amount (N) Action-> manage tax
1) You have to sum up the lines to get the PO total,
select ph.segment1 po_num, sum ( (pl.unit_price * pl.quantity)) price
from po_lines_all pl, po_headers_all ph
where pl.po_header_id = ph.po_header_id
and ph.type_lookup_code in ('STANDARD', 'BLANKET') --Add as per your requirement
-- and ph.segment1 = '2017'
-- and ph.org_id = 7852 --Use when you have multiple OU
group by ph.segment1
2) To get the tax
SELECT *
FROM ( SELECT lines.line_num line_number,
lines.item_description line_description,
dist.distribution_num dist_number,
dist.code_combination_id dist_code_combination_id,
NVL (dist.nonrecoverable_tax, 0) nonrecoverable_tax,
NVL (dist.recoverable_tax, 0) recoverable_tax,
NVL (dist.nonrecoverable_tax, 0)
+ NVL (dist.recoverable_tax, 0)
total_tax,
(NVL (dist.req_line_quantity, 0) * NVL (lines.unit_price, 0))
amount,
dist.org_id,
dist.DISTRIBUTION_ID
FROM po_requisition_lines_all lines, po_req_distributions_all dist
WHERE lines.requisition_line_id = dist.requisition_line_id
AND NVL (lines.cancel_flag, 'N') <> 'Y'
AND NVL (lines.modified_by_agent_flag, 'N') = 'N'
-- AND lines.requisition_header_id = :1
ORDER BY lines.line_num, dist.distribution_num) QRSLT
ORDER BY LINE_NUMBER, DIST_NUMBER
Join the po_distributions_all, po_lines_all & po_headers_all tables to get the specific value.
Thanks -
Adding Sum Totals from Multiple Tables in A single Document
Hello All,
I'm having trouble adding sum totals from multiple tables I've created in a Pages 09 doc. I putting together a spreadsheet for cost projections for a house remodel. I created tables for each room of the house. At the bottom of the document I'd like to have another table that takes the totals from each individual room and adds them up. Problem appears to be that each table has the same x/y axis labels so row and column numbers/letters are repeated so the final table can't quantify thing correctly.
Any easy solutions? I can't find anything that's helped in my search efforts.
Thanks,
JosefisJerry,
Thanks for the feedback. I thought that might be the case. And you were correct to assume I was more comfortable in Pages. I'm halfway through converting everything to numbers. In the end it will work great too. Just some different formatting/design choices to be made as numbers doesn't appear to be as versatile in the same way pages is with design. So far it looks pretty good though.
Thanks again,
Josefis -
Doubling Summed Numbers from Temp Table
I have a crystal report that uses an Oracle Stored Procedure. The stored procedure sums (using Oracle sum function) some of the data from another table into a temp table, does some additional data manipulation and then selects from the temp table. My problem is any of the data that was summed in the stored procedure is displaying as double in the Crystal Report, (e.g. a field that sums to 10 is displaying as 20 in the Crystal Report.) When I run this Stored Procedure from Oracle SQL Developer I get the correct data.
Could anyone tell me why this is happening and what to do to correct they problem? I am using Version 11.0.0.1282 of Crystal and Oracle 10g.
Thanks,
DebbieHi Debbie,
You also did not mention which DB driver you are using, ODBC, OLE DB or our native Oracle driver. Try one of the other ones to see they work. Could be an issue in the specific driver you are using.
Testing in Oracle will use the native client engine. Try using a third party SQL, ODBC or OLE DB test tool to verify running the SP works.
Thanks again
Don -
How to retrive the blob data from a table using sql query
Hi gurus,
I have a table which has " BLOB "content in a column .I want to view the data From BLOB column using sql query .It would be helpfull If some one share their idea.
Regards,
vardhani.You can use data templates.
See this: http://blogs.oracle.com/xmlpublisher/entry/blob_clob_raw_and_looooong
http://blogs.oracle.com/xmlpublisher/entry/inserting_blobs_into_your_repo
Thanks,
Bipuser -
Loading data from SAS tables to SQL server database
Hi Guys
I am championing a BI Proof of Concept project to create a self-service BI platform using tabular model parallel to our traditional BI platform on SAS.
I need to load certain SAS tables to SQL server database so I can start creating reports in SSAS. Appreciate if anyone can suggest the process that I can load the files to database engine as a scheduled job.
Appreciate your feedback and if further info needed please ask.
Cheers
MarkFrom VB6 there is not much alternative than to send row by row which indeed is slow.
But you could write a C# application which uses a table-valued parameter to load the data, and this could be streamed so that the client never has the hold the entire file. I have an example of this in this article on my web site:
http://www.sommarskog.se/arrays-in-sql-2008.html
You can also use the SqlBulkCopy class, but I don't have any example of this myself.
Erland Sommarskog, SQL Server MVP, [email protected] -
How to show data in a matrix form from a table using SQL
Dear Friends,
I have a table with three columns with the following data:
Market, Product, Date, Value
Market-A Product-A 01/01/04 34
Market-A Product-A 01/02/04 33
Market-A Product-A 01/03/04 67
Market-A Product-A 01/04/04 64
Market-A Product-B 01/01/04 34
Market-A Product-B 01/02/04 36
Market-A Product-B 01/03/04 77
Market-A Product-B 01/04/04 32
Market-B Product-C 01/01/04 25
Market-B Product-C 01/02/04 56
Market-B Product-C 01/03/04 45
Market-B Product-C 01/04/04 68
Market-B Product-D 01/01/04 78
Market-B Product-D 01/02/04 75
Market-B Product-D 01/03/04 32
Market-B Product-D 01/04/04 35
I have a requirement where in I have to filter the products based on market and then show in the following format on the screen:
After filtering based on Market-A (eg) the data should look like:
01/01/04 01/02/04 01/03/04 01/04/04
Product-A 34 33 67 64
Product-B 34 36 77 32
Kinldy suggest how can I write a query to get the data in this format using SQL
Thanks & Regards,
Vinayscott@ORA92> -- test data:
scott@ORA92> SELECT * FROM a_table
2 /
Market-A Product-A 01/01/04 34
Market-A Product-A 01/02/04 33
Market-A Product-A 01/03/04 67
Market-A Product-A 01/04/04 64
Market-A Product-B 01/01/04 34
Market-A Product-B 01/02/04 36
Market-A Product-B 01/03/04 77
Market-A Product-B 01/04/04 32
Market-B Product-C 01/01/04 25
Market-B Product-C 01/02/04 56
Market-B Product-C 01/03/04 45
Market-B Product-C 01/04/04 68
Market-B Product-D 01/01/04 78
Market-B Product-D 01/02/04 75
Market-B Product-D 01/03/04 32
Market-B Product-D 01/04/04 35
scott@ORA92> -- query:
scott@ORA92> SELECT product,
2 SUM (DECODE (the_date, to_date ('01/01/2004', 'mm/dd/yyyy'), value)) AS "01/01/04",
3 SUM (DECODE (the_date, to_date ('01/02/2004', 'mm/dd/yyyy'), value)) AS "01/02/04",
4 SUM (DECODE (the_date, to_date ('01/03/2004', 'mm/dd/yyyy'), value)) AS "01/03/04",
5 SUM (DECODE (the_date, to_date ('01/04/2004', 'mm/dd/yyyy'), value)) AS "01/04/04"
6 FROM a_table
7 WHERE market = 'Market-A'
8 GROUP BY product
9 /
Product-A 34 33 67 64
Product-B 34 36 77 32
scott@ORA92> -
I need to in SQL if possible sum the total from 6 different stores, who are all stored in a different database. I would prefer not to use a make table (again if possible) would just like a direct query using maybe CTE?
--Query 1
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
From store1
--Query 2
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
From store2
--Query 3
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
From store3
...and so on.
How can I Sum all of those sales in one query? So instead of having 3 values returned have one query that returns all the values?Since its just a sum you can even do this
Select Total1 + Total2 + Total3 AS Total
FROM (
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
As [Total1] From store1
)t1
CROSS JOIN
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
As [Total2] From store2
)t2
CROSS JOIN
Select sum(emp1Sales+emp2Sales+emp3Sales+man1Sales+man2Sales)
As [Total3] From store3
)t3
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Count rows from multiple tables using SQL only
Hi, I know this has probably been answered before, but I couldn't find the answer anywhere. Please help.
I'd like count(*) [rows] for all tables in database using SQL only - no PL/SQL
The result should be something like:
Table RowCount
DBA_TABLES 1000
DBA_USERS 50
etc.
Thanks!offcource write this script:
create or replace procedure count_tables (ip_schema VARCHAR2)
is
lv_owner VARCHAR2(100);
lv_table_name VARCHAR2(100);
lv_sql_statement VARCHAR2(2000);
lv_count_table NUMBER;
CURSOR c1 IS
SELECT owner, table_name
FROM all_tables
WHERE owner = ip_schema
ORDER BY table_name;
begin
dbms_output.put_line ('+--------------------------------------------------------------------+');
dbms_output.put_line ('¦ | | ¦');
dbms_output.put_line ('¦ Schema Name | Table Name | Number of Rows ¦');
dbms_output.put_line ('¦ | | ¦');
dbms_output.put_line ('¦------------------------------------------------------------------¦');
OPEN c1;
LOOP
FETCH c1 INTO lv_owner , lv_table_name;
EXIT WHEN c1%NOTFOUND;
lv_sql_statement := 'SELECT count(*) FROM ' || lv_owner || '.' || lv_table_name;
EXECUTE IMMEDIATE lv_sql_statement INTO lv_count_table;
IF lv_count_table > 0 THEN
dbms_output.put_line ('| '||rpad(lv_owner, 14, ' ')||'| '|| rpad(lv_table_name, 32, ' ')||'| '|| rpad(lv_count_table, 16, ' ')||' |');
-- dbms_output.put_line ('|---------------|---------------------------------|------------------|');
END IF;
END LOOP;
CLOSE c1;
dbms_output.put_line ('+--------------------------------------------------------------------+');
exception
WHEN OTHERS THEN
dbms_output.put_line ('owner: '||lv_owner||' - table: '||lv_table_name||' - '||sqlerrm);
end count_tables;
set serveroutput on size 1000000
exec count_tables
drop procedure count_tables; -
Data transfer from Oracle table to Sql Server
Hi Friends,
How can we transfer the data of one table from Oracle to Sql Server and keep refresh it everyday monrning 10 a.m?Also see:
http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a76960/hs_genco.htm#173
And from Tom Kyte:
...you could put the MS SQL server jdbc driver into the oracle database. then a
java stored procedure can open a connection to MS. This connection would not
have 2 phase commit abilities, distributed query or anything but would let you
query data from there and update it as well. -
How to return the same SUM value from two tables
Hello,
I have the following data:
SQL> SELECT * FROM t1;
T1_ID T1_VALUE
1 500
1 500
SQL> SELECT * FROM t2;
T2_ID T2_VALUE
1 1000
SQL> SELECT t1_id, SUM(t1_value), SUM(t2_value)
2 FROM t1, t2
3 WHERE t1_id = t2_id
4 GROUP BY t1_id;
T1_ID SUM(T1_VALUE) SUM(T2_VALUE)
1 1000 2000How is it possible that SUM(T2_VALUE) returns also 1000.
Thank youHere's one way:
with t1 as (select 1 t1_id, 500 t1_value from dual union all
select 1 t1_id, 500 t1_value from dual),
t2 as (select 1 t2_id, 1000 t2_value from dual)
select t3.t3_id, t3.t3_sum, t4.t4_sum
from (select t1_id t3_id, sum(t1_value) t3_sum from t1
group by t1_id) t3,
(select t2_id t4_id, sum(t2_value) t4_sum from t2
group by t2_id) t4
where t3.t3_id = t4.t4_id -
How to read BLOB column from a table in SQL or PL/SQL
I have table which is having one BLOB data type column . Ihave inserted few rows in that table . Now i want to see wheather BLOB column has been inserted properly or not . How to read that column through SQL or PL/SQL.
Can anyone help me to do this.You can only manipulate LOBs in PL/SQL because you have to use the DBMS_LOB package.
Check out the Oracle Developer's Guide -
Retreving Hexadecimal Values from a table using SQL query.
Hi,
I'm looking for a query to retreive Hexadecimal values contained in a column using SQL query.
The column contains the values of all types, alphanumeric, numeric and hexadecimal.
I need to retreive only hexadecimal values.
any help to me in this regard will be appreciated.
ThanksPresumably, you can be sure that any valid hex value is indeed MEANT to BE a hex value. For example the value 'ACE' is meant to be a hexadecimal value and not the word.
-
How to get sum amount (wrbtr) from table BSIS group by gjahr hkont monat
Hello! I am new to this forum, and to ABAP. Hope my question is not obvious.
I want to get sum amount from table BSIS, group by year, period an account. Normally I will try a SQL select like this:
SELECT gjahr monat hkont sum( wrbtr ) as wrbtr INTO CORRESPONDING FIELDS OF TABLE itab FROM BSIS WHERE (itabcond) GROUP BY gjahr monat hkont .
The problem is that the amount in field wrbtr is all positive. The result gets wrong. The debet/credit indicator shkzg determines what is positive/negative. How to solve this in the most efficient way? Should I read all accounting documents into an internal table, and loop through them, changing the sign, and then make some new select, or is there a better way?
Regards Dag-Egil
Message was edited by:
Dag-Egil Bull SletholtHere are the objects in the trace list:
SKB1
USR05
TRDIR
SKA1
SKAT
SKB1
BSIS
PRPS
BSAS
V_LTDX
USR02
RFBLG
V_LTDX
LTDX
RTXTH
RTXTF
RTXTT
TRDIR
The most of this call to this tables returns 1-2 records, apart from BSIS, where it returns 10 records. This is the same as accounting documents in the transaction FBL3N. When i try this again with more records returned I still have no call to table GLT0. -
Comparing sum from two tables and correct by difference of sum in second t,
Hello Guys,
I have a very tricky task that I cant get my head around.
The sample data looks like that:
Master Table
Claim------Booking--------Debit--------Credit------------MasterAmout
1------------1----------------D---------------------------------15.3
1------------2----------------D---------------------------------480.6
1------------3------------------------------C-------------------496.8
------------------------------------------- 0.9
Slave Table
Claim-----Booking-----Debit------------Credit----------SlaveAmout------- SlaveCorrection
1------------1------------D------------------------------------15.3---------------14.5
1------------2------------D------------------------------------480.6-------------480.6
1------------3-----------------------------C-------------------496---------------496
-------------------------------------------0.1--------------------------------------0.9
The booking have a total amout of 0.1 but has to be corrected to 0.9 because the master table has 0.9.
Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we have
to change the amount from 15.3 to 14.5. I plan my SQL like that:
1. Sum bookings from both tables for each Claim. Compare the two for each individual claim.
2. If the Master sum of the amount shows a difference between the master and slave table
2.1 select top 1 booking from slave table for the specific claim and increase/decrease by the difference of those two amounts.
Does that make sense?Hello
It would be really helpful if you could a) format your posting properly using the {noformat}{noformat} tags around your data and b) provide create table/ insert statements.
Anyway, from what you described -
Booking 1 requires a correction so the slave table also has a total of 0.9 (business rule is, corrections only on first booking). so we haveto change the amount from 15.3 to 14.5
You could achieve this with an analytic function and an outer join...WITH Master_Table AS
SELECT 1 Claim, 1 booking, 'D' debit,NULL credit,15.3 masteramount from dual union all
SELECT 1,2,'D',NUll,480.6 from dual union all
SELECT 1,3,NULL,'C',496.8 from dual
Slave_Table AS
( SELECT 1 claim, 1 booking, 'D' debit, null credit, 15.3 slaveamount,14.5 slavecorrection from dual union all
SELECT 1,2,'D',NULL,480.6,480.6 from dual union all
SELECT 1,3,null,'C',496,496 from dual
SELECT
m.claim,
m.booking,
m.debit,
m.credit,
NVL(s.slavecorrection,m.masteramount) amount
FROM
master_table m
LEFT OUTER JOIN
( SELECT
claim,
booking,
slaveamount,
slavecorrection,
ROW_NUMBER() OVER(PARTITION BY claim ORDER BY booking) rn
FROM
slave_table s
) s
ON
( s.claim = m.claim
AND
m.booking = s.booking
AND
s.rn = 1
CLAIM BOOKING D C AMOUNT
1 1 D 14.5
1 2 D 480.6
1 3 C 496.8
HTH
David
Maybe you are looking for
-
I cann't execute javac with parameters. please help !!
Hi All!! I can't understand how to execute application or bat file (javac.exe for example) WITH parameters correctly. I can execute javac.exe or bat file - WITHOUT parameters : Process p = Runtime.getRuntime().exec(WIN_PATH + " " + WIN_FLAG + " " + "
-
Final Cut Pro to Compressor - the Void In Between
So, basically, I am in love with FC Studio. However, one detail that has been absolutely frustrating has been the meltdowns experienced with exporting video directly from FCP 6 to Compressor 3. My office has multiple machines used for editing, and we
-
Apple mobile device fail to start system services
When downloading new verson of itunes, I keep getting the message that apple mobile device - failed system start? I have no idea what this means are where to verify what I am supposed to verify.
-
I just noticed that after running an image through dnoise, Aperture looses almost all the metadata. Should this be happening? Is there a way to stop it?
-
How to Download and Use HP iPrint for Android, iPhone, and iPod Touch
Greetings iPrint users! The following documents contain instructions for downloading the iPrint Application and use the app to print photos. Included on each page are step-by-step instructions with screen shots, as well as a video walkthrough. iPhone