Re: simple query to view matching record and count

From: jefftyzzer <jefftyzzer_at_sbcglobal.net>
Date: Wed, 3 Mar 2010 11:40:55 -0800 (PST)
Message-ID: <b7e6d5d1-cb9c-4807-a970-577ff3ef59b2_at_v20g2000yqv.googlegroups.com>



On Mar 2, 5:23 pm, cricketu..._at_yahoo.com wrote:
> I have the following table
>
> Student:marks
> Steve:90
> Sam:85
> Sue:95
> Mark:75
> Steve:100
> Mark:81
> Sue:92
> Sue:94
>
> What query would provide me a list of all students with names
> beginning with S and the number of records they are present in?
>
> i.e
>
> Steve 2
> Sam 1
> Sue 3
>
> Thanks,
> C

Despite the prevailing opinion here, let's assume for a moment that you're not working on a homework assignment (anything this trivial [no offense] involving students [every professor's favorite entity] is viewed circumspectly); your query might look something like this:

SELECT

	S.STUDENT_NAME,
	COUNT(*) CNT
FROM
	STUDENT S
WHERE
	S.STUDENT_NAME LIKE 'S%'
GROUP BY
	S.STUDENT_NAME;

(Note that the above assumes all names are proper-cased.)

Regards,

--Jeff Received on Wed Mar 03 2010 - 13:40:55 CST

Original text of this message