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
 COUNT

Author  Topic 

maximgor
Starting Member

7 Posts

Posted - 2008-02-05 : 11:59:10
I need to count numbers in field A and use derived field to show. For example, field A has numbers 22, 34, 31, 21, 22.So, I need to show in field B how many cases I had. B=Count(A). Somehow, it shows me only 1 even if i have number 22 repeated. CASES(heather of B column) should show 1 for everything but 2 for 22. Any help is appreciated!

Mickey.

MG

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-05 : 12:05:07
SELECT A,COUNT(A)
FROM Table
GROUP BY A
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-05 : 12:05:29
SELECT B, COUNT(A)
FROM Table1
GROUP BY B



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-02-05 : 12:31:02
how to count:
http://weblogs.sqlteam.com/mladenp/archive/2008/02/04/Back-to-Basics-Count-Count-Count-Sum-or-how-to.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

maximgor
Starting Member

7 Posts

Posted - 2008-02-05 : 12:37:37
drg_01 is column A. B column is count(drg_01) NAME(cnt) COLHDG("CASES"). But it counts only 1 time. So, if it is repeated, it doesn't count.

SELECT nwdocnum.patients NAME(NWDOCNU_01), patno.patients, phname.phymast, YEAR(ISDDATE) NAME(DISCHYR) LEN(4,0) COLHDG("DISCHYR"), MONTH(isddate) NAME(DISCHMTH) LEN(4,0) COLHDG("DISCHMTH"),
WEEK(ISDDATE) NAME(DISCHWK) LEN(4,0) COLHDG("DISCHWK"), drg.patients NAME(drg_01), drgdes.drgmsdescn NAME(DRGDES_01) LEN(30), abdrgw.mrabmstr LEN(7,2) COLHDG("WEIGHT"),
count(drg_01) NAME(cnt) COLHDG("CASES"), abals.mrabmstr COLHDG("DAYS"), abels.mrabmstr NAME(ABELS_01) COLHDG("GM_LOS"), abels.mrabmstr COLHDG("GM_SUM")
FROM hospf001/patients,hospf001/mrabmstr,hospf001/phymast,mrf400perm/drgmsdescn
PARTIAL OUTER JOIN patno.patients=abnumb.mrabmstr and nwdocnum.patients=nwdrnum.phymast and abdrg.mrabmstr=drg.drgmsdescn
WHERE NWDOCNUM IN(16,88,124,189,207,240,800) and rectyp="I" AND ISDDATE BETWEEN "&&FROM" AND "&&THRU"
GROUP BY NWDOCNU_01,patno,phname,DISCHYR,DISCHMTH,DISCHWK,drg_01,DRGDES_01,abdrgw,abals,ABELS_01,abels
ORDER BY NWDOCNU_01 Asc,DISCHWK Asc

MG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-05 : 12:41:34
this is certainly not SQL Server code. This is SQL Server forum.
Go to Top of Page
   

- Advertisement -