Sql for arithmetic (division)

G

Guest

Hello
Many thanks in advance for you help.
I have 2 sql from 2 tables:

The first sql is:
SELECT F02_Hato.CodProd, F02_Hato.CodPer, Sum(F02_Hato.CodAnimal) AS [Carga
Animal]
FROM F02_Hato
WHERE ((([F02_Hato]![Cabezas]*[F02_Hato]![UnidadAnimal]) In
("1","2","3","4","5","6","7","8","9","10","11","12","13")))
GROUP BY F02_Hato.CodProd, F02_Hato.CodPer;

The second sql
SELECT F01_UT.CodProd, F01_UT.CodPer, Sum(F01_UT.Finca1) AS TotalUT
FROM F01_UT
WHERE (((F01_UT.CodUT) In ("2","3","5")))
GROUP BY F01_UT.CodProd, F01_UT.CodPer;

I woul like to to calculate [Carga Animal]/TotalUT. Is posible to do? How
can I do the division?

Both tables are related 1 to many to a Per Table by Cod Per and Prod Table 1
to may by Cod Prod.

Thank you very much
 
M

Michel Walsh

Make a new query, bring both of your queries as if they were tables. Join
them through their CodProd and CodePer fields.

Bring the twofirst fields, from one of the table, in the grid. In a third
column of the grid, type:

[query1NameHere].[Carga Animal] / [query2NameHere].[TotalUT]



That's all.



Hoping it may help,
Vanderghast, Access MVP
 
G

Guest

Perfect.It Worked. Thanks

On the other hand I have in mind to organize the product of several querys
in a table having the column 1 as CodProd and Column 2 CodPer. How do i add
more columns to display the product of the querys previously calculated? Can
i make a new query bringing all the querys as if they were tables joining
them through CodProd and CodPer fields?can I bring the field of every
calculaterd query to a new column?
Thanks againg

Michel Walsh said:
Make a new query, bring both of your queries as if they were tables. Join
them through their CodProd and CodePer fields.

Bring the twofirst fields, from one of the table, in the grid. In a third
column of the grid, type:

[query1NameHere].[Carga Animal] / [query2NameHere].[TotalUT]



That's all.



Hoping it may help,
Vanderghast, Access MVP


sebastico said:
Hello
Many thanks in advance for you help.
I have 2 sql from 2 tables:

The first sql is:
SELECT F02_Hato.CodProd, F02_Hato.CodPer, Sum(F02_Hato.CodAnimal) AS
[Carga
Animal]
FROM F02_Hato
WHERE ((([F02_Hato]![Cabezas]*[F02_Hato]![UnidadAnimal]) In
("1","2","3","4","5","6","7","8","9","10","11","12","13")))
GROUP BY F02_Hato.CodProd, F02_Hato.CodPer;

The second sql
SELECT F01_UT.CodProd, F01_UT.CodPer, Sum(F01_UT.Finca1) AS TotalUT
FROM F01_UT
WHERE (((F01_UT.CodUT) In ("2","3","5")))
GROUP BY F01_UT.CodProd, F01_UT.CodPer;

I woul like to to calculate [Carga Animal]/TotalUT. Is posible to do? How
can I do the division?

Both tables are related 1 to many to a Per Table by Cod Per and Prod Table
1
to may by Cod Prod.

Thank you very much
 
M

Michel Walsh

At first glace, I would say yes. If all the queries have each and every
group, there should be no problem, else, the inner join will acts like an
intersection and the result would only be about the groups common to all
queries.


Hoping it may help,
Vanderghast, Access MVP


sebastico said:
Perfect.It Worked. Thanks

On the other hand I have in mind to organize the product of several querys
in a table having the column 1 as CodProd and Column 2 CodPer. How do i
add
more columns to display the product of the querys previously calculated?
Can
i make a new query bringing all the querys as if they were tables joining
them through CodProd and CodPer fields?can I bring the field of every
calculaterd query to a new column?
Thanks againg

Michel Walsh said:
Make a new query, bring both of your queries as if they were tables. Join
them through their CodProd and CodePer fields.

Bring the twofirst fields, from one of the table, in the grid. In a
third
column of the grid, type:

[query1NameHere].[Carga Animal] / [query2NameHere].[TotalUT]



That's all.



Hoping it may help,
Vanderghast, Access MVP


sebastico said:
Hello
Many thanks in advance for you help.
I have 2 sql from 2 tables:

The first sql is:
SELECT F02_Hato.CodProd, F02_Hato.CodPer, Sum(F02_Hato.CodAnimal) AS
[Carga
Animal]
FROM F02_Hato
WHERE ((([F02_Hato]![Cabezas]*[F02_Hato]![UnidadAnimal]) In
("1","2","3","4","5","6","7","8","9","10","11","12","13")))
GROUP BY F02_Hato.CodProd, F02_Hato.CodPer;

The second sql
SELECT F01_UT.CodProd, F01_UT.CodPer, Sum(F01_UT.Finca1) AS TotalUT
FROM F01_UT
WHERE (((F01_UT.CodUT) In ("2","3","5")))
GROUP BY F01_UT.CodProd, F01_UT.CodPer;

I woul like to to calculate [Carga Animal]/TotalUT. Is posible to do?
How
can I do the division?

Both tables are related 1 to many to a Per Table by Cod Per and Prod
Table
1
to may by Cod Prod.

Thank you very much
 
Top