选择两个值中的最小值

时间:2017-05-24 07:12:58

标签: sql

我有下表:

var request = new Request('https://<dc>.api.mailchimp.com/3.0/lists/[listid]/members', {
                    method: 'POST',
                    mode: 'no-cors',
                    json: {
                        "email_address": "am_it@live.com",
                        "status": "subscribed",
                    },
                    redirect: 'follow',
                    headers: new Headers({
                        'Content-Type': 'application/json',
                        'Authorization': 'Basic apikey'
                    })
                });

// Now use it!
                fetch(request).then(function (data) {
                    console.log(data);
                });

我想在同一个acc_id上只选择id_key最低的值。我怎么能查询这些东西?

id_key acc_id

400001  0009993

500002  0009993

3 个答案:

答案 0 :(得分:1)

使用MIN和GROUP By功能:

 SELECT MIN(id_key) id_key, acc_id
 FROM your_table
 GROUP BY acc_id

答案 1 :(得分:1)

解决方案

 Select acc_id, min(id_key) as id_key from myTable group by acc_id

答案 2 :(得分:0)

试试这个:

SELECT      MIN(id_key) AS id_key,
            acc_id
FROM        Tab
GROUP BY    acc_id

你可以在这里看到 - &gt; http://rextester.com/NWBU37038

希望这有帮助!!!