products というテーブルがあります。
ProductId| ProductName| ProductType| ProductSize
1 | a | yellow | 12
2 | b | green | 13
3 | c | yellow | 12
4 | d | yellow | 15
________________________________________________
各製品の数を最後に列として取得したい.ここで、productTypeとProductSizeが一致し、例外的な結果になりたい..
ProductID|ProductName|ProductType|ProductSize|TotalProduct
1 | a | yellow | 12 | 2
2 | b | green | 13 | 1
3 | c | yellow | 12 | 2
4 | d | yellow | 15 | 1
_________________________________________________________
私が試したもののいくつかは失敗しましたが、このように見えます。
select ProductId, ProductName, ProductType, ProductSize,
(select count(*) from Product where ProductType=(Products.ProductType) and ProductSize=(products.productSize)) as [TotalProduct] from Products
すべてのレコードに対して totalProduct = 4 が返されます。ありがとう