August 14, 2007 at 1:42 am
sorry im SQL beginner
ID_NRID_NR_pKZ
11v
12x
13v
21x
22x
23v
i want to count nr of KZ of which KZ='v'
i just can make a table like
ID_NR #(KZ=v)
1 2
2 1
any help?
August 14, 2007 at 1:48 am
Hi There,
Try this.
SELECT ID_NR,COUNT(*)
FROM
WHERE KZ='z'
GROUP BY ID_NR
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
August 14, 2007 at 1:51 am
thanxx
i can do that:-P
but what i want is the sum over all nr of id_nr which kz='V'
August 14, 2007 at 1:57 am
I'm confused.,
What should your result look like?
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
August 14, 2007 at 1:58 am
count(nr)
3
in this example
August 14, 2007 at 2:00 am
what about this:
SELECT COUNT(*)
FROM
WHERE KZ='z'
taht will give you a result of 3
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
August 14, 2007 at 2:06 am
yes.. but the point is it could be duplicated:
ID_NR ID_NR_p KZ
1 1 v
1 1 v
1 2 x
1 3 v
2 1 x
2 2 x
2 3 v
2 3 v
and the result should only be 3
August 14, 2007 at 2:29 am
Hi There,
Will this do the trick?
SELECT COUNT(*)
FROM (SELECT DISTINCT ID_NR,ID_NR_p,KZ FROM dbo.Table WHERE KZ ='V') [nest]
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
August 15, 2007 at 1:54 pm
da -
since you are a self-admitted beginner, here's another technique that you may want to try here: use the search feature of this site - enter your keyword phrase and select only the forums (discussions?) option to search through. It will give you a varied selection of threads that may or may not be on topic for you and may be an efficient way for you to learn about a specific topic quickly.
August 15, 2007 at 8:58 pm
Also, check out GROUP BY and Aggregate Functions in Books Online. You may also want to try the free tutorial at W3Schools.com... won't teach you the specifics of SQL Server but will allow you to learn the basics very quickly.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 16, 2007 at 1:38 pm
perfect tnax loads guys
August 16, 2007 at 2:00 pm
SELECT ID_NR,
SUM(CASE WHEN KZ = 'v' THEN 1 ELSE 0 END) AS [#]
FROM Table1
GROUP BY ID_NR
ORDER BY ID_NR
N 56°04'39.16"
E 12°55'05.25"
August 16, 2007 at 2:14 pm
hello peter
i was thinging abt this solution(but still need to sum up for all distinct id!) but i have asround 2 millions id a´t least:-P
the only thing i need is count(*) as description before!
thanx anyway
August 16, 2007 at 2:33 pm
SELECT ID_NR, SUM([#]) AS [#] FROM (
SELECT DISTINCT ID_NR, ID_NR_p, CASE WHEN KZ = 'v' THEN 1 ELSE 0 END AS [#]
FROM Table1) AS d
GROUP BY ID_NR
ORDER BY ID_NR
N 56°04'39.16"
E 12°55'05.25"
August 22, 2007 at 4:57 pm
i actually check this solution.. it did not work:-(
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply