MySQL - 最便宜的订单

时间:2017-12-04 20:06:59

标签: mysql

已移除已移除的移除

3 个答案:

答案 0 :(得分:1)

我会使用相关查询。有很多方法可以做到这一点:作为SELECT子句中的子查询,或作为WHERE子句中的子查询。

在这种情况下,我实现了第二个选项:

SELECT
    person_name,    
    order_name
FROM Persons 
    INNER JOIN Orders ON Persons.person_id = Orders.person_id
WHERE 
(
    cost = (
        SELECT MIN(cost)
        FROM Orders
        WHERE 
            (Orders.person_id = Persons.person_id)
    )
)

答案 1 :(得分:0)

删除order=并添加AS order_name

这样的事情:

SELECT p.person_name
     , ( SELECT o.order_name
           FROM orders o 
          WHERE o.person_id = p.person_id
          ORDER BY o.cost ASC
          LIMIT 1
       ) AS order_name
  FROM person p
 ORDER BY p.person_name

答案 2 :(得分:0)

MIN

您只需加入2个表并使用worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream hello-akka{ server localhost:9000; } server { listen 80; location / { root /usr/share/nginx/html; index index.html index.htm; } location /akka { proxy_pass http://hello-akka; } location /assets { root /var/www; } } } 即可完成此操作。