我有一个有趣的情况,我想用可变值计算DISTINCT行。
想象一下这样的表:
**Customer City status**
Acme Sydney Exist
Bally Sydney new exist
Bally Melbourne new exist
Costco Melbourne Exist
David Sydney null
Ego Japan Exist
Dave Sydney Exist
我正在寻找这个结果: 按状态分组"存在"
**City status**
Sydney 2
Japan 1
Melbourne 1
如何为此结果创建sql查询
谢谢
答案 0 :(得分:0)
car_xy =[(650,700),(568,231),(789,123),(968,369)]
car_id =[284,12,466,89]
#required_details merges the two lists
required_details = list(set(car_xy+car_id))
#now if i do print required_details the ouput will be a list like;
required_details = [284,12,(650,700),89,(568,231),466,(968,369),(789,123)]
#the required details adds the information in list randomly. What if i want the first elements of both the list together, like
required_details = [[284,(650,700)],[12,(568,231),[466,(789,123)],[89,(968,369)]]
这可能有用。
答案 1 :(得分:0)
您正在寻找:
select city, count(*)
from t
where status = 'Exist'
group by city;