3 Replies Latest reply on Aug 5, 2018 8:46 PM by Zelig Chan

    Tableau SQL syntax

    Zelig Chan

      Hi All,

       

      I have written the below mySQL query and it runs smoothly on mySQL workbench,

      but it doesn't seem to work well on Tableau custom SQL. Seems to be something with the function LIMIT?

       

      Can anyone help me? Many Thanks

       

       

      -----------------------------------------------------------------

      SELECT a.id AS id,

        b.qty_change AS inventory_qty_change,

        b.remark AS inventory_remark,

        b.id as inventory_id,

        b.created_at AS inventory_created_at,

        c.created_at AS wac_created_at,

        c.record_amount AS wac_record_amount,

        c.qty AS wac_qty,

        c.record_amount/c.qty as wac

      FROM ztore.product AS a

      LEFT JOIN ztore.product_inventory_log AS b

      ON b.product_id = a.id

      LEFT JOIN ztore.product_wac_log AS c

      ON c.product_id = a.id AND c.id =

      (

      SELECT x.id

      FROM ztore.product_wac_log AS x

      WHERE b.created_at > x.created_at AND b.product_id = x.product_id AND x.remark = "inbound"

      ORDER BY x.created_at DESC

      LIMIT 1

      )

      WHERE a.sn = 1000001;