美国,25,100,25%......英国,28,100,28%......等......
SELECT Country, COUNT(Country) AS number, (SELECT COUNT(Country)
FROM[Customers]) AS total FROM [Customers]
GROUP BY Country ORDER BY number DESC
我尝试了number/total AS percent
但是没有用。显然我做错了。
我希望能够过滤某些百分比超过20%的国家/地区。
谢谢!
答案 0 :(得分:1)
使用派生表,它是带别名的子查询。
//
// DemoTransitionAnimationViewController.swift
// LoginModule
//
// Created by Shubham Ojha on 8/15/17.
// Copyright © 2017 BBI. All rights reserved.
//
import UIKit
class DemoTransitionAnimationViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(self.navigationController ?? "Not exist")
if self.navigationController != nil{
self.navigationController?.delegate = NavigationControllerDelegate()
// In the above statement if I am setting the delegate as self instead of
//NavigationControllerDelegate() and conforming the methods of navigation
//controller delegate protocol. It works perfectly.
}
else{
print("navigation controller does not exist")
}
}
}
答案 1 :(得分:0)
你应该手动完成:
SELECT Country, COUNT(Country)*100/ (SELECT COUNT(Country) FROM[Customers]) AS total FROM [Customers] where total >20
答案 2 :(得分:0)
SQL下面会对你有帮助。
SELECT Country, COUNT(Country) AS number, (SELECT COUNT(Country) FROM[Customers]) AS total, ROUND(COUNT(Country) * 100.0 / (SELECT COUNT(Country) FROM[Customers]), 1) FROM [Customers]