: 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.