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
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
Share on other sites

And what these numbers represent?

Where are 123,132,213 as demanded by OP? :P

 

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;

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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