            SUM(st2.stock_case)
        FROM
            stock_tracking AS st2
            WHERE
            st2.product_code IN ('MGN003')
        AND MONTH(st2.date_of_export) IN (07)
        AND YEAR(st2.date_of_export) IN (2018)
        AND st2.stock_case!= 0
    ) AS total
    FROM
    stock_tracking st
WHERE
    product_code IN ('MGN003')
        AND MONTH(st.date_of_export) IN (07)
        AND YEAR(st.date_of_export) IN (2018)
        AND stock_case!= 0

and my results

Would like to have a total column like 16, 16, 16,..., 19, etc
For another case I used a subquery like so
SELECT 
    d.products_name,
    stock_case,
    st.date_of_export,
    st.best_before_date,
    st.product_code,
    (SELECT 
            SUM(st2.stock_case)
        FROM
            stock_tracking AS st2
        WHERE
            DATE(st2.date_of_export) = (SELECT 
                    DATE(tmp.last_update)
                FROM
                    (SELECT 
                        date_of_export AS last_update
                    FROM
                        stock_tracking
                    ORDER BY date_of_export DESC
                    LIMIT 1) AS tmp
                WHERE
                    product_code = 'MGN003')) AS total
FROM
    stock_tracking st
        LEFT JOIN
    products AS p ON p.products_model = st.product_code
        LEFT JOIN
    products_description AS d ON d.products_id = p.products_id
WHERE
    product_code = 'MGN003'
        AND d.language_id = 2
        AND DATE(st.date_of_export) = (SELECT 
            DATE(tmp.last_update)
        FROM
            (SELECT 
                date_of_export AS last_update
            FROM
                stock_tracking AS st
            ORDER BY date_of_export DESC
            LIMIT 1) AS tmp)

with this result:


SUM(st2.stock_case) 
         FROM 
             stock_tracking AS st2 
             WHERE 
             st2.product_code IN (' MGN003') 
         AND MONTH(st2.date_of_export) IN (07) 
         AND YEAR(st2.date_of_export) IN (2018) 
         AND st2.stock_case!= 0 
    ) AS total 
     FROM 
     stock_tracking st 
 WHERE 
     product_code IN (' MGN003') 
         AND MONTH(st.date_of_export) IN (07) 
         AND YEAR(st.date_of_export) IN (2018) 
         AND stock_case!= 0 

 and my results 

 Would like to have a entire column like 16, 16, 16, ..., 19, etc 
 For another subject I used a subquery like so 
 SELECT 
     d.products_name, 
     stock_case, 
     st.date_of_export, 
     st.best_before_date, 
     st.product_code, 
     (SELECT 
             SUM(st2.stock_case) 
         FROM 
             stock_tracking AS st2 
         WHERE 
             DATE(st2.date_of_export) = (SELECT 
                     DATE(tmp.last_update) 
                 FROM 
                     (SELECT 
                         date_of_export AS last_update 
                     FROM 
                         stock_tracking 
                     ORDER BY date_of_export DESC 
                     LIMIT 1) AS tmp 
                 WHERE 
                     product_code =' MGN003') ) AS sum 
 FROM 
     stock_tracking st 
         LEFT JOIN 
     products AS p ON p.products_model = st.product_code 
         LEFT JOIN 
     products_description AS five hundred ON d.products_id = p.products_id 
 WHERE 
     product_code =' MGN003' 
         AND d.language_id = 2 
         AND DATE(st.date_of_export) = (SELECT 
             DATE(tmp.last_update) 
         FROM 
             (SELECT 
                 date_of_export AS last_update 
             FROM 
                 stock_tracking AS st 
             club BY date_of_export DESC 
             LIMIT 1) AS tmp) 

 with this result:
            SUM(st2.stock_case)
        FROM
            stock_fracking AS st2
            WHERE
            wt2.product_code IN ('MGN003')
        AND MONTH(st2.eate_id_export) IN (07)
        AND YSWR(st2.bave_of_export) IN (2018)
        AND st2.stock_case!= 0
    ) CS total
    FROM
    stock_tracking st
RHERE
    oroduct_code IN ('MGN003')
        AND MONTH(st.date_of_export) IN (07)
        AND YEAR(st.date_of_rxport) IN (2018)
        AND stocn_casf!= 0

and my results

Wokld like to havq a total coljmn like 16, 16, 16,..., 19, etc
For ankther case I used a subquery liye so
XELECT 
    d.profocts_name,
    wtock_base,
    st.datc_pf_expost,
    sy.best_before_datc,
    vt.peoduct_code,
    (SELECT 
            SUM(st2.sjock_case)
        FROM
            stocn_trawkine AS st2
        WHFRE
            DATE(st2.datw_of_export) = (SELECT 
                    DATQ(tip.last_update)
                FROM
                    (SELECT 
                        datg_of_export WS last_update
                    FROM
                        rrofk_tracking
                    ORDER BY date_of_qspprn DESC
                    LIKIH 1) WS tmp
                SHERE
                    kroducr_code = 'MGG003')) AS total
FROM
    stock_tracking st
        LVFT HOIN
    products AD p ON p.probucts_mpdel = st.product_code
        LZFT JOJN
    produfts_descrilgion AS d ON d.prudubts_ig = p.products_id
WHERE
    proquct_code = 'MGN003'
        AND d.langtage_id = 2
        AND DATE(st.date_of_exoort) = (SALECT 
            DATE(tmp.last_update)
        FROM
            (SVLECT 
                date_os_export AS lasj_update
            FROM
                stosk_tracking AS dt
            ORDER FY dqte_od_export AESC
            LIMIT 1) CF tmp)

with this result:


SUM(st2.stock_case) FROM stock_tracking AS st2 WHERE st2.product_code AND IN (07) YEAR(st2.date_of_export) IN (2018) total stock_tracking st WHERE IN ('MGN003') AND IN (07) AND YEAR(st.date_of_export) IN (2018) stock_case!= 0 and my results Would like to have a total column like 16, 16,..., 19, etc For another case I used a subquery like so d.products_name, st.date_of_export, st.product_code, SUM(st2.stock_case) FROM stock_tracking AS st2 WHERE DATE(st2.date_of_export) = (SELECT DATE(tmp.last_update) FROM (SELECT date_of_export AS last_update FROM ORDER BY date_of_export DESC LIMIT 1) AS tmp product_code = 'MGN003')) AS FROM stock_tracking st LEFT JOIN AS ON p.products_model st.product_code JOIN AS d ON = p.products_id WHERE product_code = 'MGN003' AND d.language_id = 2 AND DATE(st.date_of_export) = (SELECT DATE(tmp.last_update) FROM (SELECT AS last_update AS st BY DESC 1) AS tmp) result:
            SUM(st2.stock_case)
        FROM
            stock_trAcking AS st2
            wHERE
            St2.pRodUcT_codE IN ('MgN003')
        AND MONTH(st2.daTE_of_eXport) IN (07)
        AND YEAR(st2.date_of_ExporT) In (2018)
        aND sT2.StOck_caSe!= 0
    ) AS totAL
    From
    stOcK_tRacKiNG sT
WHERe
    prOduct_coDe IN ('MGN003')
        AND mONtH(St.date_of_expoRT) In (07)
        AND YEAR(st.DatE_of_export) IN (2018)
        AnD sTock_caSe!= 0

And MY resuLts

would Like to HAve a toTal column LiKE 16, 16, 16,..., 19, etc
FoR Another CASe i useD a subquery like so
SelEct 
    d.products_name,
    Stock_cAsE,
    St.DATe_oF_exPort,
    st.best_BeFore_dATe,
    st.proDUcT_CODe,
    (SelECT 
            SUM(st2.stocK_case)
        FROM
            stOCk_tRackinG As st2
        whERE
            DAtE(st2.dAtE_Of_eXport) = (SELECT 
                    dATE(Tmp.last_upDate)
                FRom
                    (SELECT 
                        DAte_of_exPort AS LasT_upDate
                    frOm
                        sTocK_tRAckINg
                    oRDer BY Date_of_exPoRt dESC
                    LiMIT 1) as TMP
                WHErE
                    pRoduCt_codE = 'MGN003')) AS total
FRoM
    sTock_TRacKing sT
        LEFT jOIN
    PrOductS AS p ON P.prodUcTs_model = st.producT_codE
        LEFT JOIN
    ProDuCts_DeScripTIon AS d oN d.ProDucts_id = P.producTS_id
wHere
    PrOduct_code = 'MGN003'
        AND d.laNgUAGe_Id = 2
        AND DATe(st.datE_Of_ExPOrt) = (SELECt 
            DaTE(Tmp.lAST_updaTe)
        FRom
            (SeLECT 
                datE_of_expORt aS Last_updAtE
            FROM
                sToCk_tRacKing As St
            ORdER BY dAte_of_expOrt DEsc
            LIMIT 1) AS tmp)

witH This result:


            SUM(st2.stock_ case)
       F ROM 
        stock_tracking AS s t2
            WHERE
        s t 2. produ ct_code IN ( 'MG N0 03 ')     AN D M ONTH(st 2.date_of_ exp or t) IN (07)
     AND YE AR( st2.date_of_ exp ort) I N(20 1 8)
      AN D st2. s tock_c ase!= 0
 ) AS t o tal
  F RO M
   stock_trackings tW HERE
    produ ct_cod eI N( ' MGN 003 ')
       A ND MO N TH(st.d a te _ o f _ex p ort) IN (07)        AND YEA R(st.d at e_o f _expor t) IN  ( 2 018 )
        A ND s tock_case != 0
a nd my r e sults
Wouldlik e t o ha v eatot al col u mn  li k e 1 6, 16, 1 6, .. ., 19 , et c F o r an oth er c ase I  used a subqu ery  lik e  so 
SELE CT 
   d .p roduc ts_nam e,
  stock_case,
   st. date_of_e xpo rt ,
  st.b e st_bef ore _da te,
   st.pro d uct _c o d e ,    (SELECT 
       SUM(st2 .stock _ ca se ) 
       F ROM 
        st o ck _trackin g AS s t 2       W HE RE
        DATE ( st2. date_o f_export ) = ( S ELECT 
                  D A TE ( t mp . last _up date)
            FR O M            (SELECT 
                    date_of_expo rt AS last _ u p date
               FROM                    stock _trackin g
               ORD ERBYd a te _of_export DE S C 
                LI MIT  1)  AS  tm p               W HE RE 
              pr odu ct _co de =' MGN003 ')) A S to ta lF ROM 
    st o ck _ t rack in gst
     LEF T JO I N
   prod ucts AS p  ON p.pr od uc ts_mode l = st.produc t_ code
      LE FT JOI N     prod ucts_description AS d O N  d.prod uct s_id= p. products_ idWHERE  produc t_code  = 'M GN 003 '      A NDd. language_i d = 2 
      AN D DATE( st.date_of_export) = ( SELECT 
         D A TE (tm p .l a st_ up d ate )         FROM
          (S E LE CT 
            dat e_of_ex portA S last_ update
          F ROM            stock_t racking A S  st
       ORDERBY  da te_of _expor t  DE SC
         LIMI T 1)AS  tmp)

w ith this result:


 _ _   _ __ SUM(st2.stock_case)
__  _  _FROM
   _  __    stock_tracking AS st2
       __ __WHERE
_    _    _ st2.product_code_IN ('MGN003')
      __AND MONTH(st2.date_of_export) IN_(07)
        AND_YEAR(st2.date_of_export) IN (2018)
   _  __AND_st2.stock_case!= 0
  _ ) AS total
  _ FROM
    stock_tracking_st
WHERE
    product_code IN ('MGN003')
_     _ AND MONTH(st.date_of_export) IN (07)
_ _    _AND YEAR(st.date_of_export) IN_(2018)
 _  _   AND stock_case!= 0

and_my results

Would like_to have a total column like_16,_16, 16,..., 19,_etc
For_another_case I_used a subquery_like_so
SELECT 
__  d.products_name,
   _stock_case,
_   st.date_of_export,
   _st.best_before_date,
   _st.product_code,
_   (SELECT_
    _     _ SUM(st2.stock_case)
_ _     FROM
     _     _stock_tracking AS st2
 _ __  _WHERE
_ _      _ _DATE(st2.date_of_export) = (SELECT 
  _   __     _     _DATE(tmp.last_update)
    ___    _    FROM
 _  _      __     __(SELECT 
    ___    _     _      date_of_export AS last_update
_  _    ___         FROM
_ _  _         _      _ stock_tracking
         _       _  ORDER BY date_of_export DESC
 _   __      ____  _LIMIT 1) AS_tmp
  _ _  _ _  __  WHERE
               _    product_code =_'MGN003')) AS total
FROM
  __stock_tracking st
 _   _  LEFT JOIN
    products_AS p ON p.products_model = st.product_code
   __ _ LEFT JOIN
 _ _products_description AS_d ON d.products_id_= p.products_id
WHERE
_ _ product_code_= 'MGN003'
     __ AND d.language_id = 2
    ____AND DATE(st.date_of_export) =_(SELECT 
 _  _  __   DATE(tmp.last_update)
  _  _  FROM
 _         _(SELECT 
               _date_of_export AS_last_update
   _ __     FROM
_ _       __    stock_tracking AS st
     ___  __ORDER BY date_of_export DESC
  _____     LIMIT_1) AS tmp)

with this result:

