我生成了下表:
CREATE table user (
user_id INT NOT NULL UNIQUE AUTO_INCREMENT,
user_phone_number INT,
user_city VARCHAR(32) NOT NULL,
PRIMARY KEY (user_id)
);
我被问到以下内容:每个电话号码长度的用户数量(数字位数)
我尝试以下方法:
SELECT LENGTH(user_phone_number)
FROM user
WHERE user is not null
GROUP BY user_phone_number);
但如果有多个用户具有相同的电话号码长度,则会在多行中重复这些用户,而不是提供每长度的总计。请帮忙
答案 0 :(得分:2)
您的SQL有两个问题。最明显的是你遗漏了SELECT
。如果你想数点什么,这很重要。
第二个是GROUP BY
列和SELECT LENGTH(user_phone_number), COUNT(*)
FROM user
WHERE user_phone_number is not null
GROUP BY LENGTH(user_phone_number);
列不匹配。这些应该(几乎总是)相同:
ORDER BY LENGTH(user_phone_number)
最后你可能想要func hideButton() {
UIView.animate(withDuration: 0.2, delay: 0, animations: {
self.MainButton.alpha = 0
}, completion: { finished in
self.MainButton.isHidden = true
})
Timer.scheduledTimer(timeInterval: 1.2, target: self, selector: #selector(GameViewController.ShowButton), userInfo: nil, repeats: false)
}
func showButton() {
self.MainButton.isHidden = false
UIView.animate(withDuration: 0.2, delay: 0, animations: {
self.MainButton.alpha = 1
}, completion: { finished in
})
Timer.scheduledTimer(timeInterval: 1.2, target: self, selector: #selector(GameViewController.HideButton), userInfo: nil, repeats: false)
}
。