比较存在空值而非空值的列值

时间:2017-06-22 02:58:43

标签: sql tsql sql-server-2014

我想比较一个表中的值,其中对于相同的ID,存在null值而不是null值(如果不为null,则我希望最少两个非空值)。如果给定ID的所有值都为null,我希望ID显示为null。 输入

ID     Amount                           
1        Null 
1        Null                            
1        Null                            
1        500                              
1        600 
1        700
2        Null                             
2        Null 
2        Null
2        Null 
2        Null 
3        Null
3        Null
3        300
3        600
3        200

预期输出

ID          Amount
 1           500 (min Not null value)
 2           Null 
 3           200  (Min Not null value)

1 个答案:

答案 0 :(得分:4)

简单的分组就可以解决问题:

url = "https://www.shareinvestor.com/user/login.html"  # This is the main URL login page

login_data = {'name': 'test_user',
              'password': 'test_password',
              'password_m': '5d93ceb70e2bf5daa84ec3d0cd2c731a',
              'remember': True,
              'redirect': 'https://www.shareinvestor.com/sg'}

with requests.Session() as s:
    a = s.get(url).text
    b = bs4.BeautifulSoup(a, 'lxml')
    c = b.findAll('input', type='hidden')  # This is to draw out the token. I tried searching for it in the cookies previously, but failed badly.... 
    for i in c:
        login_data[i['name']] = i['value']

    # I use the this url for the response because as per the `Headers` in the picture above, it says that this is the request URL that the form is submitting to. 
    response = requests.post('https://www.shareinvestor.com/user/do_login.html?use_https=1', data=login_data)
    response = requests.get('https://www.shareinvestor.com/user/edit_profile.html', cookies=response.cookies)

    print(response.text)