Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Three into 1 ! (",)

Status
Not open for further replies.

team4344

Technical User
Jun 28, 2003
25
GB
I have 3 SQL statements.

Does anyone know how i can create simply one statement from these three.

Ideally i would like the statement to return in 3 columns

SELECT Count(Criticality) AS High_Impact
FROM Business
WHERE (((Business.Criticality)="HighImpact"));

SELECT Count(Criticality) AS Medium_Impact
FROM Business
WHERE (((Business.Criticality)="MediumImpact"));

SELECT Count(Criticality) AS Low_Impact
FROM Business
WHERE (((Business.Criticality)="low Impact"));

Many thanks for everyones help.

Olly :)

 
Code:
SELECT
  SUM(CASE WHEN criticality = 'highimpact' THEN 1 ELSE 0 END) AS high_impact,
  SUM(CASE WHEN criticality = 'mediumimpact' THEN 1 ELSE 0 END) AS medium_impact,
  SUM(CASE WHEN criticality = 'lowimpact' THEN 1 ELSE 0 END) AS low_impact
FROM business

--James
 
[tt]SELECT criticality, COUNT(criticality) GROUP BY criticality[/tt]

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top