Skip to content

Instantly share code, notes, and snippets.

@mis101247
Last active June 10, 2020 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mis101247/c76726804ae061ff6eddd7c72217f175 to your computer and use it in GitHub Desktop.
Save mis101247/c76726804ae061ff6eddd7c72217f175 to your computer and use it in GitHub Desktop.
SQL 實用筆記
# 當你要算出一張表的總數和表內的特定總數
# 範例: 找出姓柯的總人數和其中使用iphone的人數
# 醬子就只會刷一次表
SELECT COUNT(*) as total, COUNT(IF (phone = 'iphone' , 1 ,null)) as iphoneTotal FROM
(SELECT * FROM `users` where `last_name` = '柯') AS usersTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment