Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sjefsgjogleren
Starting Member
2 Posts |
Posted - 2012-02-09 : 08:43:26
|
| Hello!I'm working on a master thesis, that requires some simple SQL programming. The problem is, that my skills in SQL programming is close to none existing. I'm really hoping that you guys can help me out on this one!:)Problem:I'm working on a relativley big database and need to extract some data. I'm having several tables, and need to use several tags in order to extract the needed data. In the first table, lets call it Alarm, I'm specifiying a certain AlarmId, such that all alarms with this Id connectet to it appears. This is done with the standard:Select*from table_name where AlarmId='xxx' statment (that even I can produce!:)The thing is that relatet to all alarms there is a StopId. You can then check out that certain stopid in a different table, lets call it Stop, in order to see if any other warnings occured together with the logged alarm. My question is then, can anyone help me with creating a statment that makes me specify the AlarmId, and then automatically counts up which other warnings that occured together with the logged alarm on all the different StopId relatet to the specified AlarmId?:) |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-09 : 12:46:11
|
this maybe?Select t.AlarmId,COUNT(s.StopId) AS StopCntfrom table_name tinner join othertable son s.AlarmId = t.AlarmIdwhere t.AlarmId='xxx' group by t.AlarmId ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Sjefsgjogleren
Starting Member
2 Posts |
Posted - 2012-02-09 : 17:33:59
|
| Thanks.Unfortunatley didn't quite give the answer I was hoping for. This querry was summing up the total number of times that AlarmId='xxx' was found within the 'othertable'. The thing is that the AlarmId needs to be connectet to table_name (first table) since it also can be found within the othertable, but then not as the alarm 'trigger'. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-09 : 17:46:32
|
| It's tough to tell how your data relates from your description. Can you please post DDL, DML and Expected output in a consumable format?Here are two link that can help you compile that information so we can help you better:http://www.sqlservercentral.com/articles/Best+Practices/61537/http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-09 : 17:49:07
|
quote: Originally posted by Sjefsgjogleren Thanks.Unfortunatley didn't quite give the answer I was hoping for. This querry was summing up the total number of times that AlarmId='xxx' was found within the 'othertable'. The thing is that the AlarmId needs to be connectet to table_name (first table) since it also can be found within the othertable, but then not as the alarm 'trigger'.
sorry didnt get thatcan you give an example with sample data and required output?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|