| Author |
Topic |
|
junes
Starting Member
12 Posts |
Posted - 2008-10-23 : 05:51:29
|
| All, Please can you help. I am new to SQL and i want to create a table as shown below,Servers by OS TotalAIX 50Solaris 20Linux 30Windows 10OpenVMS 7VmWare 6Total 123Here is my SQL code and i only getting the following ouput.select count(hs.hostname) as HOSTSfrom mvc_hostsummaryvw hswhere hs.os='AIX'UNION allselect count(hs.hostname) as HOSTSfrom mvc_hostsummaryvw hswhere hs.os='Solaris'UNION allselect count(hs.hostname) as HOSTSfrom mvc_hostsummaryvw hswhere (hs.os='Windows(R) Server 2000' OR hs.os='Windows(R) Server 2003' OR hs.os='Windows(R) Server 2008')Output of the SQL script-----------------------Hosts583436How can i create two columns (Servers by OS & Total) and a row at the end which displays a grand total.Any help will be greatly appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 06:02:39
|
| can you give some sample data too as we dont know what all field your table has and which of them contain required data. |
 |
|
|
junes
Starting Member
12 Posts |
Posted - 2008-10-23 : 06:16:55
|
| Is this what you are looking for:Column Name Data Type Type_NameHOSTID 3 NUMBERHOSTNAME 12 VARCHAR2DOMAINID 3 NUMBERVENDOR 12 VARCHAR2DESCRIPTION 12 VARCHAR2STATUS 3 NUMBERIP 12 VARCHAR2DNS 12 VARCHAR2MODEL 12 VARCHAR2VERSION 12 VARCHAR2OS 12 VARCHAR2MODEL_TYPE 3 NUMBERISCLUSTER 3 NUMBERTOTALPHYSICALMEM 3 NUMBERNUMBERPROCESSOR 3 NUMBERSUPPORTFLAG 3 NUMBERBASETABLENAME 1 CHAROutput of the table SAMPLE 1----------------------------122162 EMALONFNP01 1000 HP AT/AT COMPATIBLE 4 165.47.61.195 EMALONFNP01.emea.bankofamerica.com ProLiant DL380 G4 5.2.3790 Windows(R) Server 2003 1 (null) 3669476 4 7 HOST 151085 lonecnsddb01 1000 SUN FJSV,GPUZC-M 4 165.47.191.78 lonecnsddb01.emea.bankofamerica.com sun4us Generic_118833-36.5.10 Solaris 1 (null) 8388608 2 7 HOST Output of the table SAMPLE 2---------------------------- 151085 lonecnsddb01 1000 SUN FJSV,GPUZC-M 4 165.47.191.78 lonecnsddb01.emea.bankofamerica.com sun4us Generic_118833-36.5.10 Solaris 1 (null) 8388608 2 7 HOST |
 |
|
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2008-10-23 : 06:18:30
|
| select hs.os, count(*) frommvc_hostsummaryvw hsGroup by hs.osUnion allSelect 'Total', count(*)from mvc_hostsummaryvw |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 06:19:55
|
seems like what you want isSELECT os,count(*) as TotalFROM mvc_hostsummaryvw GROUP BY os |
 |
|
|
junes
Starting Member
12 Posts |
Posted - 2008-10-23 : 07:11:14
|
| Many thanks for this, I can't believe the syntax was so simple, compare to what i was writing.I changed the code slighlty as follows:select hs.os, count(*) as OS_NUMBERfrom mvc_hostsummaryvw hswhere hs.os is not nullGROUP BY hs.osUnion allSelect 'Total', count(*)from mvc_hostsummaryvw hsswhere hss.os is not null;I have two more question please.How can i sort the ouput to have AIX on top of the list, so the data in ASC order. I have attempted to change the code but with no luck. Also how can i change the title from "OS" to "SAN Connected Servers by OS". Thanks alot.OS OS_NUMBER---------------HP-UX 1Windows(R) Server 2003 36Solaris 34AIX 58Total 129 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 07:13:14
|
| [code]select os,OS_NUMBER FROM(select hs.os, count(*) as OS_NUMBER,0 AS Catfrom mvc_hostsummaryvw hswhere hs.os is not nullGROUP BY hs.osUnion allSelect 'Total', count(*),1from mvc_hostsummaryvw hsswhere hss.os is not null;)tORDER BY Cat,os[/code] |
 |
|
|
junes
Starting Member
12 Posts |
Posted - 2008-10-23 : 07:34:41
|
| Visakh16,How can i change the Coulmn name from "OS" to "SAN Connected Servers by OS".OS OS_NUMBER---------------SAN Connected Servers by OS OS_NUMBER----------------------------------------Thanks Alot. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 07:45:39
|
quote: Originally posted by junes Visakh16,How can i change the Coulmn name from "OS" to "SAN Connected Servers by OS".OS OS_NUMBER---------------SAN Connected Servers by OS OS_NUMBER----------------------------------------Thanks Alot.
use ASselect os AS [SAN Connected Servers by OS],OS_NUMBER FROM(select hs.os, count(*) as OS_NUMBER,0 AS Catfrom mvc_hostsummaryvw hswhere hs.os is not nullGROUP BY hs.osUnion allSelect 'Total', count(*),1from mvc_hostsummaryvw hsswhere hss.os is not null;)tORDER BY Cat,os |
 |
|
|
|