dqvj51875 2012-08-02 04:50
浏览 33
已采纳

php + mysql将多行转换为单行中的列

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?

  • 写回答

1条回答 默认 最新

  • drsh30452 2012-08-02 04:56
    关注
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!