또 다른 SQL 문제로 현재 문제가 있습니다. 이 사실을 제대로 알기 위해서는 약간의 시간을 할애해야합니다.고유 한 외래 키가있는 쿼리에서 행을 선택 하시겠습니까?
어쨌든 누군가 다른 사람이 쓴이 쿼리는 몇 가지 테이블에서 값을 가져옵니다.
이제 두 개 이상의 항목이 동일한 ProductID를 가질 수 있습니다. 따라서 동일한 ProductID를 가진 모든 항목이 3 개 반환 될 수 있지만 설명이 다릅니다.
ProductID 당 하나의 항목 만 선택하고 싶습니다. 나는 DISTINCT를 사용하여 그룹화했지만 많은 오류가 발생합니다. 또한 이것은 ACCESS 데이터베이스를위한 것입니다.
내 그룹화를 엉망으로 만드는 선택 쿼리에 사용 된 논리 때문이라고 생각합니다. 여기
쿼리입니다 (나는 그것을 좀 더 나은 서식을 시도하는 온라인 도구 있지만 여전히 큰 혼란을 사용했다)SELECT tblproducts.productid,
tblproducts.categorycode,
tblproducts.scaletitle,
tblproducts.picture,
tblitems.cost,
tblitems.modelnumber,
tblitems.itemid,
Iif([tblitems]![tradeapproved],Iif(([tblitems]![markup]/100) <> 0,(Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost])) * ([tblitems]![markup]/100),
0) + Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost]) + [tblitems]![tradeapprovedcost] + [tblitems]![shippingcost],
Iif(([tblitems]![markup]/100) <> 0,(Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost])) * ([tblitems]![markup]/100),
0) + Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost]) + [tblitems]![shippingcost]) AS price
FROM (tblitems
INNER JOIN tblproducts
ON tblitems.productid = tblproducts.productid)
INNER JOIN tblsuppliers
ON tblproducts.supplierid = tblsuppliers.supplierid
WHERE tblproducts.categorycode = 'BS'
AND tblitems.tradeapproved = 0
AND tblsuppliers.active = on
AND tblitems.isaccessory = false
ORDER BY Iif([tblitems]![tradeapproved],Iif(([tblitems]![markup]/100) <> 0,(Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost])) * ([tblitems]![markup]/100),
0) + Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost]) + [tblitems]![tradeapprovedcost] + [tblitems]![shippingcost],
Iif(([tblitems]![markup]/100) <> 0,(Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost])) * ([tblitems]![markup]/100),
0) + Iif(([tblitems]![supplierdiscount]/100) <> 0,
[tblitems]![cost] - ([tblitems]![cost] * ([tblitems]![supplierdiscount]/100)),
[tblitems]![cost]) + [tblitems]![shippingcost])
는 사람이 대한 빠른 수정을 게시 할 수 있습니까? 감사합니다
코드는 피 묻은 미로입니다. 나는 형식화를 시도했지만 저녁까지 인내심을 잃어 버렸다. 그것을 읽을 수있는 형식으로 포맷 해 주시겠습니까? 아니면 단순화 된 버전을 올리시겠습니까? – Eric
@ Eric, 여기 같은 이야기가 ... 포맷을 시도했지만 포기했습니다. –
좋아, 나는 그것이 거대하다는 것을 안다, 게다가 내가 준 코드는 이것을 12 번처럼 가지고있다! 함께 일하는 것은 악몽입니다. 나는 편집을하고 더 나은 것을 게시 할 것입니다. – ddd