Home > database >  SQL nesting problems
SQL nesting problems

Time:09-24

SELECT
A.F SkuNumber FSkuNumber,
The SUM (a.f qty) fqty,
E.f invqty finvqty,

E.f invqty - SUM (a.f qty) fnowlowqty,
MAX (e.f invqty - SUM (a.f qty)) maxqty,
E.F cansellqty Fcansellqty

The from sell_systradeitem a
LEFT the JOIN sell_systrade b on a.f id=b. id
LEFT the JOIN pub_trade_taobaoitem on c=a.f oid c.F oid
LEFT the JOIN qtyinfo e on a.F SkuID=e.F SkuID and a.F StockID=e.F StockID

I'm going to ask the maximum should be how to write, please

CodePudding user response:

Put no aggregate all columns in the back of the group by

CodePudding user response:

MAX (e.f invqty - SUM (a.f qty)) maxqty,


E.f invqty, this column is a non aggregate column, he wants to do with a SUM function operation is not enough,

CodePudding user response:

 SELECT 
A.F SkuNumber FSkuNumber,
A.f qty fqty,
E.f invqty finvqty,

E.f invqty - a.f qty fnowlowqty,
MAX (e.f invqty - a.f qty) maxqty,
E.F cansellqty Fcansellqty

The from
SELECT (
S. SkuNumber,
S. id,
S. oid,
S. skuid,
S. stockid,
The SUM (s. qty) AS fqty
The FROM
Sell_systradeitem s
GROUP BY
S. SkuNumber,
S. id,
S. oid,
S. skuid,
S. stockid
) a
LEFT the JOIN sell_systrade b on a.f id=b. id
LEFT the JOIN pub_trade_taobaoitem on c=a.f oid c.F oid
LEFT the JOIN qtyinfo e on a.F SkuID=e.F SkuID and a.F StockID=e.F StockID
  • Related