Friday, March 9, 2012

multiple counts in a sql statement

How would I create a sql statement with 3 or 4 counts which would represent 3 or 4 different columns in a datagrid?

For example

SQL = "SELECT Count(department_id) as "totals1" FROM nonconformance WHERE department_id = '1'"

How would I make additional counts in this SQL statement that looks for when department_id=2 and 3 etc...

Thanksrefer to your other message, and www.sqlcourse.com|||Got another question related to this. Since I have this part

SQL = "SELECT Totals = (SELECT Count(*) FROM nonconformance WHERE department_id=7), Totals2 = (SELECT Count(*) FROM nonconformance WHERE department_id=1)"

How would I add another statement in here to Sum a different column in the database.

For example

Select Totals = (Select Sum(nc_wafer_wty) FROM nonconformance WHERE department_id = 7) etc...

What I am trying to do is create a two row datagrid with the different "totals" as columns.

Is this possible?|||wouldn't a group by statement be better than actually having where clauses with id's coded into them?|||Yes i realize that. This is just for testing right now, later I will put variables in there place.|||you aren't paying attention. Variables or not.. if you're BINDING the resultset to a control, you're best off retrieving the data correctly.|||You mean GROUP BY department_id?|||yes. That way you won't have to make an extremely long sql statement, and loop to get specific ones.

No comments:

Post a Comment