措辭不好,因爲我對SQL中的這些操作不太熟悉,假設我有一個表的東西分區,另一個表中有一個名爲address_state的表。我希望能夠加入對ADDRESS_STATE的UCASE等於要麼STATE_ABBREVIATION或STATE_NAMESQL如果連接不匹配然後加入其他東西
EG:
SELECT orders.total_value, territories.territory FROM orders
INNER JOIN tblCanadianTerritories ON
UCASE(orders.technical_address_state) = tblCanadianTerritories.state
OR
tblCanadianTerritories ON
UCASE(orders.technical_address_state) = tblCanadianTerritories.name
WHERE UCASE(orders.technical_address_country) = "CANADA"
編輯:
既然來了兩個可能的解決方案:
SELECT so_order.id, so_order.date_entered, so_order.check_if_new_customer, tblCanadianTerritories.territory, so_order.total_value FROM so_order
INNER JOIN tblCanadianTerritories ON
UCASE(so_order.technical_address_state) = tblCanadianTerritories.state
OR
UCASE(so_order.technical_address_state) = tblCanadianTerritories.name
WHERE UCASE(so_order.technical_address_country) = "CANADA"
ORDER BY so_order.date_entered ASC
OR
SELECT so_order.id, so_order.date_entered, so_order.check_if_new_customer,
tblCanadianTerritories.territory, so_order.total_value FROM so_order
INNER JOIN tblCanadianTerritories ON UCASE(so_order.technical_address_state) =
tblCanadianTerritories.state
WHERE UCASE(so_order.technical_address_country) = "CANADA"
ORDER BY so_order.date_entered ASC
UNION
SELECT so_order.id, so_order.date_entered,so_order.check_if_new_customer,
tblCanadianTerritories.territory, so_order.total_value FROM so_order
INNER JOIN tblCanadianTerritories ON UCASE(so_order.technical_address_state) =
tblCanadianTerritories.name
WHERE UCASE(so_order.technical_address_country) = "CANADA"
ORDER BY so_order.date_entered;
但他們都似乎檢索不同的結果。
你可能有一個錯誤。您正在使用名爲tblCanadianTerritories的表/視圖加入名爲orders的表/視圖。然後你引用一個名爲so_order的表/視圖。訂單和訂單是錯誤的嗎? – 2011-04-12 17:24:44
是的,消毒。 – davidahines 2011-04-12 17:49:46