Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Wednesday, March 7, 2012

How Can I Write this SQL Query ?

Hi

I have 2 tables and I want to Get information from that tables by SQL Query but How Can I writ this SQL Query ? .. My target as Follow

Class Table

---------------

ClassID ClassName

1 AA

2 BB

Student Table

---------------

StudentID StudentName ClassID

1 Student 1 1

2 Student 2 1

3 Student 3 2

4 Student 4 1

5 Student 5 2

6 Student 6 1

How Can I Writ SQL Query to get result like the following ..

----------------

ClassID ClassName StudentCount

1 AA 4

2 BB 2

My SQL Query must get all Class table column plus column content the count of student in each class

And thanks with my regarding

Fraas

The simplest way to accomplish this would be a query like this:
SELECT
Class.ClassID,
Class.ClassName,
Count(Student.StudentID) AS StudentCount
FROM
Class
LEFT OUTER JOIN
Student ON Class.ClassID = Student.ClassID
GROUP BY
Class.ClassID,
Class.ClassName
ORDER BY
Class.ClassID

This will return one row for each class, with the number of students ineach class. If no students are found for the class 0 will appearin the StudentCount column.

|||In a related question, how would someone run a similar query thatwouldn't count the number of students but rather concatenate the names,preferably with separators?
|||

Thanks For Your Answer .. it's work niceSmile [:)]

Sunday, February 19, 2012

How can I troubleshoot eratic, slow SQL Backup job?

I have a SQL 2000 sp3 server running on a server class machine with
local drives.
I'm backing up a 50 gig db from the e partition to the F: partition.
Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
There are no jobs running when the backups execute, no index rebuilds,
no veritas, no virus scans running.
I'll run a backup and it will take 20 minutes. I rerun it again
right away and it takes 2.5 hours.
I run a statistics IO trace, and the only difference is the cumulative
wait time...which is much much higher when the backup takes 2.5 hours.
Any suggestions on how to troubleshoot this? Or why it might be
happening?On Apr 16, 5:51 pm, "Sanctus" <mch...@.hotmail.com> wrote:
> I have a SQL 2000 sp3 server running on a server class machine with
> local drives.
> I'm backing up a 50 gig db from the e partition to the F: partition.
> Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
> There are no jobs running when the backups execute, no index rebuilds,
> no veritas, no virus scans running.
> I'll run a backup and it will take 20 minutes. I rerun it again
> right away and it takes 2.5 hours.
> I run a statistics IO trace, and the only difference is the cumulative
> wait time...which is much much higher when the backup takes 2.5 hours.
> Any suggestions on how to troubleshoot this? Or why it might be
> happening?
Here are some ideas...
E: to F: - are these different drives on a san and does the backup
have to go accross the network - higher network traffic at times?
Network saturation?
Are their heavier user processes at times? Heavy duty queries/long
running transactions?
Is this a dedicated SQL Server, could another application be hogging
the Memory or IO?
As you can see, I am just shooting blind. Maybe some of these ideas
can help you think how to investigate?

How can I troubleshoot eratic, slow SQL Backup job?

I have a SQL 2000 sp3 server running on a server class machine with
local drives.
I'm backing up a 50 gig db from the e partition to the F: partition.
Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
There are no jobs running when the backups execute, no index rebuilds,
no veritas, no virus scans running.
I'll run a backup and it will take 20 minutes. I rerun it again
right away and it takes 2.5 hours.
I run a statistics IO trace, and the only difference is the cumulative
wait time...which is much much higher when the backup takes 2.5 hours.
Any suggestions on how to troubleshoot this? Or why it might be
happening?On Apr 16, 5:51 pm, "Sanctus" <mch...@.hotmail.com> wrote:
> I have a SQL 2000 sp3 server running on a server class machine with
> local drives.
> I'm backing up a 50 gig db from the e partition to the F: partition.
> Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
> There are no jobs running when the backups execute, no index rebuilds,
> no veritas, no virus scans running.
> I'll run a backup and it will take 20 minutes. I rerun it again
> right away and it takes 2.5 hours.
> I run a statistics IO trace, and the only difference is the cumulative
> wait time...which is much much higher when the backup takes 2.5 hours.
> Any suggestions on how to troubleshoot this? Or why it might be
> happening?
Here are some ideas...
E: to F: - are these different drives on a san and does the backup
have to go accross the network - higher network traffic at times?
Network saturation?
Are their heavier user processes at times? Heavy duty queries/long
running transactions?
Is this a dedicated SQL Server, could another application be hogging
the Memory or IO?
As you can see, I am just shooting blind. Maybe some of these ideas
can help you think how to investigate?

How can I troubleshoot eratic, slow SQL Backup job?

I have a SQL 2000 sp3 server running on a server class machine with
local drives.
I'm backing up a 50 gig db from the e partition to the F: partition.
Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
There are no jobs running when the backups execute, no index rebuilds,
no veritas, no virus scans running.
I'll run a backup and it will take 20 minutes. I rerun it again
right away and it takes 2.5 hours.
I run a statistics IO trace, and the only difference is the cumulative
wait time...which is much much higher when the backup takes 2.5 hours.
Any suggestions on how to troubleshoot this? Or why it might be
happening?
On Apr 16, 5:51 pm, "Sanctus" <mch...@.hotmail.com> wrote:
> I have a SQL 2000 sp3 server running on a server class machine with
> local drives.
> I'm backing up a 50 gig db from the e partition to the F: partition.
> Sometimes the backup takes 20 minutes...sometimes it takes 2.5 hours.
> There are no jobs running when the backups execute, no index rebuilds,
> no veritas, no virus scans running.
> I'll run a backup and it will take 20 minutes. I rerun it again
> right away and it takes 2.5 hours.
> I run a statistics IO trace, and the only difference is the cumulative
> wait time...which is much much higher when the backup takes 2.5 hours.
> Any suggestions on how to troubleshoot this? Or why it might be
> happening?
Here are some ideas...
E: to F: - are these different drives on a san and does the backup
have to go accross the network - higher network traffic at times?
Network saturation?
Are their heavier user processes at times? Heavy duty queries/long
running transactions?
Is this a dedicated SQL Server, could another application be hogging
the Memory or IO?
As you can see, I am just shooting blind. Maybe some of these ideas
can help you think how to investigate?