#计算7天内销量,并把每件商品的不同尺码库存分别显示day7=today-datetime.timedelta(days=7)logs7=db.session.execute("SELECTproduct_name,goods_id,sum(number)assellsumFROMsdb_sell_logswherecreatetime>:createtimegroupbygoods_idorderbysum(number)desclimit0,20",{"createtime":datetime_timestamp(day7.strftime("%Y-%m-%d00:00:00"))}).fetchall()goods_store7={}foriteminlogs7:store=db.session.execute("SELECTpdt_desc,storefromsdb_productswheregoods_id=:goods_id",{"goods_id":item.goods_id}).fetchall()item_store=[]forstore_iteminstore:item_store.append([store_item.pdt_desc,store_item.store])goods_store7[item.goods_id]=item_store这段代码要怎么优化请问?感觉这个foriteminlogs7:的循环里要处理N次的select效率好低下。
繁花不似锦
相关分类