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 |
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-16 : 21:49:50
|
| SELECT SUM(T1.SUM_REG_AMT) AS SALES_AMT, COUNT(DISTINCT(T1.LOYALTY_ACCOUNT_ID)) AS MEM_COUNT, SALES_AMT / MEM_COUNT AS AVER,casewhen t1.SUM_REG_AMT < 1000 then 1when T1.SUM_REG_AMT >= 1000 and T1.SUM_REG_AMT < 2000 then 2when T1.SUM_REG_AMT >= 2000 and T1.SUM_REG_AMT < 3000 then 3when T1.SUM_REG_AMT >= 3000 and T1.SUM_REG_AMT < 5000 then 4when T1.SUM_REG_AMT >= 5000 and T1.SUM_REG_AMT < 10000 then 5when T1.SUM_REG_AMT >= 10000 and T1.SUM_REG_AMT < 15000 then 6when T1.SUM_REG_AMT >= 15000 and T1.SUM_REG_AMT < 20000 then 7when T1.SUM_REG_AMT >= 20000 and T1.SUM_REG_AMT < 30000 then 8when T1.SUM_REG_AMT >= 30000 and T1.SUM_REG_AMT < 40000 then 9when T1.SUM_REG_AMT >= 40000 and T1.SUM_REG_AMT < 50000 then 10when T1.SUM_REG_AMT >= 50000 and T1.SUM_REG_AMT < 70000 then 11when T1.SUM_REG_AMT >= 70000 and T1.SUM_REG_AMT < 100000 then 12when T1.SUM_REG_AMT >= 100000 then 13end AS TIER_SEQFROM SUM_AWARD_BRANCH T1, BRANCH T2WHERE T1.BRANCH_ID = T2.BRANCH_IDAND T2.CORPORATION_ID = 305AND T1.YEAR_NO = 2011AND T1.MONTH_NO BETWEEN 1 AND 6GROUP BY case, T1.LOYALTY_ACCOUNT_IDORDER BY TIER_SEQ ASCi have another table, that contains tier informationtier_idlower_boundupper_boundand tier_seqcan i compare that computed column to another table that doesnt have an related key to the 1st 2 to table? |
|
|
kfluffie
Posting Yak Master
103 Posts |
Posted - 2011-12-17 : 00:57:09
|
| I am not sure how you are going to compare or join the information together.How is the data from SUM_AWARD_BRANCH related to the other table? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-17 : 03:12:07
|
| the posted code is not syntactically correct . for example you cant use aliases directly as in SALES_AMT / MEM_COUNT AS AVER------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|