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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Help.

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2009-08-25 : 16:14:29
Hi there. I am a rookie to SQL and have a problem with the query
The table is like

SystemName BP_Type ID
AA\BB\CC KDKD 10000
AA\BB\CC IEIE 201
AA\BB\DD IAEJ 1020
...

Now I want to check under each SystemName, for each different BP_Types, how many entries are there.
so the result will be like
SystemName BP_Type Sum
AA\BB\CC KDKD 2
AA\BB\CC IEIE 1
AA\BB\DD IAEJ 101


Anyone could help.

Thanks.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-25 : 16:42:02
Does you sample data and expected output match??

maybe u need this?

select systemname,bp_type,count(*) from @t group by systemname,bp_type
Go to Top of Page

mavershang
Posting Yak Master

111 Posts

Posted - 2009-08-25 : 18:29:28
Thanks for your post. But your query only gives the number of entries grouped by SystemName. That is partly what I need. But I need divide further by different bp_type within each SystemName.



quote:
Originally posted by vijayisonly

Does you sample data and expected output match??

maybe u need this?

select systemname,bp_type,count(*) from @t group by systemname,bp_type


Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-25 : 18:48:33
Huh?
vijayisonly's query is grouping by systemname,bp_type
That should do exactly what you want or what I am missing?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

VLADIM
Starting Member

1 Post

Posted - 2009-08-26 : 07:22:29
I am work with Visual Studio 2005 + C# + XQUery.

Below is part FILE.xml

<xs:element nam_="ScheduleSteps"
......
</xs:element>
<xs:element nam_="aliasName"
......
</xs:element>
<xs:element nam_="localName"
......
</xs:element>
<xs:element nam_="mRID"
......
</xs:element>

Part from the programs on C#
.......
string s_qu =
"<NSet> { " +
" for $aa in document(\"FILE.xml\")//@*[1] " +
" return <Tb> { ($aa) } </Tb> " +
// (: ?? " return <Tb> { data($aa) } </Tb> " +
" </NSet> ";
.......

1. With operator { ($aa) } i get

nam_="ScheduleSteps"
nam_="aliasName"
nam_="localName"
nam_="mRID"
And it is true.

2. But with operator { data($aa) } i get error < ')'expected >
Function data() is no right ?
Help my please if possibal. Vladim.
Go to Top of Page
   

- Advertisement -