Jump to content

green, wet behind the ears new to web programming needs help


Recommended Posts

Ok so I have a mysql database i am trying to query, and i am doing a search by year and country, and i also have a parameter for the flow of a particular good- either import or export or re-export or re-import.

 

I would like it to sum based on the country and flow export being summed to re-export etc

 

this is probably best solved by proper use of a mysql query- so i suppose that is not php- anyways

 

thank you, this is my first foray into mysql, php etc and i just want to make something mildly useful

 

many thanks

 

john

ok i got it apparently- i still cant figureout how to subtract things from each other in mysql, but... one step at a time

 

select country, SUM(usd) from t01 where comcode=10600 and year=2008 and (flow='Export' OR flow='Re-Export') group by country;

 

so what is happening here is it is printing out the sum in each country of the the rows which are either export or re-export to give the sum total- just what the doctor ordered.

 

just for others reference: here was my table

+---------+------+---------+------------------------------------+-----------+--------+--------+-----------------+----------+

| country | year | comcode | name                              | flow      | usd    | weight | unit            | quantity |

+---------+------+---------+------------------------------------+-----------+--------+--------+-----------------+----------+

| Albania | 2008 |  10600 | Animals, live, except farm animals | Import    | 859291 | 112974 | Number of items |  109907 |

| Albania | 2008 |  10600 | Animals, live, except farm animals | Export    | 767554 |  82215 | Number of items |    78592 |

| Albania | 2008 |  10600 | Animals, live, except farm animals | Re-Export | 603716 |  66820 | Number of items |    63999 |

+---------+------+---------+------------------------------------+-----------+--------+--------+-----------------+----------+

 

amd here was the output I wanted:

 

 

| United Arab Emirates            |  24431653 |

| United Kingdom                  |  29994341 |

| Uruguay                          |    116322 |

| USA                              | 162622419 |

| Venezuela                        |    22212 |

| Viet Nam                        |  4927146 |

| Yemen                            |  1698956 |

| Zambia                          |    108680 |

| Zimbabwe                        |    567810 |

+----------------------------------+-----------+

 

 

 

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.