How to select one field from view in MySQL?


Problem :

How can do the following query in MySQL?

Select SUM(T1.Amount) 
From 
( 
  Select  Distinct PersonName,Amount 
  From  tblusers as T1 
  where city ="xxx"
) 


Solution :

MySQL requires an alias on a derived table or subquery. So you will want to use the following:

Select SUM(t1.Amount) 
From 
( 
  Select Distinct PersonName, Amount 
  From  tblusers
  where city ="xxx"
) t1

You should be able to use the following though depending on your needs:

select personName, sum(Amount)
from tblusers
where city = "xxx"
group by personName

Or if you just want to return the sum, you can use:

select sum(Amount)
from tblusers
where city = "xxx"
group by personName

Mysql Tutorials

Mysql Howto..

How to retrieve an image from mysql using json? [closed]

How to SELECT some data derived from field aliases from other sub-queries

How to use SELECT inside COUNT in MYSQL

How do I use MacPorts to downgrade a dynamic library?

How To Have Multiple Users Accessing Backend & Save Data? [closed]

How to get Items in order with limit in mysql

How to select all articles with a tag and all article's tags with one MySQL query?

How do I replace/update all instances of every string in a column with matching values from another table?

How to handle the following Exception while connecting MySQL with Eclipse?

How do I search part of a column?

using php, how would I convert all rows of a char field such as “11/19/10” to a date field?

How to include a conditional column in a mysql query list?

how to import delimited data into mysql in phpmyadmin

How to use three conditions in WHERE clause of mysql query?

COCOA Objective-c : How can connect to mysql database?

How to change a variable in mysql database on click of a button.

How to get error code returned by query using MySQL in Asp.Net

How to find the SID in mysql to connect to Oracle

How to remove installation of MySQL on Mac OS X

How to Store Check box in MYsql?

How to select from select where group by in MySQL?

How to query MySQL by one of the field's subvalue?

How To Pass Lists of data from C# to MySQL Stored Procedures

JDBC and MySQL, how to persist java.util.Date to a DATETIME column?

How to insert into multiple tables in a single statement in MySQL?

Using Talend to extract HTML Search Pages into .txt files based on input keywords. How can I parse this data End-to-End and write it to MySQL?

How can I delete ghost database field between a special date?

How to “remove duplicates” from a UNION query

How to use MySQL IN with Joomla query - Syntax Issue

meteor reporting of data in existing mysql db. how?