How to write such MYSQL statements?

Source: Internet
Author: User
Search for the sum of the points. The condition is that from the data table whose name is equal to the param value, the uid with id equal to the param_id value is equal to 3 SELECTsum (point) FROMfirWHERE (SELECTuidFROMfir. paramWHEREidfir. param_id) & #039; 3 & #039; The above statement is fir. param is actually a database fi... search for the sum of points. The condition is that, from the data table whose name is equal to the param value, the uid with id equal to the param_id value is equal to 3.

SELECT sum(point) FROM fir WHERE (SELECT uid FROM fir.param WHERE id = fir.param_id) = '3'

The above statement, fir. param, is actually the value of a field in the database fir. It stores the name of the second or third database (such as the sec), but an error is returned. What should I do?

firparam  |  param_id   |   pointsec    |  11         |   10third  |  23         |   -20sec    |   id     |   uid11     |   3third  |   id     |   uid23     |   3

Reply content:

Search for the sum of points. The condition is that, from the data table whose name is equal to the param value, the uid with id equal to the param_id value is equal to 3.

SELECT sum(point) FROM fir WHERE (SELECT uid FROM fir.param WHERE id = fir.param_id) = '3'

The above statement, fir. param, is actually the value of a field in the database fir. It stores the name of the second or third database (such as the sec), but an error is returned. What should I do?

firparam  |  param_id   |   pointsec    |  11         |   10third  |  23         |   -20sec    |   id     |   uid11     |   3third  |   id     |   uid23     |   3

The syntax of this statement is incorrect. From fir. param... but in fact, fir is the table name And param is the column name?
We recommend that you do not write statements. Write out your requirements, and write out the expected execution results.

The author actually saves the table name as a field, finds the table name based on the condition, and finally obtains the data. This operation cannot be completed in an SQL statement. You can try the view or stored procedure.

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.