0

我有以下 MySQL 查询

    SELECT REPLACE(book.title,'','') AS "item-name", REPLACE(inventory.sku,'','') AS "sku", REPLACE(IF(inventory.sku IN (SELECT sku FROM qty_skus) , (SELECT qty_skus.quantity FROM qty_skus WHERE qty_skus.sku = inventory.sku LIMIT 1), inventory.quantity),'','') AS "quantity",
REPLACE(LEFT( CONCAT(IF(book_type.book_text IS NOT NULL, CONCAT(book_type.book_text," "), ""), IFNULL(defect.defect,""), " ", IFNULL(inventory.additional_note,""), " ", IFNULL(feature.feature, ""), " ", IFNULL(water.feature, ""), " ", IFNULL(note.note,""),
                            " " ), 2000),'','') AS "item-note",
REPLACE(IF(book.weight>3.99, "1", "2"),'','') AS "will-ship-internationally",     REPLACE(inventory.isbn13,'','') AS "product-id", REPLACE(inventory.ourPrice,'','') AS "price",
REPLACE(IF(book.weight>4.8 AND (inventory.ourPrice - inventory.cost) < 9, "n", "y"),'','') AS "expedited-shipping", REPLACE(book_condition.book_condition,'','') AS "item-condition",
REPLACE(concat(location.location,IF(inventory.fixed="1", " Fixed", "")),'','') AS "Location", REPLACE(book.author,'','') AS "author", REPLACE(book.publisher,'','') AS "publisher",
REPLACE(IF(book_condition.book_condition="New", "11", IF(book_condition.book_condition="Fine", "1", IF(book_condition.book_condition="Very Good", "2", IF(book_condition.book_condition="Good", "3", IF(book_condition.book_condition="Poor", "4", ""))))),'','') AS "condition-id",
        REPLACE(IF(inventory.cost < ((follette_title.usedbuying_price *1.37) OR (amtext.price*1.37) OR (nebraska.price *1.2) OR (tichenor.price *1.25)),IF(feature.book_type_3 = "DMG",inventory.cost,
        IF(book_condition.book_condition="Good",inventory.cost,
        IF(book_condition.book_condition="Poor",inventory.cost,IF(inventory.book_type_id = 3, inventory.cost,
        IF(inventory.commission_level = 1, IF(inventory.cost < ((follette_title.usedbuying_price *1.71) OR (amtext.price*1.71)),(max((follette_title.usedbuying_price*1.71) OR (amtext.price*1.71)),inventory.cost),
        (max((follette_title.usedbuying_price*1.37) OR (amtext.price*1.37) OR (nebraska.price *1.2) OR (tichenor.price *1.25))))))))),inventory.cost),'','') AS "Cost",
                    REPLACE(concat(IFNULL(buyer_type.buyer_type, ""),IFNULL(source.source, ""),IFNULL(inventory.source_date, ""),IFNULL(note.book_type_2, ""),IF(inventory.csmt=1, "CSMT", ""),IF(inventory.cu=1, "CU", ""),IF(inventory.manual=1, "manual", ""),IFNULL(book_type.book_code, ""),IF(water.book_type_4="WATER", "WATER", "")),'','')  AS "Source", REPLACE(book.pub_date,'','') AS "pubdate", REPLACE(book.binding,'','') AS "Media", REPLACE(book_condition.book_condition,'','') AS "condition",
                    REPLACE(IF(location.location="FBA", "AMAZON_NA", ""),'','') AS "fulfillment-center-id"
                    FROM inventory
                    LEFT JOIN defect ON inventory.defect_id = defect.defect_id
                    LEFT JOIN book_condition ON defect.condition_id = book_condition.condition_id
                    LEFT JOIN book_type ON inventory.book_type_id = book_type.book_type_id
                    LEFT JOIN book ON inventory.isbn13 = book.isbn13
                    LEFT JOIN feature ON inventory.feature_id = feature.feature_id
                    LEFT JOIN water on inventory.additional_feature = water.feature_id
                    LEFT JOIN note ON inventory.note_id = note.note_id
                    LEFT JOIN location ON inventory.location_id = location.location_id
                    LEFT JOIN source ON inventory.source_id = source.source_id
                    LEFT JOIN buyer_type ON source.buyer_type_id = buyer_type.buyer_type_id
                    LEFT JOIN follette_title on inventory.isbn13 = follette_title.isbn13
                    LEFT JOIN amtext on inventory.isbn13 = amtext.isbn13
                    LEFT JOIN nebraska on inventory.isbn13 = nebraska.isbn13
                    LEFT JOIN tichenor on inventory.isbn13 = tichenor.isbn13
                    WHERE inventory.upload = 1 AND inventory.ourPrice > 0 AND inventory.location_id > 0 limit 0,20

我收到以下错误,我不知道为什么:

    [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))))),inventory.cost),'','') AS "Cost",                     REPLACE(concat(IFNULL(buyer_type.' at line 12

我查看了错误指示的保留字,但我不认为成本是保留字。帮助!!!!

4

1 回答 1

0

改变这个

    IF(inventory.commission_level = 1, IF(inventory.cost < ((follette_title.usedbuying_price *1.71) OR (amtext.price*1.71)),(max((follette_title.usedbuying_price*1.71) OR (amtext.price*1.71)),inventory.cost),
    (max((follette_title.usedbuying_price*1.37) OR (amtext.price*1.37) OR (nebraska.price *1.2) OR (tichenor.price *1.25))))))))),inventory.cost),'','') AS "Cost",

    IF(inventory.commission_level = 1, IF(inventory.cost < ((follette_title.usedbuying_price *1.71) OR  (amtext.price*1.71)),(max((follette_title.usedbuying_price*1.71) OR (amtext.price*1.71)),inventory.cost),
    (greatest((follette_title.usedbuying_price*1.37) ,(amtext.price*1.37) , (nebraska.price *1.2), (tichenor.price *1.25))))))))),inventory.cost),'','') AS "Cost",

你不能 max(a or b or c)改用greatest(a,b,c)

于 2013-08-28T15:42:01.713 回答