gpt4 book ai didi

php - 如何在html表中显示原始sql查询输出

转载 作者:行者123 更新时间:2023-11-29 11:18:14 25 4
gpt4 key购买 nike

我在 Laravel 中通过原始 SQL 查询生成了下表:

+----------+-------+-------+
| Products | Price | Shop |
+----------+-------+-------+
| Jacket | 300.0 | Shop1 |
| T-Shirt | 300.0 | Shop1 |
| Jacket | 500.0 | Shop2 |
| Shoes | 200.0 | Shop2 |
+----------+-------+-------+

不知道如何循环这些数据,所以我在浏览器中得到这样的结果:

+---------+-------+-------+
| Product | Shop1 | Shop2 |
+---------+-------+-------+
| Jacket | 300.0 | 500.0 |
| T-Shirt | 300.0 | NULL |
| Shoes | NULL | 200.0 |
+---------+-------+-------+

最佳答案

尝试使用

    SELECT a.product, 
(SELECT max(b.price)
FROM yourtable b
WHERE b.product = a.product
AND b.shop = 'Shop1') shop1,
(SELECT max(c.price)
FROM yourtable c
WHERE c.product = a.product
AND b.shop = 'Shop2') shop2
FROM yourtable a group by a.product

关于php - 如何在html表中显示原始sql查询输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39397260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com