根据指定的列选择唯一的行

时间:2017-03-27 05:58:44

标签: mysql sql

根据指定列给出包含重复项的表;在这种情况下为personid,如何选择唯一行(不包括列date)?

date       |personid  |amount  |category |location
23/02/2017 |frank     |2344.00 |productA |uk
23/02/2017 |claire    |4443.23 |productB |usa
24/02/2017 |frank     |2344.00 |productA |uk 

选择唯一的行,不包括date列:

personid  |amount  |category |location
frank     |2344.00 |productA |uk
claire    |4443.23 |productB |usa

4 个答案:

答案 0 :(得分:1)

尝试使用GROUP BY

SELECT personid, amount, category, location
FROM yourTable
GROUP BY personid, amount, category, location

SELECT DISTINCT

SELECT DISTINCT personid, amount, category, location
FROM yourTable

您可能会发现DISTINCT经常使用GROUP BY在幕后实施,这很有用。

答案 1 :(得分:1)

使用像这样的

Select distinct personid,amount,category,location from myTable

答案 2 :(得分:1)

您可以使用

select distinct personid,amount,category,location from table

OR

select personid, amount, category, location FROM table group by  personid, amount, category, location

答案 3 :(得分:0)

import UIKit

class ViewController: UIViewController {


    @IBOutlet weak var imageView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let image = UIImage(named: "image.gif")
        let maskingImage = UIImage(named: "mask-image.gif")
        imageView.image = maskImage(image: image!, mask: maskingImage!)
    }

        func maskImage(image:UIImage, mask:(UIImage))->UIImage{

        let imageReference = image.cgImage
        let maskReference = mask.cgImage

        let imageMask = CGImage(maskWidth: maskReference!.width,
                                height: maskReference!.height,
                                bitsPerComponent: maskReference!.bitsPerComponent,
                                bitsPerPixel: maskReference!.bitsPerPixel,
                                bytesPerRow: maskReference!.bytesPerRow,
                                provider: maskReference!.dataProvider!, decode: nil, shouldInterpolate: true)

        let maskedReference = imageReference!.masking(imageMask!)

        let maskedImage = UIImage(cgImage:maskedReference!)

        return maskedImage
    }
}
相关问题