Sql server 显示股票详细信息的步骤

Sql server 显示股票详细信息的步骤,sql-server,Sql Server,我正在尝试显示库存详细信息,如MRP、销售率、税额等 我使用了三个网格视图在表单中创建条目。他们是, GV采购 GV产品详细信息-(用于显示产品名称和产品代码) GV库存明细-(用于显示数量、MRP、销售价格等) 我使用SQL查询在网格视图中填充DB记录 我在表格中从产品网格视图中选择产品a,库存网格将显示产品a的相应数据 我的数据库记录 code Name QTY MRP S.Rate aa11 Pro A 5 120.00 130.00 aa11

我正在尝试显示库存详细信息,如MRP、销售率、税额等

我使用了三个网格视图在表单中创建条目。他们是,

  • GV采购
  • GV产品详细信息-(用于显示产品名称和产品代码)
  • GV库存明细-(用于显示数量、MRP、销售价格等)
  • 我使用SQL查询在网格视图中填充DB记录

    我在表格中从产品网格视图中选择产品a,库存网格将显示产品a的相应数据

    我的数据库记录

       code   Name  QTY  MRP    S.Rate
    
       aa11   Pro A  5  120.00  130.00
    
       aa11   Pro A  2  130.00  150.00
    
       aa12   Pro B  4  100.00  110.00
    
       aa13   Pro C  2   50.00   60.00
    
    当我在表格中的GV产品详细信息中选择Pro A时。GV库存详细信息将显示Pro A的数量、MRP、S.费率

    但是我的查询返回的格式如下

        aa11 Pro A  5  120.00  130.00 
    
                    2   130.00  150.00
    
                    4   100.00   110.00
    
                    2     50.00    60.00 
    
    这是我的疑问

       select s.*,iif( d.NewSalePrice is null,s.saleprice1,d.NewSalePrice)as NewSalePrice,Pdate from (select s.*,p.ProductFullName,p.ProductCode from Stock s,Product p where s.productfullcode=p.ProductFullCode) s left join(select Productfullcode,MRP,PUnitPrice,NewSalePrice,Pdate from DailyPricing ) d on s.ProductFullCode=d.ProductFullCode where  s.MRP=d.MRP and s.UnitPrice=d.PUnitPrice and Pdate=(select MAX(Pdate) from DailyPricing where  PUnitPrice=s.UnitPrice and mrp=s.MRP and ProductFullCode=s.ProductFullCode) order by ProductFullCode
    
    如何获取仅与Pro A匹配的库存详细信息

    注意:这些表格格式只是我表格的一个模型

    提前感谢,


    Vinayak vk.:-

    您可以简化查询,并为所需的产品名称添加where子句

    尚未针对模拟数据对其进行测试,但类似于以下SQL:

    select 
        s.*, 
        p.ProductFullName, 
        p.ProductCode,
        coalesce(d.NewSalePrice, s.saleprice1) as SalePrice,
        max(d.Pdate) over (partition by p.ProductFullCode, s.mrp, s.UnitPrice) as MaxPdate
    from Product p 
    join Stock s on s.productfullcode = p.ProductFullCode
    join DailyPricing d on (s.ProductFullCode = d.ProductFullCode and s.MRP = d.MRP and s.UnitPrice = d.PUnitPrice)
    where p.ProductFullName = 'Pro A'
    order by p.ProductFullCode