473,378 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Urgent Deliverable

I had got a table with 3 columns.
I had to get the sum of the third column divide it by 10.
let it be named as total.
then finally i had to split my records into 10 groups such that the
sum of column3 of each group must be less than the variable total(sum
of the third column divide it by 10).
Earlier response is appreciated

the final result should be as follows

col1 col2 col3 rank
EQR 2700 8918.44 10
AES 1400 9115.65 10
AGN 999 10196.67 10
AIV 999 3402.57 10
ASH 999 4415.74 10
ATI 999 2292.05 10
AW 999 2644.65 10
AYE 999 2654.57 10
BMC 999 3735.47 10
CMS 999 2050.46 10
DUK 999 25127.84 10
EDS 999 11006.71 10
EMN 999 4219.86 10
EP 999 6991.52 10
FCX 999 6588.62 10
GLK 999 1350.59 10
GT 999 2707.77 10
IPG 999 5518.71 10
KR 999 12520.19 10
MU 999 6389.95 10
MWV 999 5854.56 10
NCR 999 6371.15 10
RDC 999 3019.74 10
SANM 999 3243.14 10
SGP 999 27334.46 10
SLR 999 4696.96 10
SWY 999 8435.37 10
TE 999 3196.75 10
TIN 999 3561.09 10
TSG 999 2858.63 10
UNM 999 5090.75 10
VIA.B 999 63703.96 10
WMB 999 9378.77 10
XL 999 10368.7 10
JNS 999 3504.15 10
BIIB 999 21667.54 10
RAI 999 11866.37 10
PMTC 600 1541.41 10
X 558.33 5889.25 10
EK 433.33 9486.21 10
CB 418.42 14267.31 10
PCG 366.67 14109.45 10
CMVT 350 4417.54 10
RIG 350 14131.35 10
CTXS 340 3633.5 10
OMX 320 2598.12 10
GP 308.33 8283.98 10
CA 300 15923.63 10
IP 290.91 19049.88 10
AAPL 258.33 31109.82 10
ASN 246.15 6769.59 10
SLB 238.89 40058.07 10
RHI 222.22 5260.35 10
AMAT 220 26699.84 10
BSX 200 27918.41 10
GLW 200 15340.49 10
TXT 200 9898.76 10
XEL 190 7282.18 10
VLO 188 13352.88 10
MAS 184.21 16486.4 10
MERQ 164.29 3704.65 10
MSFT 158.33 285705.38 10
XTO 157.69 9348.59 10
FSH 157.14 7406.67 10
NUE 154.93 8934.55 10
HAL 152.94 18198.59 10
EOG 142.62 8804.19 10
CZN 140 4525.23 10
TXU 135 20151.04 10
HPC 120 1624.63 10
SPG 112.5 13152.98 10
NWL 108.33 5913.7 10
HET 106.25 7087.12 10
DOW 102 46865.61 10
GR 100 4079.37 10
LU 100 14411.27 9
MON 96.55 14413.41 9
CMI 94.39 3535.31 9
WY 94.34 14967.7 9
PNW 93.94 3818.55 9
GENZ 88 14428.28 9
LLY 86.49 61380.1 9
NAV 86 2717.67 9
ANDW 83.33 2102.31 9
BRCM 83.33 8600.98 9
EMC 83.33 31391.26 9
EFX 82.61 3822.96 9
NVLS 81.82 3655.51 9
UCL 80 12519.52 9
NE 76.19 7134.28 9
D 75.95 22995.31 9
PFE 73.33 181948.84 9
MNST 72.73 3726.17 9
ZMH 72.5 19342.22 9
KLAC 69.7 9039.65 9
PD 68.42 9193.47 9
LUV 66.67 11288.36 9
ABS 65.71 8421.14 9
PCAR 64.44 12275.27 9
PKI 63.64 2945 9
TOY 62.69 4612.97 9
ROK 60.98 10476.57 9
YHOO 57.14 48651.21 9
PHM 56.41 8428.83 9
CCL 56 36476.53 9
PLL 55 3339.29 9
DD 54.55 51375.98 9
NBR 54.35 7535.35 9
PPG 53.73 11822.8 9
KG 52.94 2539.7 9
T 52.63 15272.73 9
MAT 50 8071.11 9
SYMC 50 14808.29 9
NOC 47.27 19103.36 9
MXIM 46.43 12687.92 9
KBH 46.29 4229.42 9
NTAP 45.45 11423.65 9
KMG 45.39 9366.98 9
BJS 44.74 7760.46 9
CPWR 44.44 2671.37 9
BHI 43.75 14525.85 9
SBL 42.86 4403.75 9
MOLXE 42.86 5128.62 9
FDX 42.65 28821.07 9
AVY 42.31 6637.48 9
OXY 42.28 23043.87 9
JBL 42.11 4753.74 9
AEE 41.67 9758.36 9
COH 40 10598.08 9
EOP 40 11282.68 9
ODP 40 5401.64 9
VZ 39.53 98547.22 9
CMX 38.71 17536.35 9
CIN 38.6 7312.11 9
QLGC 38.24 3542.16 9
APA 37.74 17766.55 9
FRX 36.84 15299.94 9
PH 36.67 7784.93 9
ETN 36.47 10327.68 9
WAT 36.36 5930.78 9
A 35.71 10858.18 9
CHIR 35.71 6137.96 8
SUN 35.04 6397.79 8
AT 34.43 16718.84 8
BEN 33.82 17056.81 8
JWN 33.78 6758.72 8
SOV 33.33 8611.36 8
NKE 32.43 16154.94 8
ACV 31.82 4942.07 8
FE 31.82 13114.28 8
APOL 31.43 14357.84 8
DE 30.88 17208.36 8
BNI 30.77 18111.92 8
COL 30.77 7631.09 8
NWS.A 30.77 50526.68 8
MHS 30.23 11600.15 8
DG 30 6622.19 8
HLT 30 8589.1 8
TMO 30 4788.9 8
R 29.51 2928.59 8
GDT 29.17 23304.52 8
KSS 29.17 16128.71 8
AMGN 28.85 79053.26 8
MCO 28.57 12391.06 8
UNH 28.41 58107.62 8
JCP 27.71 12201 8
ALL 27.27 34612.53 8
STJ 26.92 14044.17 8
CTX 26.9 7620.47 8
DHR 26.67 16936.9 8
SNA 26.67 1905.12 8
SBUX 26.32 21598.76 8
TRB 25.71 12702.01 8
VMC 25.42 5784 8
BBT 25 21801.96 8
NSC 25 13828.56 8
ORCL 25 71946.41 8
MTB 24.62 11888.09 8
DELL 24.14 103744.53 8
TYC 23.53 73123.58 8
CCU 23.33 18599.87 8
HPQ 23.33 57007.68 8
ESRX 23.26 5637.25 8
APD 22.58 13390.83 8
CSCO 22.22 118788.69 8
NFB 22.22 13507.54 8
MET 22.06 29587.36 7
BC 22 4436.79 7
PG 22 135027.64 7
WYE 21.43 52874.19 7
SYK 21.21 19755.41 7
MDT 21.05 63445.97 7
ABT 20.83 70113.79 7
JP 20.73 6812.45 7
TROW 20.69 7669.6 7
LTD 20.27 9632.3 7
EBAY 20 54027 7
G 20 50355.37 7
CC 19.57 2739.07 7
DIS 19.23 58517.69 7
SPLS 19.05 16301.34 7
CAT 18.97 30404.13 7
EMR 18.97 28222.44 7
SHW 18.75 6106.19 7
BOL 18.6 3874.18 7
LLTC 18.52 11587.76 7
CMA 18.48 9868.6 7
LOW 18 44039.65 7
SIAL 17.91 4339.16 7
CD 17.86 24794.36 7
RX 17.86 5423.06 7
BMET 17.65 10733.76 7
CSC 17.65 9750.73 7
HON 17.65 30948.85 7
UVN 17.65 6958.92 7
XRX 17.65 13342 7
WMT 17.46 221907.04 7
APC 17.42 16376.18 7
DOV 17.07 7788.8 7
BBBY 17.02 12192 7
ADSK 16.67 6740.42 7
CAG 16.67 15207.25 6
MDP 16.67 2418.97 6
COP 16.45 64046.72 6
PX 16.33 14011.84 6
BDK 16.13 6652.98 6
GILD 16 14329.52 5
FII 15.79 3156.76 5
GDW 15.63 19787.03 5
GE 15.63 381971.16 5
AIG 15.53 172657.01 5
AET 15.38 18759.19 5
LMT 15.38 25591.1 5
RKY 15.31 2697.98 5
KRB 15 33960.63 5
GD 14.93 20679.74 5
DDS 14.75 2049.79 5
COST 14.58 22329.97 5
DGX 14.55 9644.36 5
GWW 14.49 5513.92 5
AZO 14.42 7109.66 5
ADM 14.29 15839.21 5
NVDA 14.29 3809.6 5
PAYX 14.29 11535.5 5
TXN 14.29 40105.14 5
WLP 14.29 36498.6 5
MO 14.02 131016.12 5
ADP 14 25328.75 5
ITW 13.98 25719.12 5
HAS 13.95 3469.53 5
WM 13.7 34986.64 5
ABI 13.64 3930.3 5
AXP 13.64 66964.28 4
BBY 13.38 17647.15 4
LXK 13.19 10759.48 4
DRI 13.04 4696.14 4
AVP 12.96 19968.03 4
LH 12.96 6526.5 4
BAX 12.9 20811.28 4
ETR 12.5 15540.85 4
LEG 12.5 5440.62 4
CBE 12.35 6378.43 4
WWY 12.24 13435.41 4
MMM 12.22 65677.13 4
HSY 12.2 10834.75 4
LIZ 12.12 4552.55 4
HD 11.9 90605.11 4
WAG 11.9 43521.04 4
IBM 11.83 155516 4
ITT 11.83 7873.89 4
HDI 11.76 17672.34 4
KMI 11.76 9295.95 4
SNV 11.76 8409.62 4
CBSS 11.59 5754.19 4
PEP 11.54 90456.57 4
SFA 11.43 4646.95 4
GAS 11.39 1627.58 4
BDX 11.29 14423.15 4
TMK 11.22 5902.64 4
ACS 11.11 6608.09 4
GIS 11.11 19345.54 4
FO 10.87 12105.97 4
JNJ 10.84 192011.88 4
MRO 10.84 13422.5 4
XOM 10.84 332886.87 3
FISV 10.64 7481.32 3
ASD 10.53 8589.38 3
FPL 10.39 14223.54 3
ERTS 10.34 19645.06 3
ROH 10.2 9947.01 3
AA 10 25687.84 3
MCD 10 40720.87 3
SYY 10 22373.56 3
MTG 9.92 6184.18 3
IR 9.91 12809.35 3
PBI 9.84 10317.94 3
BLL 9.76 4810.49 3
PGN 9.62 10931.87 3
USB 9.62 56108.1 3
RBK 9.52 2588.26 3
MI 9.23 9565.12 3
UPS 8.96 44892.17 3
UTX 8.77 51451.81 3
HCR 8.7 2986.43 3
MAR 8.7 14127.81 3
CVX 8.47 115252.5 3
BUD 8.33 38855.54 3
RSH 7.79 5248.53 3
CTAS 7.69 7469.99 3
ECL 7.69 8681.7 3
INTC 7.69 141951.35 3
LLL 7.45 8223.43 3
WB 7.45 87974.14 2
MKC 7.41 5086.59 2
MIL 7.27 2164.75 2
MBI 7.2 8406.91 2
AN 7.14 5037.47 2
DVN 7.14 19766.51 2
HOT 7.14 12083.44 2
EXC 7.02 29317.79 2
OMC 6.84 15817.3 2
TIF 6.76 4573.06 2
BR 6.74 17112.33 2
ASO 6.67 8856.27 2
BAC 6.59 187296.64 2
ZION 6.36 6080.94 2
GCI 6 20430.29 2
GPC 6 7392.09 2
ABK 5.81 8354.4 2
SWK 5.71 3912.29 2
K 5.66 18432.3 2
HMA 5.41 5387.28 2
CTL 5.26 4387.01 2
KO 5.26 100382.4 2
NTRS 5.26 9566.28 2
SDS 5.26 7767.74 2
AFL 4.92 19991.43 2
WFC 4.85 103711.57 2
PGL 4.79 1621.89 2
HCA 4.76 18814.15 2
BF.B 4.55 6031.02 2
VRTS 4.55 10881.39 2
CIT 4.55 8485.05 2
ED 4.41 10617.2 2
ET 4.35 5119.07 2
BK 4.26 23081.76 2
INTU 4.11 7309.85 2
UST 4.11 8370.65 2
QCOM 3.85 61289.11 2
COF 3.8 18999.89 2
JCI 3.66 11291.16 2
CPB 3.51 12064.04 2
HNZ 3.51 13208.13 2
CL 3.39 27861.17 2
KEY 3.39 13589.17 2
KRI 2.86 5013.93 2
YUM 2.86 13577.35 2
STI 2.34 26703.14 2
KMB 2.2 31950.93 2
FDO 2.13 5609.8 2
CLX 1.92 12678.8 2
MWD 1.8 61252.3 1
PFG 1.67 12456.44 1
SEE 1.56 4286.83 1
C 0.99 254557.38 1
FD 0.8 9610.84 1
ADCT 0 2082.88 1
BMS 0 3101.23 1
CINF 0 7414.28 1
CVG 0 2023.49 1
GPS 0 19297 1
IFF 0 3978.73 1
LSI 0 2351.93 1
NI 0 6036.17 1
PTV 0 3296.61 1
SCH 0 15140.01 1
STT 0 14940.15 1
TGT 0 45460.78 1
VFC -1.04 5903.69 1
FITB -1.33 27483.2 1
MCK -1.37 10137.16 1
BCR -1.49 7095.27 1
WMI -2.56 16591.77 1
NYT -2.63 5607.78 1
HSP -2.78 4509.58 1
SAFC -3.01 5872.23 1
IGT -3.12 10860.5 1
MER -3.28 55782.8 1
ADI -3.33 13488.9 1
RF -3.33 14873.28 1
EC -4 3675.18 1
CEG -4.55 8792.65 1
MAY -5.07 9898.33 1
PVN -5.71 4889.12 1
ADBE -6 13577.88 1
LEH -6.33 24568.23 1
HBAN -6.67 5308.5 1
MHP -7.69 17185.95 1
SLM -7.81 21573.12 1
SO -8.89 24928.34 1
BSC -8.95 10433.94 1
SVU -10 4270.67 1
WPI -10.42 3266.44 1
HIG -10.45 19763.81 1
ABC -10.57 6126.22 1
APCC -10.71 4068.23 1
FHN -10.87 5241.56 1
FLR -11.11 4486.49 1
NEM -11.11 16962.98 1
PNC -11.3 15225.71 1
CAH -11.49 24334.52 1
RTN -11.54 16906.97 1
CFC -12.09 21475.47 1
JNY -12.12 4110.36 1
ALTR -13.33 7148.03 1
LTR -13.41 12613.93 1
CVS -14.06 18543.01 1
STA -14.18 25131.6 1
GS -15.6 52219.46 1
PRU -15.79 27548.01 1
FDC -16.39 33807.93 1
SEBL -16.67 4426.18 1
TJX -17.02 12066.1 1
AV -18.18 6569.4 1
WHR -18.75 4534.17 1
PGR -19.14 16747.06 1
MEL -19.3 12431.16 1
WEN -19.64 4470.22 1
CSX -20 8586.71 1
FON -20 33009.84 1
HRB -20.34 7957.53 1
DCN -21.62 2377.25 1
CI -21.84 10773.72 1
KSE -22.22 6338.72 1
AHC -22.38 7941.73 1
PLD -22.54 7013.95 1
MRK -23.29 62203.26 1
JPM -23.91 132986.74 1
MOT -24 38318.12 1
FNM -27.6 62478.2 1
DTE -28.68 7621.1 1
PEG -28.99 12543.42 1
CMCSA -29.41 71146.96 1
NXTL -30.36 31031.88 1
BMY -30.61 45605.03 1
SRE -30.63 8686.74 1
AOC -31.34 7196.19 1
NOVL -33.33 2185.12 1
NSM -33.33 6015.33 1
TLAB -33.33 3296.56 1
TWX -33.33 79365.38 1
SLE -34.04 18427.41 1
RRD -34.12 7328.9 1
HUM -34.15 5462.91 1
PPL -35.66 10208.32 1
PBG -36.84 6839.77 1
TEK -38 2575.79 1
CTB -39.47 1617.88 1
NCC -39.66 23300.29 1
BLS -39.68 48065.41 1
BLI -40 1270.86 1
MYL -41.94 4475.18 1
MEDI -43.33 5883.52 1
SBC -45.76 78774.24 1
UNP -47.62 15471.27 1
XLNX -50 10167.26 1
FRE -52.65 44950.27 1
CCE -53.57 10299.51 1
PCL -53.57 6557.16 1
DJ -54.55 3183.08 1
F -55.79 23163.61 1
MYG -59.18 1244.55 1
MMC -59.42 17125.13 1
FSL.B -60.53 6939.89 1
LNC -60.64 8055.91 1
EIX -61.02 10579.08 1
AMD -75 5799.67 1
LPX -76.32 2817.36 1
PMCS -77.78 1830.29 1
ACE -81.7 12334.19 1
GM -91.11 20791.24 1
BA -96.35 42483.61 1
AEP -100 13946.94 1
AMCC -100 1019.95 1
SUNW -100 14663.01 1
CNP -104.35 3463.42 1
UIS -155.56 2637.06 1
TER -195 2724.39 1
VC -213.04 961.16 1
DPH -360 4259.45 1
CIEN -999 1457.99 1
CPN -999 1779.24 1
DAL -999 697.53 1
DYN -999 1259.96 1
GTW -999 1767.76 1
JDSU -999 2969.83 1
PWER -999 623.67 1
Q -999 7626.81 1
S -999 10392.45 1
THC -999 4634 1
Jul 23 '05 #1
5 1413
Too lazy to test, but here goes:

-- get the desired subgroup total
declare @total dec(28,2)
select @total=sum(col3)/10.0 from myTbl

-- create a running total column by using the proprietary Update syntax
select *, col3 as runTotal
into #T
from myTbl
order by col2 desc

declare @v dec(28,2)
set @v=0.0
update #T
set @v=runTotal=@v+col3

-- now assign the rank
select col1, col2, col3,
case
when runTotal <= 1*@total then 10
when runTotal <= 2*@total then 9
when runTotal <= 3*@total then 8
when runTotal <= 4*@total then 7
when runTotal <= 5*@total then 6
when runTotal <= 6*@total then 5
when runTotal <= 7*@total then 4
when runTotal <= 8*@total then 3
when runTotal <= 9*@total then 2
else 1 as Rank
from #T

Jul 23 '05 #2
I missed an "end" in the case statement. It should be "else 1 end as
Rank".

Jul 23 '05 #3
Hello louis,

Fantastic and Great Work.Thanks For your Early Reply.It worked
greatly.If u have time please send me a mail regarding u r contact
details so that we can maintain a good friendship Relation
Thanks
Kalyan


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Kalyan,

Thanks for the compliment. I can be reached at
lo************@gmail.com.

Jul 23 '05 #5
It seems google groups is protecting me from myself. The first part of
my address is "louisduc" and the last part of my email address is
"nguyen".

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob | last post by:
I have a form - when you click the submit button, it appends a variable to the URL (e.g. xyz.cgi?inputID=some_dynamic_variable) It also opens a new page. Now, that some_dynamic_variable is...
9
by: Stefan Bauer | last post by:
Hi NG, we've got a very urgent problem... :( We are importing data with the LOAD utility. The input DATE field data is in the format DDMMYYYY (for days) and MMYYYY (for months). The target...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
8
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.