Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT Agent.exid, afName, fshortName,
- cast(AmountM as int) AmountM,
- cast(AmountC as int) AmountC,
- ordersc.ordate
- --cast(Sum(orSumRoubles) as money) Sum
- FROM (SELECT DS_ORDERS.MasterFID, Mfid, orSumRoubles, Sum(Amount) AmountM
- FROM DS_ORDERS, DS_Orders_Items, DS_ITEMS, DS_ObjectsAttributes
- Where orDate >= '2011-01-05 00:00:00.000' and orDate < '2011-10-05 00:00:00.000'
- and DS_ORDERS.orid = DS_Orders_Items.orid
- and DS_ORDERS.MasterFID = DS_Orders_Items.MasterFID
- and DS_ITEMS.iID = DS_Orders_Items.iID
- and DS_ObjectsAttributes.Activeflag = 1
- and DS_ITEMS.Activeflag = 1
- and AttrValueId in (5220009)
- and DS_ObjectsAttributes.Id = DS_ITEMS.iid
- and orType in (1,2) and Condition = 1
- Group by DS_ORDERS.MasterFID, Mfid, orSumRoubles) as OrdersM,
- (SELECT ordate, DS_ORDERS.MasterFID, Mfid, orSumRoubles, Sum(Amount) AmountC
- FROM DS_ORDERS, DS_Orders_Items, DS_ITEMS, DS_ObjectsAttributes
- Where orDate >= '2011-01-05 00:00:00.000' and orDate < '2011-10-05 00:00:00.000'
- and DS_ORDERS.orid = DS_Orders_Items.orid
- and DS_ORDERS.MasterFID = DS_Orders_Items.MasterFID
- and DS_ITEMS.iID = DS_Orders_Items.iID
- and DS_ObjectsAttributes.Activeflag = 1
- and DS_ITEMS.Activeflag = 1
- and AttrValueId in (5220010)
- and DS_ObjectsAttributes.Id = DS_ITEMS.iid
- and orType in (1,2) and Condition = 1
- Group by ordate,DS_ORDERS.MasterFID, Mfid, orSumRoubles) as OrdersC,
- (SELECT fid, exid, fName as afName
- From DS_Faces Where ftype = 4 and fActiveFlag = 1) as Agent,
- (SELECT DS_Faces.fid, fshortName, Mfid, MasterFID
- From DS_Faces, MobFaces
- Where ftype = 7 and MFactiveflag = 1 and fActiveFlag = 1
- and MobFaces.Mfid = DS_Faces.fid) as Faces
- Where OrdersM.MasterFID = Agent.fid
- and OrdersC.MasterFID = Agent.fid
- and OrdersM.Mfid =* Faces.fid
- and OrdersC.Mfid =* Faces.fid
- and Faces.MasterFID = Agent.fid
- --and Agent.exid = 260502
- Group by Agent.exid, afName, fShortName, AmountM, AmountC, ordersc.ordate
- Order by afName, fShortName, ordate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement