How can I query the data in the database with one condition, and then count the total amount of data stored in another field.

Source: Internet
Author: User
How can I query the data in the database with one condition, and then count the total amount of data stored in another field. there is a requirement that I first display Runan building and then count how many computers Runan building has received.


Reply to discussion (solution)

It is enough to accumulate data during reading.

It is enough to accumulate data during reading.
Please let me know more... thank you!

$ SQL = "select sum (number) as total where area = 'runan mansion '"; $ result = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ result )) {$ total = $ row ['total'];} echo "Runan building :". $ total. "platform ";

How can this problem be solved?
Array
Array (
Array ('A', 1 ),
Array ('A', 2 ),
Array ('B', 1 ),
Array ('C', 1 ),
Array ('A', 1 ),
)
We need to sum the second column by the first column. what do you do?

How can this problem be solved?
Array
Array (
Array ('A', 1 ),
Array ('A', 2 ),
Array ('B', 1 ),
Array ('C', 1 ),
Array ('A', 1 ),
)
We need to sum the second column by the first column. what do you do?

$ Query = "select * from tbl_apply_register where area = 'runan mansion '"; $ SQL = mysql_query ($ query); while ($ row = mysql_fetch_array ($ SQL )) {$ tmp [] = $ row [number];} echo array_sum ($ tmp );

$ SQL = "select sum (number) as total where area = 'runan mansion '"; $ result = mysql_query ($ SQL); while ($ row = mysql_fetch_array ($ result )) {$ total = $ row ['total'];} echo "Runan building :". $ total. "platform ";

$ Query = "select * from tbl_apply_register where area = 'runan mansion '"; $ SQL = mysql_query ($ query); while ($ row = mysql_fetch_array ($ SQL )) {$ tmp [] = $ row [number];} echo array_sum ($ tmp );

$ SQL = "select sum (number) as total where area = 'runan mansion '";
Sorry, I have an extra where
Your method is essentially the same as mine, but I calculate it directly in the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.