nrsh_ram Posted February 8, 2010 Share Posted February 8, 2010 Hi there, I need a help whereby i am wondering if SQL can perform calculation on statistics? i am looking an sql command to genarate all the sample space ..for an example the user key in 123.. so the sql command muct be able to generate the sample space {123,132,213,2} is this can be done in sql? kindly advice. Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/ Share on other sites More sharing options...
RussellReal Posted February 8, 2010 Share Posted February 8, 2010 do you mean.. for 123 123 213 221 132 312 321 231 ? then no BUT before you insert it into a row you can calculate it yourself.. or when you retrieve it you can calculate it.. Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008685 Share on other sites More sharing options...
Mchl Posted February 8, 2010 Share Posted February 8, 2010 then no Actually yes... same way you can drive nails into a wall with a screwdriver.... Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008692 Share on other sites More sharing options...
Gamic Posted February 8, 2010 Share Posted February 8, 2010 Just for fun: create table #test( n int ); insert into #test(n) values (1); insert into #test(n) values (2); insert into #test(n) values (3); select distinct convert(char(1),t1.n) + convert(char(1), t2.n) + convert(char(2), t2.n) as 'output' from #test t1 cross join #test t2 cross join #test t3 order by 1 asc ; Result: output ------ 111 122 133 211 222 233 311 322 333 (9 row(s) affected) Seemed a lot easier than driving a nail into a wall - but will become a lot more annoying when you need to add extra numbers Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008699 Share on other sites More sharing options...
Mchl Posted February 8, 2010 Share Posted February 8, 2010 And what these numbers represent? Where are 123,132,213 as demanded by OP? SELECT t1.n,t2.n,t3.n FROM test AS t1 CROSS JOIN test AS t2 ON t1.n != t2.n CROSS JOIN test AS t3 ON t1.n != t3.n AND t2.n != t3.n; Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008703 Share on other sites More sharing options...
RussellReal Posted February 8, 2010 Share Posted February 8, 2010 Hi there, I need a help whereby i am wondering if SQL can perform calculation on statistics? i am looking an sql command to genarate all the sample space ..for an example the user key in 123.. so the sql command muct be able to generate the sample space {123,132,213,2} is this can be done in sql? kindly advice. however, I'm sure you can define a mysql function for this. but it is so pointless to have mysql do this in the first place, and insert and drop and create tables for each page view.. I shouldn't have said it was impossible, but thats alot more work then just doing it in php.. Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008765 Share on other sites More sharing options...
Gamic Posted February 8, 2010 Share Posted February 8, 2010 Those numbers have gone for a walk . But yea, just goes to show how silly one little typo can be. create table #test( n int ); insert into #test(n) values (1); insert into #test(n) values (2); insert into #test(n) values (3); select distinct convert(char(1),t1.n) + convert(char(1), t2.n) + convert(char(1), t3.n) as 'output' -- typo last time was t2.n being used twice... silly me! from #test t1 cross join #test t2 cross join #test t3 order by 1 asc ; drop table #test; And this now produces the much better output: output ------ 111 112 113 121 122 123 //Here's one! 131 132 //Ah, This one was missing too! 133 211 212 213 //And you! 221 222 223 231 232 233 311 312 313 321 322 323 331 332 333 //Only half evil! Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1009119 Share on other sites More sharing options...
Mchl Posted February 8, 2010 Share Posted February 8, 2010 Yeah. Now we have solutions for both with- and without- repetition permutations. A recursive function in PHP could be written for both. Quote Link to comment https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1009121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.