×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

why can't I do this?

why can't I do this?

why can't I do this?

(OP)
Why is this illegal and how can I fix it? Thanks.

SELECT COUNT(*) AS NumberOfHistory
FROM Enrolls
WHERE COURSENUM = 405;

SELECT COUNT(*) AS NumberOfScience
FROM Enrolls
WHERE COURSENUM = 605;
 

RE: why can't I do this?

Possibly because you are counting everything ie (*)

Try counting your table key (whatever its name is)
eg

SELECT COUNT(table_key) AS NumberOfHistory
FROM Enrolls
WHERE COURSENUM = 405;

Or are you wanting two columns then

select sum( case when coursenum = 605 then 1 else 0 end ) as NumOfSci,
sum( case when coursenum = 405 then 1 else 0 end ) as NumOfHist
FROM Enrolls

Ian
 

RE: why can't I do this?

Or are you trying to get 2 rows, in which case use a union

CODE

SELECT "History" AS Course, COUNT(*) AS Number
FROM Enrolls
WHERE COURSENUM = 405
UNION
SELECT "Science" AS Cource COUNT(*) AS Number
FROM Enrolls
WHERE COURSENUM = 605;

Or more efficiently:

CODE

SELECT COURSENUM, COUNT(*)
FROM Enrolls
WHERE COURSENUM IN (405,605)
GROUP BY COURSENUM

Without knowing a little more about what you want, what error you're getting and what system you're running, it's difficult to provide you with the exact answer you need!

hth

Ben

----------------------------------------------
Ben O'Hara www.RobotParade.co.uk

Quote (David W. Fenton):

We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
  

RE: why can't I do this?


Quote:

Why is this illegal and how can I fix it?

it isn't, and you don't have to



smile

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

RE: why can't I do this?

Quote:


Why is this illegal and how can I fix it?

I agree with r937. If it's "illegal", there must be an error message you can post?

Ever notice how fast Windows runs? Me neither.
 

RE: why can't I do this?

plz try this..

SELECT COURSENUM,COUNT(*) AS NumberOfScience
FROM Enrolls
WHERE COURSENUM = 605;
  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close