473,659 Members | 2,965 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,DEPTART MENT,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 1374
amitpatel66
2,367 Recognized Expert Top Contributor
HI Everybody,

I have created one table called Employee.this table cantains four columns
ID,NAME,DEPTART MENT,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
2113
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 it, but it can make ugly looking scripts. What's the general consensus? Craig
2
1779
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 statement offers. I'm sure this is easy, but I can't seem to find the answer! I want an output file to look like this: 0.1 0.8575 0.2 12.0900 0.4 345.0000
8
5213
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 = et.ElementTree('some_file.xml') xmlb = et.Element('parent') et.SubElement(xmlb, 'child1') et.SubElement(xmlb, 'child2')
4
3564
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 first step, I've created a variable: bool useConsole(true); then I trap all output like: if(useConsole){ cout << text; }
6
2193
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? Thanks.
3
3362
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 following: bold text, italic text, superscript & subscript text, bullet points. The output html is then saved in an XML file as a CDATA section for later use in the application when formatted output is required. I have looked up many sites on the...
2
2043
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 : The range of short int(which is signed by default) is -32768 to + 32767.
6
3680
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++ strings? Using a string stream and the << operator does not give me the formatting control like sprintf. Or did I miss something.... :-|
4
4653
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 0123456789abcdef0123456789abcdef 0123456789abcdef0123456789abcdef and the code does indeed do that when I use the fprintf() call. When I comment that line out and use the iostream line, I get gibberish. I guess I'm just not 'getting' C++...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6179
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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 we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.