0

I have a following details in my database table with columns:

currency code
currency rate
currency trade type

Eg, I had the following rows in details (database):

USD  3.33  buy 
USD  3.43  sell
SGD  4.33  buy
SGD  4.43  sell

And then, I want to bring my database tables into PHP/HTML tables as following:

     BUY   SELL
USD  3.33  3.43 
SGD  4.33  4.43

How to use looping to make them be like that?

2
  • You correctly tagged the question with the "pivot" tag -- there's numerous questions & examples. I think you want rent-a-coder -- SO does not exist to write it for you. Commented Aug 2, 2012 at 4:54
  • @OMGPonies - It depends on who sees the question whether it will be written for you. Sometimes I will redo a simple webpage that someone has made with the Google-Copy-Paste-?!? method. (The code is often just plain awful, and the person is asking why something went wrong.) Commented Aug 2, 2012 at 6:28

1 Answer 1

2
SELECT
    t1.code,
    t1.rate as buy,
    t2.rate as sell
FROM currency t1
JOIN currency t2 ON t2.code = t1.code AND t2.trade_type = 'sell'
WHERE t1.trade_type = 'buy'

Assuming this is a currency rate table and there are no duplicates for a any (code,trade_type) pair.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.