Jump to content

[SOLVED] SELECT SUM WHEN id=id


DEVILofDARKNESS

Recommended Posts

I have a query which runs fine and outputs:

 

NATION_NAME      POWER

The Belgian Union    6

The Belgian Union    4

Ireland                  2

 

Now I want to show it DISTINCT, but the powers should be count up so I would get:

 

NAT._NAME    POWER

The Belg. UN.    10

Ireland              2

 

how can I solve this?

 

SELECT nations.nation_name, regions.region_id, (SELECT SUM( weapons.defense) * region_weapons.ammount) As power, (SELECT SUM( power ) WHERE regions.nation_id) As ultimatepower FROM weapons INNER JOIN region_weapons ON region_weapons.weapon_id = weapons.weapon_id INNER JOIN regions ON regions.region_id = region_weapons.region_id INNER JOIN nations ON nations.nation_id = regions.nation_id GROUP BY regions.region_id

Link to comment
https://forums.phpfreaks.com/topic/173213-solved-select-sum-when-idid/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.