Home > Backend Development > PHP Tutorial > mysql query statement problem

mysql query statement problem

WBOY
Release: 2023-03-02 11:34:02
Original
1090 people have browsed it

Picture 1:mysql query statement problem

Picture 2:mysql query statement problem

Question: How to query Figure 1 through SQL statements and display the format as shown in Figure 2? (PS: There are many more orderids, not just 6). Is it because the SQL statement cannot be processed and can only be processed through PHP? Please give me some advice, I've been thinking about it for a long time

Reply content:

Picture 1:mysql query statement problem

Picture 2:mysql query statement problem

Question: How to query Figure 1 through SQL statements and display the format as shown in Figure 2? (PS: There are many more orderids, not just 6). Is it because the SQL statement cannot be processed and can only be processed through PHP? Please give me some advice, I've been thinking about it for a long time

Try the following sql statement to see if it meets your needs

<code>select orderid,sum(CASE cosetypeid WHEN 4 THEN amount END) AS 'cosetypeid为4时的amount值',
sum(CASE cosetypeid WHEN 5 THEN amount END) AS 'cosetypeid为5时的amount值',
sum(CASE cosetypeid WHEN 7 THEN amount END) AS 'cosetypeid为7时的amount值'
from X  GROUP BY orderid </code>
Copy after login

Of course it depends on the back-end code to write. The database only handles the writing and reading of data. The logic code still needs to be done by the backend, that is, PHP. There is no need to force MYSQL to do this work.

You can try it upstairs

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template