根据组的条件选择行

时间:2019-06-20 12:18:00

标签: sql sql-server sql-server-2008

我有一张下表,代码值可以是1到10。我只想选择产品,如果它的代码值大于或等于3并且不应该分配代码= 9。

Declare @Product Table(ProductId INT, Code DECIMAL(10,2))

INSERT INTO @Product(ProductId, Code)
Select 844558,3
UNION
Select 844558,3.5
UNION
Select 844558,4
UNION
Select 296013,2
UNION
Select 296013,3
UNION
Select 494948,3.5
UNION
Select 494948,4
UNION
Select 494948,9
UNION
Select 392991,4
UNION
Select 392991,9.5 


SELECT ProductId
FROM @Product
WHERE Code <> 9
GROUP BY ProductId
HAVING MIN(Code) >= 3

结果将只有产品ID 844558和392991。 未选择296013,因为已为其分配了代码2 未选择494948,因为它的代码为9

我在下面的查询中写道,以选择代码大于或等于3的记录。如何排除代码= 9的产品

   public function videoLinkChecker()
    {
        dispatch(new VideoLinkCheckerJob());
        return back()->with('success', 'İşlem başlatıldı tamamlandığında raporu Eğitimler sayfasında görüntüleyebilirsiniz!');
    }

2 个答案:

答案 0 :(得分:1)

增强您的 func getImage(asset: PHAsset) -> UIImage{ let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] fetchOptions.fetchLimit = 1 let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions) if (fetchResult.firstObject != nil) { var lastAsset: PHAsset = fetchResult.lastObject as! PHAsset var image = UIImage() PHImageManager.default().requestImage(for: lastAsset, targetSize: CGSize(width: 100, height: 100) , contentMode: .aspectFill, options: PHImageRequestOptions(), resultHandler: { (result, info) -> Void in image = result! }) return image! //Cannot force unwrap value of non-optional type 'UIImage' } } 子句:

having

答案 1 :(得分:0)

从源头排除产品,这将返回正确的结果集。我使用where子句来完成此操作,该子句选择了代码为9的所有productid值。这样,外部结果集的所有代码都大于3,内部结果集不包含任何代码为9的东西。

{3, 2, 1, 4, 3, 2, 1, 5, 4, 3, 2, 1}

enter image description here