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 |
|
Malik
Starting Member
3 Posts |
Posted - 2011-11-18 : 00:42:46
|
Hi All, I am trying to do some calculation on my tables but i need your advice about the best way to do it. I have large table such as with following values: notice frequent means count for the the records with same values. A1 | A2| A3 | A4 | A5 | frequent m | f | aaa | 10 | 3 | 1m | f | aaa | 5 | 2 | 1s | m | bbb | 10 | 3 | 1i devide the above table to two small tables and group by the values TableA and Table BTableA A1 | A2 | A3 | frequent m | f | aaa | 2s | m | bbb | 1Table BA4 | A5 | frequent10 | 3 | 2 5 | 2 | 1I would like to get the result of dividing the frequent of table B on the frequent of Table A, where values in table A and values in Table B must be exist in Large table. Thank you very much in advance for your help.   |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-18 : 01:55:42
|
if tables are not already existing ,useSELECT A1,A2,A3,COUNT(*) AS frequent INTO TableAFROM mastertableGROUP BY A1,A2,A3SELECT A4,A5,COUNT(*) AS frequent INTO TableBFROM mastertableGROUP BY A4,A5and if they're already existing useINSERT TableA (A1,A2,A3,frequent)SELECT A1,A2,A3,COUNT(*) FROM mastertableGROUP BY A1,A2,A3INSERT TableB (A4,A5,frequent)SELECT A4,A5,COUNT(*) FROM mastertableGROUP BY A4,A5 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Malik
Starting Member
3 Posts |
Posted - 2011-11-18 : 06:21:39
|
Thanks for replying. I do not have a problem with creating and group the records in a new table. But the problem is how to calculate the(row_tableB/row_tableA) where attributes values for tableA and tableB must be in master table. quote: Originally posted by visakh16 if tables are not already existing ,useSELECT A1,A2,A3,COUNT(*) AS frequent INTO TableAFROM mastertableGROUP BY A1,A2,A3SELECT A4,A5,COUNT(*) AS frequent INTO TableBFROM mastertableGROUP BY A4,A5and if they're already existing useINSERT TableA (A1,A2,A3,frequent)SELECT A1,A2,A3,COUNT(*) FROM mastertableGROUP BY A1,A2,A3INSERT TableB (A4,A5,frequent)SELECT A4,A5,COUNT(*) FROM mastertableGROUP BY A4,A5 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-18 : 10:28:50
|
ok. for that do likeSELECT m.A1,m.A2,m.A3,m.A4,m.A5,b.frequent*1.0/a.frequent as [b/a value]FROM Master mJOIN tableA aON a.A1 = m.A1AND a.A2 = m.A2AND a.A3 = m.A3JOIN tableB bON b.A4 = m.A4AND b.A5 = m.A5 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|