Click here to Skip to main content
15,885,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I use same column in database to display two different condition column?

What I have tried:

Hi All

This is my current table:
Database: "QTY"

<pre>Location   Item   Quantity
    A      2.0       4  
    B      2.0       2  
    A      3.0       3  
    C      2.0       5  
    D      3.0       1  
    B      3.0       1


At the present, I can only out individually,
By this sql
Select QTY.Location, QTY.Quantity
FROM QTY
WHERE QTY.item=2.0;


likes:
Table 1:
Location  2.0
   A       4
   B       2
   C       5

Table 2:
Location  3.0
   A       3
   B       1
   D       1


Desire result:
Location   2.0   3.0
    A      4       3  
    B      2       1  
    C      5       0  
    D      0       1  


Could I have any advice from codeprojecter? Thanks..
Posted

1 solution

In other words, you want to "rotate" item rows into columns ;)

Take a look here: MySQL/Pivot table - Wikibooks, open books for an open world[^]
 
Share this answer
 
Comments
wai nok Tang 24-Jun-20 0:22am    
Got it! Thanks.
Maciej Los 24-Jun-20 2:16am    
You're very welcome.
If my answer was helpful, please accept it (green button) - formally to remove your question from unanswered list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900