johnleaf Posted January 6, 2011 Share Posted January 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/223567-green-wet-behind-the-ears-new-to-web-programming-needs-help/ Share on other sites More sharing options...
mikosiko Posted January 6, 2011 Share Posted January 6, 2011 well... Merlin the magician with his lustrous Cristal ball doesn't login here to often ... so post your table, the code that you have already and your specific questions and someone sure will help welcome Quote Link to comment https://forums.phpfreaks.com/topic/223567-green-wet-behind-the-ears-new-to-web-programming-needs-help/#findComment-1155661 Share on other sites More sharing options...
johnleaf Posted January 6, 2011 Author Share Posted January 6, 2011 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 | +----------------------------------+-----------+ Quote Link to comment https://forums.phpfreaks.com/topic/223567-green-wet-behind-the-ears-new-to-web-programming-needs-help/#findComment-1155834 Share on other sites More sharing options...
BLaZuRE Posted January 7, 2011 Share Posted January 7, 2011 What is your specific question? Albania doesn't appear on your second table so I don't know what you wanted. Subtracting in a query is simple. If you want fieldA - fieldB, you can do SELECT (fieldA-fieldB) FROM tableC Quote Link to comment https://forums.phpfreaks.com/topic/223567-green-wet-behind-the-ears-new-to-web-programming-needs-help/#findComment-1156400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.