我在使用sql时遇到更多问题,每天都有其他毕业生获得一张纸,他们必须解决如何解决10个查询问题。
我可以在硬编码值时获取下面的代码来返回数据,但我需要做的是将name和item的值传递给子查询,我不能使用函数或视图并显示每个客户的结果。< / p>
SELECT
c.Name AS 'A',
c.Address AS 'B',
sales2.MinPrice AS 'C',
MAX(sales.TotalItemsSold) AS 'D'
FROM
ABC c,
(SELECT SUM(i.Qty) AS TotalItemsSold
FROM DEF i
INNER JOIN GHI o ON i.Orderno = o.OrderNo
WHERE o.Cust = 'name') sales,
(SELECT (Min(s.Price) * i.Qty) AS MinPrice
FROM ABC c
INNER JOIN GHI o ON c.Name = o.Cust
INNER JOIN DEF i ON i.Orderno = o.OrderNo
INNER JOIN JKL s ON i.Item = s.Item
WHERE i.Item = 'item' AND o.Cust = 'name'
GROUP BY i.Qty) sales2
GROUP BY
c.Name, c.Address, Sales2.MinPrice