473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I want formatted output

4 New Member
HI Everybody,

I have created one table called Employee.this table cantains four columns
ID,NAME,DEPTARTMENT,SALARY.

Now i want out put in below mentioned format.

Emp.ID Emp.Name Dept. Salary Total Salary by Dept
1 X1 Software 5000
2 X2 Software 7000
12000
3 X3 Testing 8000
4 X4 Testing 4000
5 X5 Testing 3000
15000
6 X6 HR 2000
7 X7 HR 1000
3000
Can anyone please help to get output in this format?

Thanks in advance.
amit
Jan 8 '08 #1
3 1361
amitpatel66
2,367 Recognized Expert Top Contributor
HI Everybody,

I have created one table called Employee.this table cantains four columns
ID,NAME,DEPTARTMENT,SALARY.

Now i want out put in below mentioned format.

Emp.ID Emp.Name Dept. Salary Total Salary by Dept
1 X1 Software 5000
2 X2 Software 7000
12000
3 X3 Testing 8000
4 X4 Testing 4000
5 X5 Testing 3000
15000
6 X6 HR 2000
7 X7 HR 1000
3000
Can anyone please help to get output in this format?

Thanks in advance.
amit
Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> ed
  3. Wrote file afiedt.buf
  4.  
  5.   1  select t.id,SUM(salary) from
  6.   2  (select 1 AS ID, 'X1' AS NAME, 'SW' AS DEPT, 1000 AS SALARY from dual
  7.   3  UNION
  8.   4  select 2 AS ID, 'X2' AS NAME, 'SW' AS DEPT, 1000 AS SALARY from dual
  9.   5  UNION
  10.   6  select 3 AS ID, 'X3' AS NAME, 'S' AS DEPT, 1000 AS SALARY from dual
  11.   7  UNION
  12.   8  select 4 AS ID, 'X4' AS NAME, 'S' AS DEPT, 3000 AS SALARY from dual) t
  13.   9* GROUP BY ROLLUP(dept,t.id)
  14. SQL> /
  15.  
  16.         ID SUM(SALARY)
  17. ---------- -----------
  18.          3        1000
  19.          4        3000
  20.                   4000
  21.          1        1000
  22.          2        1000
  23.                   2000
  24.                   6000
  25.  
  26. 7 rows selected.
  27.  
  28. SQL> 
  29.  
  30.  
Jan 8 '08 #2
Amit Parmar
4 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> ed
  3. Wrote file afiedt.buf
  4.  
  5.   1  select t.id,SUM(salary) from
  6.   2  (select 1 AS ID, 'X1' AS NAME, 'SW' AS DEPT, 1000 AS SALARY from dual
  7.   3  UNION
  8.   4  select 2 AS ID, 'X2' AS NAME, 'SW' AS DEPT, 1000 AS SALARY from dual
  9.   5  UNION
  10.   6  select 3 AS ID, 'X3' AS NAME, 'S' AS DEPT, 1000 AS SALARY from dual
  11.   7  UNION
  12.   8  select 4 AS ID, 'X4' AS NAME, 'S' AS DEPT, 3000 AS SALARY from dual) t
  13.   9* GROUP BY ROLLUP(dept,t.id)
  14. SQL> /
  15.  
  16.         ID SUM(SALARY)
  17. ---------- -----------
  18.          3        1000
  19.          4        3000
  20.                   4000
  21.          1        1000
  22.          2        1000
  23.                   2000
  24.                   6000
  25.  
  26. 7 rows selected.
  27.  
  28. SQL> 
  29.  
  30.  
Thanks for your reply,
but, i already got output in this format.
What i want is,"tolal salary by department" should be displayed in separate column. That i have mentioned below.

ID SUM(SALARY) Total Salary by Dept.
---------- ----------- ----------------------------
3 1000
4 3000
------------------------------------4000
1 1000
2 1000
------------------------------------2000
------------------------------------6000

Thanks in advance,
Amit Parmar
Jan 9 '08 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Try this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1  select empid,dept,salary ss,NULL from data1
  5.   2  UNION ALL
  6.   3  SELECT NULL,dept,NULL, sum(salary) from data1 group by dept
  7.   4  UNION ALL
  8.   5  SELECT NULL,NULL,NULL,SUM(SALARY) FROM data1
  9.   6* order by dept
  10. SQL> /
  11.  
  12.      EMPID DEPT                         SS       NULL
  13. ---------- -------------------- ---------- ----------
  14.          1 SW                        10000
  15.          2 SW                         1000
  16.          5 SW                          100
  17.            SW                                   11100
  18.          3 WWS                       10000
  19.          4 WWS                        1000
  20.            WWS                                  11000
  21.                                                 22100
  22.  
  23. 8 rows selected.
  24.  
  25. SQL> 
  26.  
Jan 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
2098
by: Craig Thomson | last post by:
Do people generally try and output nicely formatted html from their scripts? I have been trying to, with variable indenting for tables etc. It makes it easier to see the html and perhaps debug...
2
1766
by: Mark | last post by:
How do I output formatted numerical data to an external (text) file. At a minimum I want to specify the number of decimal places to print. Ideally I'd like the type of control the fortran FORMAT...
8
5202
by: Matthew Thorley | last post by:
Greetings, perhaps someone can explain this. I get to different styles of formatting for xmla and xmlb when I do the following: from elementtree import ElementTree as et xmla =...
4
3554
by: Joe C | last post by:
I've written a console application and would like to isolate all screen output so that it will be easier to migrate the code to a GUI-type platform without modification to the base code. As a...
6
2186
by: Jason Heyes | last post by:
I am starting to worry about the performance of formatted read/write operations on data-redundant objects in my program.What can I do to improve this performance should it become an issue? ...
3
3354
by: Craig Petrie | last post by:
Hi, I have a large table in Word 2003 that has formatted text in the cells and wish to read and convert a cells formatted contents to html output via vb.net code. The formatting contains the...
2
2032
by: rufi | last post by:
hi group, I am new to C and using gcc compiler in Linux. I am having the following problems when using the printf() funtion to have the formatted output. Here r some things which i m trying...
6
3667
by: Jojo | last post by:
Hi all, I was wondering how I can perform formatted output with C++ strings. For example, suppose I have in plain C: sprintf(C_string, "%5.2f %6d"); How can I do such a thing with C++...
4
4640
by: keith | last post by:
I've been beating my head against this for a little while, so perhaps someone can help me out here? The code below should output exactly as follows (the hex data lines up in a fixed font): DATA...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.