Jump to content

probability in php


nrsh_ram

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/191295-probability-in-php/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008699
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1008765
Share on other sites

Those numbers have gone for a walk :P.

 

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!

Link to comment
https://forums.phpfreaks.com/topic/191295-probability-in-php/#findComment-1009119
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.