日期:2014-05-17 浏览次数:20537 次
SELECT Name,
(SELECT COUNT(*) FROM SalesOrderDetail S
WHERE S.ProductID=P.ProductID) AS SalesAmount
FROM Product P
for( int P_Name = 0; P_Name < N; P_Name++)
for( int S_ID = 0; S_ID < M; S_ID++ )
if ( P_ID == S_ID )
printf( '%s', Name );
select p.Name,
isnull(s.SalesAmount,0) 'SalesAmount'
from Product p
left join
(select ProductID,
count(1) 'SalesAmount'
from SalesOrderDetail
group by ProductID
) s on p.ProductID=s.ProductID
SELECT ProductName,
(SELECT COUNT(*) FROM SalesOrderDetail S
WHERE S.ProductID=P.ProductID) AS SalesAmount
FROM Product P
select P.ProductName,S.num from
(
SELECT ProductID,COUNT(*) as num FROM SalesOrderDetail
group by ProductID
)S inner join Product P
on S.ProductID=P.ProductID