﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / select query / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 14:14:29 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>[quote][b]alex_pangcats (7/1/2009)[/b][hr]Hi everyone,I need your help to solve my problem, a simple yet little bit complicated query condition.Here's the scenario.There's a table (Teacher_Student) that contains id (refer to teacher_student id), teacher_name &amp; student name. Note this table is not normalized.ex. Teacher1 have student1,student2,student3 &amp; student4.....ex. Teacher2 have student1,student2,student3 &amp; student4.....this table contains records between teacher &amp; student relationship.Another table (Teacher_Student_Classes) that contains dayId,teacher_name,student_name,date &amp; classes(subject).ex. Teacher1 handle many classes(subjects)ex. Every class  have many students.Now i want to create a query that shows how many number of students attended the class of teacher1 from one month.ex. teacher1 have a total 0f 20 students.     teacher2 have a total of 50 studens.example results:              Jan-1   Jan-2    Jan-3 .........teacher1  20         19         15teacher2 50          45         30The results something like a calendar type.thanks in advance. hope that my messages help you to understand my problem.[/quote]Alex,You're a brand new poster on this forum and you may not be aware of a couple of problems with your post.  Hopefully, this will clarify why people are asking you for more detail in the manner that they're asking.This problem isn't a difficult one but, like the others, I'm not clear on things like the following...[quote]Note this table is not normalized.ex. Teacher1 have student1,student2,student3 &amp; student4.....ex. Teacher2 have student1,student2,student3 &amp; student4.....[/quote]Since you said that "this table is not normalized", we can envision many ways that the data could be constructed in the table including a CSV column much like you posted above.  Rather than wasting our time and your's trying to solve a problem that isn't clearly defined, folks have asked you for the CREATE TABLE statement for each of the two tables along with some examples of data in a readily consumable format.  It's also important that you accurately post what the final output should look like compared to the sample data.The data being in readily consumable format is very important because most of us like to test our solutions for folks like you before we post them but we don't have a lot of time to create data or reformat data you've provided (remember that all of us do this for free and out of the goodness of our hearts).  Further, both the CREATE TABLE and the readily consumable data provide absolute clarity about the problem... it lets us know what all the datatypes are and provides a very good example of your environment.With that and the fact that we're actually interested in helping you solve your problem, please take a look at the article at the first link in my signature below.  If you were to post the table creation statements and data in the readily consumable format outlined in that article, you'd be amazed at how fast someone will come up with an answer for you.</description><pubDate>Fri, 03 Jul 2009 10:39:33 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>[quote][b]Eswin (7/2/2009)[/b][hr]No Florian its just that i couldn't solves alex's problem so i thought i will make it mine............since i didn't see many people viewing this post........[/quote]All Alex needs to do is post the information Gail requested and he'll get the help he is looking for Eswin.</description><pubDate>Thu, 02 Jul 2009 23:19:41 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>No Florian its just that i couldn't solves alex's problem so i thought i will make it mine............since i didn't see many people viewing this post........</description><pubDate>Thu, 02 Jul 2009 20:33:37 GMT</pubDate><dc:creator>Eswin</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>Seems like Eswin and alex_pangcats are in same class:[url]http://www.sqlservercentral.com/Forums/Topic746129-338-1.aspx[/url]</description><pubDate>Thu, 02 Jul 2009 12:03:32 GMT</pubDate><dc:creator>Florian Reischl</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.[url]http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]</description><pubDate>Thu, 02 Jul 2009 11:55:13 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>[quote][b]alex_pangcats (7/1/2009)[/b][hr]Hi everyone,Another table (Teacher_Student_Classes) that contains dayId,teacher_name,student_name,date &amp; classes(subject).ex. Teacher1 handle many classes(subjects)ex. Every class  have many students.Now i want to create a query that shows how many number of students attended the class of teacher1 from one month.ex. teacher1 have a total 0f 20 students.     teacher2 have a total of 50 studens.example results:              Jan-1   Jan-2    Jan-3 .........teacher1  20         19         15teacher2 50          45         30The results something like a calendar type.thanks in advance. hope that my messages help you to understand my problem.[/quote] SELECT Date,       (select count(student_name) from Teacher_Student_Classes where teacher_name=t1 and date = 'jan') AS [t1],       (select count(student_name) from Teacher_Student_Classes where teacher_name=t2 and date = 'Feb') AS [t2],       (select count(student_name) from Teacher_Student_Classes where teacher_name=t3 and date = 'Mar') AS [t3]   FROM Teacher_Student_Classes  GROUP BY Date</description><pubDate>Wed, 01 Jul 2009 23:35:48 GMT</pubDate><dc:creator>Eswin</dc:creator></item><item><title>RE: select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>check out:[url=http://www.angelosp.com/blog/post/T-SQL---Turning-rows-into-columns.aspx]http://www.angelosp.com/blog/post/T-SQL---Turning-rows-into-columns.aspx[/url]</description><pubDate>Wed, 01 Jul 2009 23:04:32 GMT</pubDate><dc:creator>Eswin</dc:creator></item><item><title>select query</title><link>http://www.sqlservercentral.com/Forums/Topic745947-338-1.aspx</link><description>Hi everyone,I need your help to solve my problem, a simple yet little bit complicated query condition.Here's the scenario.There's a table (Teacher_Student) that contains id (refer to teacher_student id), teacher_name &amp; student name. Note this table is not normalized.ex. Teacher1 have student1,student2,student3 &amp; student4.....ex. Teacher2 have student1,student2,student3 &amp; student4.....this table contains records between teacher &amp; student relationship.Another table (Teacher_Student_Classes) that contains dayId,teacher_name,student_name,date &amp; classes(subject).ex. Teacher1 handle many classes(subjects)ex. Every class  have many students.Now i want to create a query that shows how many number of students attended the class of teacher1 from one month.ex. teacher1 have a total 0f 20 students.     teacher2 have a total of 50 studens.example results:              Jan-1   Jan-2    Jan-3 .........teacher1  20         19         15teacher2 50          45         30The results something like a calendar type.thanks in advance. hope that my messages help you to understand my problem.</description><pubDate>Wed, 01 Jul 2009 21:31:04 GMT</pubDate><dc:creator>alex_pangcats</dc:creator></item></channel></rss>