Discussion:
How to simulate a list of value in a specific range
(too old to reply)
Lucia
2007-07-21 19:40:07 UTC
Permalink
Ciao a tutti, vorrei gestire una simulazione di combinazioni in SQL ma
non so come strutturare in modo corretto le tabelle e le query.

I would like simulate all combinations of the ingredients in a specific
prescriptions

I must to create the tables and query and I would like to know how to
manage a simulation


I have made some tests in Access (holding one table with one series of
values, pass, of type 0,100 0,200 0,300…) but Access does not seem to be
the software adapted.

I try to describe the problem


Table ingredients
Nome
Weight (always 100 for all ingredients )
Caratteristica1
Caratteristica2
Caratteristica3
...
Caratteristica7


In the prescriptions table I insert all ingredients of a specific
prescriptions
(I can set 10 as the maximum of ingredients that I can Insert in a
prescription ... for simplify the query)


Tabella Ricette:
prescriptionsName
ingredientsName (ingredients Table)

in this table I've the X ingrediets of the prescription

Now I want to simulate the combinations of X ingredients if I want to
have X weight of the prescription

fot all combination that has the X ingredients and that has specific
range for the "CaratteristicaX" column

Example

If I want 4000 Weight of a specific prescription (4000 is an user
information)

for each ingredients I must to do

(Caratteristica1/Weight(always 100))*4000
(Caratteristica2/Weight(always 100))*4000
(Caratteristica3/Weight(always 100))*4000

Now I've the value of each Caratteristica for the weight of the
prescripton (4000)


I sum all ingredientrs (with the Caratteristica value) and I've the
value of the "CaratteristicaX" for all prescription

I find the value of the Caratteristica in the total weight (4000):

totalCaratteristica1/4000*100 -> %
totalCaratteristica2/4000*100 -> %
totalCaratteristica3/4000*100 - %



Now I must to find all combination of ingredients (all ingredients of
the prescription) that has the sum of "Caratteristica" in the range

Caratteristica1 between 10% and 15%
Caratteristica2 between 20% and 50%
Caratteristica3 between 40% and 50%



Thanks for help me!!!
Lucia
2007-07-23 09:14:17 UTC
Permalink
Nobody can help me??
JPD
2007-07-23 09:22:47 UTC
Permalink
Ciao Lucia,

Potresti darmi una descrizzione del tuo problema in Italiano per favore?
La versione inglese non l'ho capito bene.

Jonathan
Post by Lucia
Nobody can help me??
Lucia
2007-07-23 13:15:39 UTC
Permalink
Post by JPD
Ciao Lucia,
Potresti darmi una descrizzione del tuo problema in Italiano per favore?
La versione inglese non l'ho capito bene.
Jonathan
Non è che non l'hai capita bene tu, sono io che mi sono espressa
malissimo :-((

(io ho ipotizzato una struttura del DB, sicuramente sbagliata ... penso
di aver affrontato il problema dalla parte sbagliata); chiedo troppo se
ti invio il backup del mio DB??

Problema:

Ho fatto alcune prove in Access (tenendo una tabella con una serie di
valori, passi, del tipo 0,100 0,200 0,300...) ma Access non sembra
essere lo strumento adatto.

Provo ad illustrare il problema, spero che qualcuno mi sappia dare
qualche dritta per gestire il problema con SQL Server



Tabella Ingredienti:
Nome
Grammi (sempre 100 per tutti gli ingredienti)
Caratteristica1
Caratteristica2
Caratteristica3
...
Caratteristica7
(le caratteristiche sono 7)



Dovrei poi una tabella Ricette nella quale vengono inseriti gli X
prodotti per quella ricetta (se preferito posso porre un vincolo di
massimo 10 ingredienti per ricetta)

Tabella Ricette:
NomeRicetta
NomeIngrediente (tabella ingredienti)

in questa tabella inserisco gli X ingredienti della ricetta

Io devo fare una simulazione degli X ingredienti della ricetta
ipotizzando di voler produrre X grammi totali, trovando tutte le
combinazioni degli X ingredienti che rispettando dei range di valori:
Caratteristica1 deve essere tra 10% e 15%, Caratteristica2 deve essere
tra 20% e 50%, Caratteristica3 deve essere tra 40% e 50%,

Tradotto in un esempio:

ipotizzando di voler produrre 4000 grammi (dato fornito dall'utente)

per ogni ingrediente devo fare:
(Caratteristica1/Grammi(che è sempre 100))*4000
(Caratteristica2/Grammi(che è sempre 100))*4000
(Caratteristica3/Grammi(che è sempre 100))*4000

in questo modo trovo il valore della caratteristica rapportato al peso
totale da produrre (4000)


sommo tutti gli ingredienti (con le relative caratteristiche) e quindi
trovo il valore delle caratteristiche per tutta la ricetta

calcolo il rapporto percentuale della somma totale della caratteristica
sul peso totale:
totaleCaratteristica1/4000*100
totaleCaratteristica2/4000*100
totaleCaratteristica3/4000*100
quindi ho l'influenza della caratteristica sul peso totale (4000)


fatto questo devo trovare tutte le combinazioni di ingredienti che hanno
il parametro percentuale delle 3 caratteristiche nei range:

Caratteristica1 deve essere tra 10% e 15%
Caratteristica2 deve essere tra 20% e 50%
Caratteristica3 deve essere tra 40% e 50%
JPD
2007-07-23 14:51:35 UTC
Permalink
Le caratteristiche hanno sempre gli stessi valori per tutti
gl'ingredienti e se si quali sono?

Jonathan
Post by Lucia
Post by JPD
Ciao Lucia,
Potresti darmi una descrizzione del tuo problema in Italiano per
favore? La versione inglese non l'ho capito bene.
Jonathan
Non è che non l'hai capita bene tu, sono io che mi sono espressa
malissimo :-((
(io ho ipotizzato una struttura del DB, sicuramente sbagliata ... penso
di aver affrontato il problema dalla parte sbagliata); chiedo troppo se
ti invio il backup del mio DB??
Ho fatto alcune prove in Access (tenendo una tabella con una serie di
valori, passi, del tipo 0,100 0,200 0,300...) ma Access non sembra
essere lo strumento adatto.
Provo ad illustrare il problema, spero che qualcuno mi sappia dare
qualche dritta per gestire il problema con SQL Server
Nome
Grammi (sempre 100 per tutti gli ingredienti)
Caratteristica1
Caratteristica2
Caratteristica3
...
Caratteristica7
(le caratteristiche sono 7)
Dovrei poi una tabella Ricette nella quale vengono inseriti gli X
prodotti per quella ricetta (se preferito posso porre un vincolo di
massimo 10 ingredienti per ricetta)
NomeRicetta
NomeIngrediente (tabella ingredienti)
in questa tabella inserisco gli X ingredienti della ricetta
Io devo fare una simulazione degli X ingredienti della ricetta
ipotizzando di voler produrre X grammi totali, trovando tutte le
Caratteristica1 deve essere tra 10% e 15%, Caratteristica2 deve essere
tra 20% e 50%, Caratteristica3 deve essere tra 40% e 50%,
ipotizzando di voler produrre 4000 grammi (dato fornito dall'utente)
(Caratteristica1/Grammi(che è sempre 100))*4000
(Caratteristica2/Grammi(che è sempre 100))*4000
(Caratteristica3/Grammi(che è sempre 100))*4000
in questo modo trovo il valore della caratteristica rapportato al peso
totale da produrre (4000)
sommo tutti gli ingredienti (con le relative caratteristiche) e quindi
trovo il valore delle caratteristiche per tutta la ricetta
calcolo il rapporto percentuale della somma totale della caratteristica
totaleCaratteristica1/4000*100
totaleCaratteristica2/4000*100
totaleCaratteristica3/4000*100
quindi ho l'influenza della caratteristica sul peso totale (4000)
fatto questo devo trovare tutte le combinazioni di ingredienti che hanno
Caratteristica1 deve essere tra 10% e 15%
Caratteristica2 deve essere tra 20% e 50%
Caratteristica3 deve essere tra 40% e 50%
Lucia
2007-07-23 20:33:23 UTC
Permalink
Prima di tutto grazie per l'aiuto

Nella tabella ingredienti ho 7 caratteristiche che possono avere vari
valori decimal(10,2) ... ogni ingrediente ha valori differenti
JPD
2007-07-24 08:56:36 UTC
Permalink
Non c'e problema!

Questi valori decimal sono percentuali, no? Lo voglio sapere per sapere
se superano mai il 100.
Post by Lucia
Prima di tutto grazie per l'aiuto
Nella tabella ingredienti ho 7 caratteristiche che possono avere vari
valori decimal(10,2) ... ogni ingrediente ha valori differenti
Lucia
2007-07-24 20:22:40 UTC
Permalink
No, purtroppo non sono valori percentuali. Sono parametri inseriti in
funzione di calcoli precedenti e fissi ogni ingrediente (non fa 100 la
somma delle caratteristiche)

Grazie infinite per l'aiuto che mi stai dando
Lucia
2007-07-25 14:52:18 UTC
Permalink
Nessun aiutino?? :-((
SB
2007-07-24 03:27:54 UTC
Permalink
Post by Lucia
Ciao a tutti, vorrei gestire una simulazione di combinazioni in SQL ma
non so come strutturare in modo corretto le tabelle e le query.
I would like simulate all combinations of the ingredients in a specific
prescriptions
I must to create the tables and query and I would like to know how to
manage a simulation
I have made some tests in Access (holding one table with one series of
values, pass, of type 0,100 0,200 0,300...) but Access does not seem to be
the software adapted.
I try to describe the problem
Table ingredients
Nome
Weight (always 100 for all ingredients )
Caratteristica1
Caratteristica2
Caratteristica3
...
Caratteristica7
In the prescriptions table I insert all ingredients of a specific
prescriptions
(I can set 10 as the maximum of ingredients that I can Insert in a
prescription ... for simplify the query)
prescriptionsName
ingredientsName (ingredients Table)
in this table I've the X ingrediets of the prescription
Now I want to simulate the combinations of X ingredients if I want to
have X weight of the prescription
fot all combination that has the X ingredients and that has specific
range for the "CaratteristicaX" column
Example
If I want 4000 Weight of a specific prescription (4000 is an user
information)
for each ingredients I must to do
(Caratteristica1/Weight(always 100))*4000
(Caratteristica2/Weight(always 100))*4000
(Caratteristica3/Weight(always 100))*4000
Now I've the value of each Caratteristica for the weight of the
prescripton (4000)
I sum all ingredientrs (with the Caratteristica value) and I've the
value of the "CaratteristicaX" for all prescription
totalCaratteristica1/4000*100 -> %
totalCaratteristica2/4000*100 -> %
totalCaratteristica3/4000*100 - %
Now I must to find all combination of ingredients (all ingredients of
the prescription) that has the sum of "Caratteristica" in the range
Caratteristica1 between 10% and 15%
Caratteristica2 between 20% and 50%
Caratteristica3 between 40% and 50%
Thanks for help me!!!
I think what you are looking for is something like following:
select sum(Caratteristica1) 4000*100,
sum(Caratteristica2)/ 4000*100 ,
sum(Caratteristica3)/ 4000*100
from etc...
having (sum(Caratteristica1) 4000*100) between 10 and 15
and (sum(Caratteristica2)/ 4000*100) between 20 and 50
and (sum(Caratteristica3)/ 4000*100 ) between 40 and 50
SB
2007-07-24 03:36:14 UTC
Permalink
Post by Lucia
Ciao a tutti, vorrei gestire una simulazione di combinazioni in SQL ma
non so come strutturare in modo corretto le tabelle e le query.
I would like simulate all combinations of the ingredients in a specific
prescriptions
I must to create the tables and query and I would like to know how to
manage a simulation
I have made some tests in Access (holding one table with one series of
values, pass, of type 0,100 0,200 0,300...) but Access does not seem to be
the software adapted.
I try to describe the problem
Table ingredients
Nome
Weight (always 100 for all ingredients )
Caratteristica1
Caratteristica2
Caratteristica3
...
Caratteristica7
In the prescriptions table I insert all ingredients of a specific
prescriptions
(I can set 10 as the maximum of ingredients that I can Insert in a
prescription ... for simplify the query)
prescriptionsName
ingredientsName (ingredients Table)
in this table I've the X ingrediets of the prescription
Now I want to simulate the combinations of X ingredients if I want to
have X weight of the prescription
fot all combination that has the X ingredients and that has specific
range for the "CaratteristicaX" column
Example
If I want 4000 Weight of a specific prescription (4000 is an user
information)
for each ingredients I must to do
(Caratteristica1/Weight(always 100))*4000
(Caratteristica2/Weight(always 100))*4000
(Caratteristica3/Weight(always 100))*4000
Now I've the value of each Caratteristica for the weight of the
prescripton (4000)
I sum all ingredientrs (with the Caratteristica value) and I've the
value of the "CaratteristicaX" for all prescription
totalCaratteristica1/4000*100 -> %
totalCaratteristica2/4000*100 -> %
totalCaratteristica3/4000*100 - %
Now I must to find all combination of ingredients (all ingredients of
the prescription) that has the sum of "Caratteristica" in the range
Caratteristica1 between 10% and 15%
Caratteristica2 between 20% and 50%
Caratteristica3 between 40% and 50%
Thanks for help me!!!
I think what you are looking for is something like following:
select sum(value for Caratteristica1) 4000*100,
sum(value for Caratteristica2)/ 4000*100 ,
sum(value for Caratteristica3)/ 4000*100
from etc...
group by ingredients
having (sum(value for Caratteristica1) 4000*100) between 10 and 15
and (sum(value for Caratteristica2)/ 4000*100) between 20 and 50
and (sum(value for Caratteristica3)/ 4000*100 ) between 40 and 50
Lucia
2007-08-13 21:19:41 UTC
Permalink
nobody can help me???

Loading...