0

以下代码片段是多个表的连接。我需要显示从澳大利亚任何人订购的所有订单号、客户名称、产品名称、价格和数量。我得到表格标题但没有行。这有什么问题吗?

SELECT 
      "order".orderno AS ord, 
      customer.cname, 
      product.prodname, 
      customer.country_code, 
      orderdetl.price, 
      orderdetl.qty, 
      country.country_code
    FROM 
      prema01.country, 
      prema01.customer, 
      prema01."order", 
      prema01.orderdetl, 
      prema01.product
    WHERE 
      customer.country_code = 'AUS'

我已经更改了代码,验证了表格中有数据,但它仍然是空白的。我完全被难住了。

SELECT O.ORDERNO, C.CNAME, PN.PRODNAME, ODT.PRICE, ODT.QTY, ODT.QTY * PN.PRODSELL AS TOTAL
FROM prema01.ORDER O, prema01.CUSTOMER C, prema01.ORDERDETL ODT, prema01.PRODUCT PN, prema01.COUNTRY CT
WHERE CT.COUNTRY_NAME = 'Australia' 
AND C.COUNTRY_CODE = CT.COUNTRY_CODE 
AND C.CUSTNO = O.CUSTNO 
AND O.ORDERNO = ODT.ORDERNO 
AND PN.PRODNO = ODT.PRODNO AND O.ORDERNO <= 60
ORDER BY TOTAL DESC;

忘记添加更改。这些表中有数据,我已经物理验证了这一点。

4

2 回答 2

1

For starters, you need some join conditions e.g.

Select
  r.country_code,
  c.cname
From
  prema01.country r
    inner join
  prema01.customer c
    on r.country_code = c.country_code

You need to build up the relationships with the other tables in a similar way.

Also, are you sure your tables have any data in them. Does

Select
  Count(*)
From
  prema01.country

return anything? How about

Select
  Count(*)
From
  prema01.customer
Where
  country_code = 'AUS'

?

于 2012-12-01T01:40:26.663 回答
0

已修复,当我的国家/地区表中有“AUSTRALIA”时,我正在寻找“Australia”。谢谢您的帮助

于 2012-12-01T02:29:38.103 回答