473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Some help with SUM function

I've got basic SELECT access on an SQL database which contains a list of switches of these switches computers are connected, I want a way of finding all the spaces where computers arent and then totally the number of spare spaces. There is not a field which has spare spaces so I've wrote my own code for this, I'm just struggling with the total part, this is what I've got so far:

Expand|Select|Wrap|Line Numbers
  1. SELECT switch, COUNT(*) as "Servers", 20 - COUNT(*) as "Spare slots" 
  2. from dedicated_servers 
  3. where switch like 'rs%' 
  4. GROUP by switch HAVING COUNT(switch) < 20  
  5. order by Servers;switch like 'rs%' GROUP by switch 
  6. HAVING COUNT(switch)
which provides something like the following (it looks tidier on my screen :-( ):
Expand|Select|Wrap|Line Numbers
  1. +-------------+---------+-------------+
  2. | switch      | Servers | Spare slots |
  3. +-------------+---------+-------------+
  4. | rsj14-1.dc |      12 |           8 |
  5. | rsj12-1.dc |      15 |           5 |
  6. | rsi2-2.dc  |      16 |           4 |
  7. | rsj13-1.dc |      16 |           4 |
  8. | rsi2-1.dc  |      16 |           4 |
  9. +-------------+---------+-------------+
So yeah, somewhere I want a total of the spare slots column, which = 22 :-)

I only have SELECT access so creating a new column or something like that isn't really an option. i've found this hard mainly because my sum column isn't part of the DB... Thanks in advance for your help boys n' girls.
Oct 11 '07 #1
2 973
I mean total = 25, gosh that was stoopid...
Oct 11 '07 #2
Note... the code is also wrong, think I pasted too much or something, i'm new to these forum things, this is the correct code:

Expand|Select|Wrap|Line Numbers
  1. SELECT switch, COUNT(*) as "Servers", 20 - COUNT(*) as "Spare slots" 
  2. from dedicated_servers 
  3. where switch like 'rs%' 
  4. GROUP by switch 
  5. HAVING COUNT(switch) < 20  
  6. order by Servers;
I've just tested this and it works and gives the result I originally wrote of.
Oct 11 '07 #3

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

Similar topics

36
by: Antoon Pardon | last post by:
I'm rather new at this, so I don't know how I should introduce this, nor whether these ideas are worth much but here goes. What I would like to change is access to variables on an intermediate...
16
by: Michele Simionato | last post by:
I have read with interest the recent thread about closures. The funny thing is that the authors are arguing one against the other but I actually agree with all of them and I have a proposal that...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
7
by: Prashanth Badabagni | last post by:
#include<string.h> void (*foobar)(); void main() { char *str; strcpy(str,"Fun1"); strcat(str,"method1");
17
by: fctk | last post by:
some other doubts: 1) K&R, p50, 2.10: "if expr1 and expr2 are expressions, then expr1 op= expr2 is equivalent to expr1 = (expr1) op (expr2) except that expr1 is computed only once."
11
by: chsalvia | last post by:
I've been programming in C++ for a little over 2 years, and I still find myself wondering when I should use polymorphism. Some people claim that polymorphism is such an integral part of C++,...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
6
by: Max | last post by:
i have a event bind function like this(though it is not so robust): bind$=function(o,evt,fn,cb){ var aE='attachEvent'; var aEL='addEventListener'; if(!o&&o){ return o(evt,fn,!!cb); } return...
2
by: chromis | last post by:
Hi there, I've been reading an OOP book recently and it gives some nice Adaptor / Template patttern code to wrap around the php Mysql functions. I thought that I'd try and create a Simple Address...
3
by: bnashenas1984 | last post by:
Hi everyone I'v been programming a simple task and process manager which is working fine now but the problem is that my program does NOT work on some computers. I think it must have something to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...

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.