在python中通过SqlAlchemy Orm转换Sql server原始查询

在python中通过SqlAlchemy Orm转换Sql server原始查询,python,sql-server,sqlalchemy,Python,Sql Server,Sqlalchemy,这是实际查询 select ProductID,[Start_date] from ( select distinct product.productid,price.pricedate from mst_product product inner join mst_product_sp sp on product.productid = sp.productid and product.ManufacturerID = 28003 and product.Subscri

这是实际查询

select ProductID,[Start_date] from (
 select  distinct product.productid,price.pricedate
from mst_product product 
    inner join mst_product_sp sp on product.productid = sp.productid and product.ManufacturerID = 28003 
    and product.SubscriptionStartDate is not null and product.SubscriptionEndDate is not null and sp.observationDate is not null
    inner join TXN_ProductPrice price on product.ProductId = price.ProductId
    and price.PriceDate between cast(getdate()-15 as date) and cast(getdate() as date))aa,
    (select distinct(Start_date) from NSE_NIFTY_WORKINGDAYS where start_date between cast(getdate()-15 as date) and cast(getdate() as date))bb
现在,我被卡在交叉连接部分,直到现在,这是我所做的,这是不工作的

session.query(MstProduct.product_id,NiftyWorkingdays.startDate).join(MstProductSP,MstProduct.product_id==MstProductSP.product_Id).filter(
                    and_(MstProduct.manufacturer_id==28003,MstProduct.subscription_startdate.isnot(None)
                    ,MstProduct.subscription_enddate.isnot(None),
                    MstProductSP.ObservationDate.isnot(None))
                    ).join(TxnProductPrice,MstProduct.product_id==TxnProductPrice.product_ID).filter(and_(TxnProductPrice.price_Date<=start,TxnProductPrice.price_Date>=a)
                    ).join(NiftyWorkingdays.startDate).filter(and_(NiftyWorkingdays.startDate<=start,NiftyWorkingdays.startDate>=a)).distinct()
session.query(MstProduct.product\u id,NiftyWorkingdays.startDate)。加入(MstProductSP,MstProduct.product\u id==MstProductSP.product\u id)。筛选(
和(MstProduct.manufacturer\u id==28003,MstProduct.subscription\u startdate.isnot)(无)
,MstProduct.subscription\u enddate.isnot(无),
MstProductSP.ObservationDate.isnot(无))
).join(TxnProductPrice,MstProduct.product\u id==TxnProductPrice.product\u id).过滤器(和(TxnProductPrice.price\u Date=a)
).join(NiftyWorkingdays.startDate).filter(and(NiftyWorkingdays.startDate=a)).distinct()

得到了答案:)