本文介绍了从saleItem和sale表中选择销售日期,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表tblSale和tblSaleLineItems,
我要针对任何商品搜索销售历史记录,并在出售任何特定商品时获取所有日期..

tblSale具有

saleId,
saleDate,
TotalAmmount,

和tblSaleLineItem

id,
来自tblSale
的SaleId作为外键itemId作为来自tblItem
的外键购买数量,
和小计、、、、

我想按itemId搜索所有具有该特定项目的商品,

i have 2 tables tblSale, and tblSaleLineItems,
i want search sale history against any item, get all dates whenever any particular item sold..

tblSale has

saleId,
saleDate,
TotalAmmount,

and tblSaleLineItem

id,
SaleId as foreign key, from tblSale
itemId as foreign key from tblItem
purchasedQuantity,
and subTotal,,,,

i wanna search by itemId , all seles which have that particular item,,,

推荐答案

SELECT S.saleId, S.saleDate, L.itemId, L.purchasedQuantity
FROM tblSale S
JOIN tblSaleLineItem L ON S.saleId = L.saleId
WHEREL. itemId = <selectionCriteria>
ORDER BY S.saleDate


替换< selectionCriteria>与您想要的itemId.

没有有关tblItem的信息,但您可以这样包含


Replace <selectionCriteria> with itemId you want.

There is no information about the tblItem but you could include like so

SELECT S.saleId, S.saleDate, L.itemId, I.itemName, L.purchasedQuantity
FROM tblSale S
JOIN tblSaleLineItem L ON S.saleId = L.saleId
JOIN tblItem I ON L.itemId = I.itemId
WHERE L.itemId = <selectionCriteria>
ORDER BY S.saleDate;


这篇关于从saleItem和sale表中选择销售日期,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:19