Mysql Query statement problems

Source: Internet
Author: User
: Question: How can I use an SQL statement to query and display the result in format 2? (Ps: There are still many orderids, not just 6). Is it true that SQL statements cannot be processed and can only be processed through php? I have been thinking for a long time.

:

:

Q: How can I use an SQL statement to query and display the result in format 2? (Ps: There are still many orderids, not just 6). Is it true that SQL statements cannot be processed and can only be processed through php? I have been thinking for a long time.

Reply content:

:

:

Q: How can I use an SQL statement to query and display the result in format 2? (Ps: There are still many orderids, not just 6). Is it true that SQL statements cannot be processed and can only be processed through php? I have been thinking for a long time.

Can the following SQL statements meet your needs?

Select orderid, sum (CASE cosetypeid WHEN 4 THEN amount END) AS 'amount value WHEN cosetypeid is 4 ', sum (CASE cosetypeid WHEN 5 THEN amount END) AS 'amount value WHEN cosetypeid is 5 ', sum (CASE cosetypeid WHEN 7 THEN amount END) AS 'amount value WHEN cosetypeid is 7' from x group by orderid

Of course, it depends on the back-end code. The database only processes data writing and reading, and the logic code still needs to be performed by the backend, that is, PHP. there is no need to force MYSQL to do this.

You can give it a try upstairs.

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.