i have two tables
one table contain the basic information about the users.
second table contain amount information of users.
i want to sum of amount of users Country vise. i have country id in users table.
but in second table have the user id and amount information.
how i can get the sum of users amount country vise.
if any one have idea then please help me.
14 2086 Purple 404
Recognized Expert Contributor
Hi,
You refer to tables, is it safe to assume there is a database of some sort ? Can you give a little more info on what environment you are running plse
Purple
ak1dnar 1,584
Recognized Expert Top Contributor
i have two tables
one table contain the basic information about the users.
second table contain amount information of users.
i want to sum of amount of users Country vise. i have country id in users table.
but in second table have the user id and amount information.
how i can get the sum of users amount country vise.
if any one have idea then please help me.
if this user id is repeating in both the tables you can make it. userinfo table user_id - userName - user_country_id
1001 - Mike - 5
1002 - Sam - 2
1003 - Jane - 5 amountinfo table amt_id - user_id - amount
1 - 1001 - 100
2 - 1002 - 150
3 - 1003 -250 -
SELECT sum(amount)
-
FROM amountinfo
-
LEFT JOIN userinfo ON amountinfo.user_id = userinfo.user_id
-
WHERE userinfo.user_country_id = '5'
hi
first of all thanks for reply.
now i tell u the structure of data base.
basically i have three tables. 1. country
this table contain the following fields. id_zone, country_name 2. user_info.
this table contain the following fields. id, user_name, id_zone 3. amount.
this table contain the following fields. id, id_user, amount
amount table contain multiple amount of id_user
now i want to get the sum of amount of users country vise .
help me about this problem.
i will be thanks full .
Purple 404
Recognized Expert Contributor
Hi,
this is the SQL based on MSSQL - not sure if it will work on other RDBMS platforms - which is why I asked what the environment was on an previous post.. - SELECT SUM(amount.amount) AS sum_amount, country.country
-
FROM amount INNER JOIN
-
user_info ON amount.id_user = user_info.id INNER JOIN
-
country ON user_info.id_zone = country.id_zone
-
GROUP BY country.country
Regards Purple
Hi,
this is the SQL based on MSSQL - not sure if it will work on other RDBMS platforms - which is why I asked what the environment was on an previous post.. - SELECT SUM(amount.amount) AS sum_amount, country.country
-
FROM amount INNER JOIN
-
user_info ON amount.id_user = user_info.id INNER JOIN
-
country ON user_info.id_zone = country.id_zone
-
GROUP BY country.country
Regards Purple
hi
thanks but it not work properly .
ak1dnar 1,584
Recognized Expert Top Contributor
Post your SQL queries for table structures with some sample values. NOTE : As purple asked what is the SQL environment that you have used for this.
(MySQL,MsSQL,etc)
hi
i use mysql database
and send a sample of query
$sql =mysql_query("SELECT *
FROM $tbl_users u, $tbl_gd_country c
WHERE u.id_zone=c.id_zone
GROUP BY u.id_zone
ORDER BY c.id_zone ");
$j=0;
while($result = mysql_fetch_array($sql)) {
$sql_quran = "SELECT sum(amount)
FROM $tbl_amount m,$tbl_users u
WHERE m.id_user='$result[id]'
AND u.id=m.id_user
";
one thing i tell here i have multiple entry of a same id_user in amount table
hi
i use mysql database
and send a sample of query
$sql =mysql_query("SELECT *
FROM $tbl_users u, $tbl_gd_country c
WHERE u.id_zone=c.id_zone
GROUP BY u.id_zone
ORDER BY c.id_zone ");
$j=0;
while($result = mysql_fetch_array($sql)) {
$sql_quran = "SELECT sum(amount)
FROM $tbl_amount m,$tbl_users u
WHERE m.id_user='$result[id]'
AND u.id=m.id_user
";
one thing i tell here i have multiple entry of a same id_user in amount table
Purple 404
Recognized Expert Contributor Purple 404
Recognized Expert Contributor
Hi,
Having looked at your code can we just pause for a moment and review what it is your are trying to get as a results set - my 'guess' is amount by user by country ?
are you also using the array returned from the first SQL query - is there are reason you have not done this as one SQL query ?
Apologies for the numerous questions but if we clarify at the start we will all save time :)
Purple
ak1dnar 1,584
Recognized Expert Top Contributor
hi
i use mysql database
and send a sample of query
$sql =mysql_query("SELECT *
FROM $tbl_users u, $tbl_gd_country c
WHERE u.id_zone=c.id_zone
GROUP BY u.id_zone
ORDER BY c.id_zone ");
$j=0;
while($result = mysql_fetch_array($sql)) {
$sql_quran = "SELECT sum(amount)
FROM $tbl_amount m,$tbl_users u
WHERE m.id_user='$result[id]'
AND u.id=m.id_user
";
one thing i tell here i have multiple entry of a same id_user in amount table
I requested the SQL query for table structure i think. example: -
--
-
-- Table structure for table `users`
-
--
-
-
CREATE TABLE `users` (
-
`id` int(10) NOT NULL auto_increment,
-
`region` varchar(250) default NULL,
-
`staffid` varchar(250) default NULL,
-
`firstname` varchar(250) default NULL,
-
`surname` varchar(250) default NULL,
-
PRIMARY KEY (`id`)
-
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-
-
--
-
-- Dumping data for table `users`
-
--
-
-
INSERT INTO `users` VALUES (1, 'region1', 'staff1', 'Mike', 'Conors');
-
INSERT INTO `users` VALUES (2, 'region2', 'staff2', 'Akon', 'white');
-
-
If you using phpMyAdmin export them for the current tables.
hi
i cannot understand this
plz help me
Purple 404
Recognized Expert Contributor
Hi,
or you could try replacing both of your queries with : - SELECT SUM(amount.amount) AS amount, user_info.user_name, user_info.id_zone, country.id_zone AS country_zone, country.country
-
FROM user_info INNER JOIN
-
amount ON user_info.id = amount.id_user INNER JOIN
-
country ON user_info.id_zone = country.id_zone
-
GROUP BY user_info.id, user_info.user_name, user_info.id_zone, country.id_zone, country.country
-
ORDER BY user_info.id_zone
If that doesn't do it for you, follow Ajaxrands suggestion and I am sure we can get through this...
Purple
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kostatus |
last post by:
I have a virtual function in a base class, which is then overwritten by a
function of the same name in a publically derived class. When I call the
function using a pointer to the derived class...
|
by: Peter Olcott |
last post by:
www.halting-problem.com
|
by: Ian Stanley |
last post by:
Hi,
Continuing my strcat segmentation fault posting-
I have a problem which occurs when appending two sting literals using
strcat.
I have tried to fix it by writing my own function that does the...
|
by: Jon Davis |
last post by:
If I have a class with a virtual method, and a child class that overrides
the virtual method, and then I create an instance of the child class AS A
base class...
BaseClass bc = new ChildClass();...
|
by: Ammar |
last post by:
Dear All,
I'm facing a small problem.
I have a portal web site, that contains articles, for each article, the end
user can send a comment about the article.
The problem is:
I the comment length...
| |
by: Dany |
last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was...
|
by: =?Utf-8?B?am8uZWw=?= |
last post by:
Hello All,
I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM).
On some
devices the IM will not start. The IM appears in the IM-List but when it is
selected from the...
|
by: sherifbk |
last post by:
Problem description
==============
- I have 4 clients and 1 server (SQL server)
- 3 clients are Monitoring console 1 client is operation console
- Monitoring console collects some data from...
|
by: AceKnocks |
last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |