Re: SQL that performs division



Chris wrote:
I have a table that has some measures for recipes. Things like cup
pint gallon etc... I am trying to write something that can convert
between them easily. So far this is the direction i have taken:


I have a database that has, among other data:
Teaspoon 1
Tablespoon 3
Fluid OZ 6
Gill 24
Cup 48
Pint 96
Quart 192
Gallon 768
Firkin 6912
Hogshead 48384

That is a list of some of the values, it is column measure_name and
conversion_rate, the conversion rate for these measures are all
exressed in teaspoons.

The SQL query I wrote to do the conversion is here:
-- how many cups in a hogshead?
SELECT b1/a1 conversion FROM
(SELECT m.conversion_rate a1 FROM measure m
WHERE m.measure_name = 'cup') a, (SELECT m1.conversion_rate b1 FROM
measure m1
WHERE m1.measure_name = 'hogshead') b;

I'm using MySQL 5.0, im sure there are functions i can be using but
the join is what im worried about the most,

This to me is a very ugly SQL query and im thinking there's a better
way to do this, does anyone have any ideas on how i can improve this
query?

Consider using a front-end language like Java, C#, Basic, FORTRAN, Perl or whatever to interact with the database. Let the database handle data. Let the logic layer handle logic.

- Lew
.



Relevant Pages

  • SQL that performs division
    ... Teaspoon 1 ... The SQL query I wrote to do the conversion is here: ... -- how many cups in a hogshead? ... This to me is a very ugly SQL query and im thinking there's a better ...
    (comp.lang.java.databases)
  • Re: SQL that performs division
    ... the conversion rate for these measures are all ... The SQL query I wrote to do the conversion is here: ... WHERE m1.measure_name = 'hogshead') b; ... This to me is a very ugly SQL query and im thinking there's a better ...
    (comp.lang.java.databases)
  • Web Developers - Happy Hearts And HDTV! - Lockergnome
    ... Certificate on your MSIIS Web server. ... getting data from a database is only half the problem. ... Zend recently started a series about building rock solid code in PHP. ... which provides bulk database conversion. ...
    (freebsd-questions)
  • Re: Converting database from Access 97 to 2003: problems
    ... Although the owner of the database had all the rights the conversion was not ... placed the Admin user in the Admins group (Admins group has Administrator ...
    (microsoft.public.access.conversion)
  • Re: MDW
    ... using the MDB at the same time. ... When Access 2003 enables the database, ... Multi-User Databases are databases which have an associated WIF (Workgroup ... that could complicate the conversion process. ...
    (microsoft.public.access.gettingstarted)