diff --git a/run_format.py b/run_format.py index eb0e492e63453..eacf01fea13cf 100644 --- a/run_format.py +++ b/run_format.py @@ -4,43 +4,246 @@ import re import black -suffixes = ['md', 'py', 'java', 'c', 'cpp', 'go', 'php', 'cs', 'rs', 'js', 'ts'] +suffixes = ["md", "py", "java", "c", "cpp", "go", "php", "cs", "rs", "js", "ts", "sql"] -code_blocks = ['python', 'java', 'cpp', 'c', 'go', 'ts', 'js', 'php', 'cs', 'rs'] +code_blocks = ["python", "java", "cpp", "c", "go", "ts", "js", "php", "cs", "rs", "sql"] + +functions_to_replace = [ + "ABS", + "ACOS", + "ADDDATE", + "ADDTIME", + "AES_DECRYPT", + "AES_ENCRYPT", + "ASCII", + "ASIN", + "ATAN", + "AVG", + "BIN", + "BIT_COUNT", + "CEIL", + "CHAR", + "CHAR_LENGTH", + "CHARACTER_LENGTH", + "CONCAT", + "CONCAT_WS", + "CONNECTION_ID", + "CONV", + "CONVERT", + "COS", + "COT", + "COUNT", + "CRC32", + "CURDATE", + "CURRENT_DATE", + "CURRENT_TIME", + "CURRENT_TIMESTAMP", + "CURTIME", + "DATABASE", + "DATE", + "DATEDIFF", + "DATE_ADD", + "DATE_FORMAT", + "DATE_SUB", + "DAY", + "DAYNAME", + "DAYOFMONTH", + "DAYOFWEEK", + "DAYOFYEAR", + "DECODE", + "DEFAULT", + "DEGREES", + "DES_DECRYPT", + "DES_ENCRYPT", + "ELT", + "ENCODE", + "ENCRYPT", + "EXP", + "EXPORT_SET", + "EXTRACT", + "FIELD", + "FIND_IN_SET", + "FLOOR", + "FORMAT", + "FOUND_ROWS", + "FROM_DAYS", + "FROM_UNIXTIME", + "GET_FORMAT", + "GET_LOCK", + "GREATEST", + "GROUP_CONCAT", + "HEX", + "HOUR", + "IF", + "IFNULL", + "IN", + "INET_ATON", + "INET_NTOA", + "INSERT", + "INSTR", + "INTERVAL", + "ISNULL", + "LAST_INSERT_ID", + "LCASE", + "LEAST", + "LEFT", + "LENGTH", + "LN", + "LOAD_FILE", + "LOCALTIME", + "LOCALTIMESTAMP", + "LOCATE", + "LOG", + "LOG10", + "LOG2", + "LOWER", + "LPAD", + "LTRIM", + "MAKE_SET", + "MAKEDATE", + "MAKETIME", + "MATCH", + "MAX", + "MD5", + "MICROSECOND", + "MID", + "MIN", + "MINUTE", + "MOD", + "MONTH", + "MONTHNAME", + "NAME_CONST", + "NOW", + "NULLIF", + "OCT", + "OCTET_LENGTH", + "ORD", + "PASSWORD", + "PERIOD_ADD", + "PERIOD_DIFF", + "PI", + "POSITION", + "POW", + "POWER", + "PROCEDURE ANALYSE", + "QUARTER", + "QUOTE", + "RADIANS", + "RAND", + "RELEASE_LOCK", + "REPEAT", + "REPLACE", + "REVERSE", + "RIGHT", + "ROUND", + "ROW_COUNT", + "RPAD", + "RTRIM", + "SCHEMA", + "SEC_TO_TIME", + "SECOND", + "SESSION_USER", + "SHA1", + "SHA", + "SIGN", + "SIN", + "SLEEP", + "SOUNDEX", + "SPACE", + "SQRT", + "STR_TO_DATE", + "STRCMP", + "SUBDATE", + "SUBSTR", + "SUBSTRING", + "SUBSTRING_INDEX", + "SUBTIME", + "SUM", + "SYSDATE", + "SYSTEM_USER", + "TAN", + "TIME", + "TIMEDIFF", + "TIMESTAMP", + "TIMESTAMPADD", + "TIMESTAMPDIFF", + "TIME_FORMAT", + "TIME_TO_SEC", + "TO_DAYS", + "TRIM", + "TRUNCATE", + "UCASE", + "UNCOMPRESS", + "UNCOMPRESSED_LENGTH", + "UNHEX", + "UNIX_TIMESTAMP", + "UPPER", + "USER", + "UTC_DATE", + "UTC_TIME", + "UTC_TIMESTAMP", + "UUID", + "VAR_POP", + "VAR_SAMP", + "VARIANCE", + "VERSION", + "WEEK", + "WEEKDAY", + "WEEKOFYEAR", + "XOR", + "YEAR", + "YEARWEEK", + "ROW_NUMBER", + "RANK", + "DENSE_RANK", + "NTILE", + "LAG", + "LEAD", + "FIRST_VALUE", + "LAST_VALUE", + "CUME_DIST", + "PERCENT_RANK", + "PERCENTILE_CONT", + "PERCENTILE_DISC", +] def add_header(path: str): """Add header to php and go files""" - print(f'[add header] path: {path}') - with open(path, 'r', encoding='utf-8') as f: + print(f"[add header] path: {path}") + with open(path, "r", encoding="utf-8") as f: content = f.read() - if path.endswith('.php'): - content = ' List[str]: paths = [] for root, _, files in os.walk(os.getcwd()): for file in files: - path = root + '/' + file - if 'node_modules' in path or '__pycache__' in path or '.git' in path: + path = root + "/" + file + if "node_modules" in path or "__pycache__" in path or ".git" in path: continue - if any(path.endswith(f'.{suf}') for suf in suffixes): + if any(path.endswith(f".{suf}") for suf in suffixes): paths.append(path) return paths def format_inline_code(path: str): """Format inline code in .md file""" - if not path.endswith('.md'): + if not path.endswith(".md"): return - with open(path, 'r', encoding='utf-8') as f: + with open(path, "r", encoding="utf-8") as f: content = f.read() - root = path[: path.rfind('/')] - print(f'[format inline code] path: {path}') + root = path[: path.rfind("/")] for suf in code_blocks: - res = re.findall(f'```{suf}\n(.*?)```', content, re.S) + res = re.findall(f"```{suf}\n(.*?)```", content, re.S) for block in res or []: # skip empty code block if not block or not block.strip(): continue - if suf in ['c', 'cpp', 'java', 'go']: - file = f'{root}/Solution2.{suf}' - with open(file, 'w', encoding='utf-8') as f: + if suf in ["c", "cpp", "java", "go"]: + file = f"{root}/Solution2.{suf}" + with open(file, "w", encoding="utf-8") as f: f.write(block) - if suf == 'go': + if suf == "go": add_header(file) os.system(f'gofmt -w "{file}"') remove_header(file) else: os.system(f'npx clang-format -i --style=file "{file}"') - with open(file, 'r', encoding='utf-8') as f: + with open(file, "r", encoding="utf-8") as f: new_block = f.read() - if not new_block.endswith('\n'): - new_block += '\n' + if not new_block.endswith("\n"): + new_block += "\n" content = content.replace(block, new_block) os.remove(file) - elif suf == 'python': + elif suf == "python": new_block = black.format_str( block, mode=black.FileMode(string_normalization=False) ) content = content.replace(block, new_block) + elif suf == "sql": + for func in functions_to_replace: + pattern = r"\b{}\s*\(".format(func) + new_block = re.sub( + pattern, f"{func.upper()}(", block, flags=re.IGNORECASE + ) + content = content.replace(block, new_block) + block = new_block - with open(path, 'w', encoding='utf-8') as f: + with open(path, "w", encoding="utf-8") as f: f.write(content) @@ -103,7 +313,7 @@ def run(): for path in paths: add_header(path) - if any(path.endswith(suf) for suf in ['c', 'cpp', 'java']): + if any(path.endswith(suf) for suf in ["c", "cpp", "java"]): # format with clang-format os.system(f'npx clang-format -i --style=file "{path}"') @@ -111,7 +321,7 @@ def run(): os.system('npx prettier --write "**/*.{md,js,ts,php,sql}"') # format with gofmt - os.system('gofmt -w .') + os.system("gofmt -w .") for path in paths: remove_header(path) @@ -119,5 +329,5 @@ def run(): format_inline_code(path) -if __name__ == '__main__': +if __name__ == "__main__": run() diff --git a/solution/0100-0199/0180.Consecutive Numbers/README.md b/solution/0100-0199/0180.Consecutive Numbers/README.md index 5fecb7103e1f0..992f949bca76c 100644 --- a/solution/0100-0199/0180.Consecutive Numbers/README.md +++ b/solution/0100-0199/0180.Consecutive Numbers/README.md @@ -68,16 +68,16 @@ WITH SELECT *, CASE - WHEN (lag(num) OVER (ORDER BY id)) = num THEN 0 + WHEN (LAG(num) OVER (ORDER BY id)) = num THEN 0 ELSE 1 END AS mark FROM Logs ), - p AS (SELECT num, sum(mark) OVER (ORDER BY id) AS gid FROM t) + p AS (SELECT num, SUM(mark) OVER (ORDER BY id) AS gid FROM t) SELECT DISTINCT num AS ConsecutiveNums FROM p GROUP BY gid -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/0100-0199/0180.Consecutive Numbers/README_EN.md b/solution/0100-0199/0180.Consecutive Numbers/README_EN.md index 829805b327701..3e427e9de8a40 100644 --- a/solution/0100-0199/0180.Consecutive Numbers/README_EN.md +++ b/solution/0100-0199/0180.Consecutive Numbers/README_EN.md @@ -64,16 +64,16 @@ WITH SELECT *, CASE - WHEN (lag(num) OVER (ORDER BY id)) = num THEN 0 + WHEN (LAG(num) OVER (ORDER BY id)) = num THEN 0 ELSE 1 END AS mark FROM Logs ), - p AS (SELECT num, sum(mark) OVER (ORDER BY id) AS gid FROM t) + p AS (SELECT num, SUM(mark) OVER (ORDER BY id) AS gid FROM t) SELECT DISTINCT num AS ConsecutiveNums FROM p GROUP BY gid -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/0100-0199/0180.Consecutive Numbers/Solution.sql b/solution/0100-0199/0180.Consecutive Numbers/Solution.sql index c87a60edfe835..bdc0fe39980bb 100644 --- a/solution/0100-0199/0180.Consecutive Numbers/Solution.sql +++ b/solution/0100-0199/0180.Consecutive Numbers/Solution.sql @@ -4,13 +4,13 @@ WITH SELECT *, CASE - WHEN (lag(num) OVER (ORDER BY id)) = num THEN 0 + WHEN (LAG(num) OVER (ORDER BY id)) = num THEN 0 ELSE 1 END AS mark FROM Logs ), - p AS (SELECT num, sum(mark) OVER (ORDER BY id) AS gid FROM t) + p AS (SELECT num, SUM(mark) OVER (ORDER BY id) AS gid FROM t) SELECT DISTINCT num AS ConsecutiveNums FROM p GROUP BY gid -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; diff --git a/solution/0100-0199/0182.Duplicate Emails/README.md b/solution/0100-0199/0182.Duplicate Emails/README.md index 2b1746daf5bb3..0d8c05566b108 100644 --- a/solution/0100-0199/0182.Duplicate Emails/README.md +++ b/solution/0100-0199/0182.Duplicate Emails/README.md @@ -72,7 +72,7 @@ Person 表: SELECT email FROM Person GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; ``` ```sql diff --git a/solution/0100-0199/0182.Duplicate Emails/README_EN.md b/solution/0100-0199/0182.Duplicate Emails/README_EN.md index 13622f64853f2..dc48a9d091873 100644 --- a/solution/0100-0199/0182.Duplicate Emails/README_EN.md +++ b/solution/0100-0199/0182.Duplicate Emails/README_EN.md @@ -66,7 +66,7 @@ We can use a self-join to join the `Person` table with itself, and then filter o SELECT email FROM Person GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; ``` ```sql diff --git a/solution/0100-0199/0182.Duplicate Emails/Solution.sql b/solution/0100-0199/0182.Duplicate Emails/Solution.sql index 849ea0dce7562..0c89c772ebdca 100644 --- a/solution/0100-0199/0182.Duplicate Emails/Solution.sql +++ b/solution/0100-0199/0182.Duplicate Emails/Solution.sql @@ -2,4 +2,4 @@ SELECT email FROM Person GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; diff --git a/solution/0100-0199/0184.Department Highest Salary/README.md b/solution/0100-0199/0184.Department Highest Salary/README.md index 90c130f49e264..a1703922343df 100644 --- a/solution/0100-0199/0184.Department Highest Salary/README.md +++ b/solution/0100-0199/0184.Department Highest Salary/README.md @@ -100,7 +100,7 @@ FROM JOIN Department AS d ON e.departmentId = d.id WHERE (d.id, salary) IN ( - SELECT departmentId, max(salary) + SELECT departmentId, MAX(salary) FROM Employee GROUP BY 1 ); @@ -114,7 +114,7 @@ WITH d.name AS department, e.name AS employee, salary, - rank() OVER ( + RANK() OVER ( PARTITION BY d.name ORDER BY salary DESC ) AS rk diff --git a/solution/0100-0199/0184.Department Highest Salary/README_EN.md b/solution/0100-0199/0184.Department Highest Salary/README_EN.md index 3fd39b36476b6..3a941a1d99dd0 100644 --- a/solution/0100-0199/0184.Department Highest Salary/README_EN.md +++ b/solution/0100-0199/0184.Department Highest Salary/README_EN.md @@ -98,7 +98,7 @@ FROM JOIN Department AS d ON e.departmentId = d.id WHERE (d.id, salary) IN ( - SELECT departmentId, max(salary) + SELECT departmentId, MAX(salary) FROM Employee GROUP BY 1 ); @@ -112,7 +112,7 @@ WITH d.name AS department, e.name AS employee, salary, - rank() OVER ( + RANK() OVER ( PARTITION BY d.name ORDER BY salary DESC ) AS rk diff --git a/solution/0100-0199/0184.Department Highest Salary/Solution.sql b/solution/0100-0199/0184.Department Highest Salary/Solution.sql index 1acc8d9707cd1..87e7b4680f3e7 100644 --- a/solution/0100-0199/0184.Department Highest Salary/Solution.sql +++ b/solution/0100-0199/0184.Department Highest Salary/Solution.sql @@ -5,7 +5,7 @@ FROM JOIN Department AS d ON e.departmentId = d.id WHERE (d.id, salary) IN ( - SELECT departmentId, max(salary) + SELECT departmentId, MAX(salary) FROM Employee GROUP BY 1 ); diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README.md b/solution/0100-0199/0185.Department Top Three Salaries/README.md index b0f9e2085c92d..05684ff88ead6 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README.md @@ -126,7 +126,7 @@ WITH T AS ( SELECT *, - dense_rank() OVER ( + DENSE_RANK() OVER ( PARTITION BY departmentId ORDER BY salary DESC ) AS rk diff --git a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md index ec7a4b6211ef9..70e1a60f4099c 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md +++ b/solution/0100-0199/0185.Department Top Three Salaries/README_EN.md @@ -122,7 +122,7 @@ WITH T AS ( SELECT *, - dense_rank() OVER ( + DENSE_RANK() OVER ( PARTITION BY departmentId ORDER BY salary DESC ) AS rk diff --git a/solution/0100-0199/0185.Department Top Three Salaries/Solution.sql b/solution/0100-0199/0185.Department Top Three Salaries/Solution.sql index 5d1ff474da523..688fb4f39f0e0 100644 --- a/solution/0100-0199/0185.Department Top Three Salaries/Solution.sql +++ b/solution/0100-0199/0185.Department Top Three Salaries/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - dense_rank() OVER ( + DENSE_RANK() OVER ( PARTITION BY departmentId ORDER BY salary DESC ) AS rk diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README.md b/solution/0100-0199/0196.Delete Duplicate Emails/README.md index 8960c700c5ee2..f8f5d6ad31927 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README.md @@ -65,7 +65,7 @@ Person 表: ```sql # Write your MySQL query statement below DELETE FROM Person -WHERE id NOT IN (SELECT min(id) FROM (SELECT * FROM Person) AS p GROUP BY email); +WHERE id NOT IN (SELECT MIN(id) FROM (SELECT * FROM Person) AS p GROUP BY email); ``` ```sql @@ -78,7 +78,7 @@ WHERE ( SELECT id, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY email ORDER BY id ) AS rk diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md index 65175fb3b7fb4..a56f075b00e85 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md +++ b/solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md @@ -61,7 +61,7 @@ Person table: ```sql # Write your MySQL query statement below DELETE FROM Person -WHERE id NOT IN (SELECT min(id) FROM (SELECT * FROM Person) AS p GROUP BY email); +WHERE id NOT IN (SELECT MIN(id) FROM (SELECT * FROM Person) AS p GROUP BY email); ``` ```sql @@ -74,7 +74,7 @@ WHERE ( SELECT id, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY email ORDER BY id ) AS rk diff --git a/solution/0100-0199/0196.Delete Duplicate Emails/Solution.sql b/solution/0100-0199/0196.Delete Duplicate Emails/Solution.sql index b8fb53376c887..583a78ebc8676 100644 --- a/solution/0100-0199/0196.Delete Duplicate Emails/Solution.sql +++ b/solution/0100-0199/0196.Delete Duplicate Emails/Solution.sql @@ -1,3 +1,3 @@ # Write your MySQL query statement below DELETE FROM Person -WHERE id NOT IN (SELECT min(id) FROM (SELECT * FROM Person) AS p GROUP BY email); +WHERE id NOT IN (SELECT MIN(id) FROM (SELECT * FROM Person) AS p GROUP BY email); diff --git a/solution/0100-0199/0197.Rising Temperature/README.md b/solution/0100-0199/0197.Rising Temperature/README.md index 87c7601f0a753..f228899869afd 100644 --- a/solution/0100-0199/0197.Rising Temperature/README.md +++ b/solution/0100-0199/0197.Rising Temperature/README.md @@ -71,7 +71,7 @@ SELECT w1.id FROM Weather AS w1 JOIN Weather AS w2 - ON datediff(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; + ON DATEDIFF(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; ``` ```sql diff --git a/solution/0100-0199/0197.Rising Temperature/README_EN.md b/solution/0100-0199/0197.Rising Temperature/README_EN.md index 0e5f1126e8af7..9c928ee0d2f68 100644 --- a/solution/0100-0199/0197.Rising Temperature/README_EN.md +++ b/solution/0100-0199/0197.Rising Temperature/README_EN.md @@ -64,7 +64,7 @@ SELECT w1.id FROM Weather AS w1 JOIN Weather AS w2 - ON datediff(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; + ON DATEDIFF(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; ``` ```sql diff --git a/solution/0100-0199/0197.Rising Temperature/Solution.sql b/solution/0100-0199/0197.Rising Temperature/Solution.sql index a46e46789a51a..e8ecebaee69ef 100644 --- a/solution/0100-0199/0197.Rising Temperature/Solution.sql +++ b/solution/0100-0199/0197.Rising Temperature/Solution.sql @@ -3,4 +3,4 @@ SELECT w1.id FROM Weather AS w1 JOIN Weather AS w2 - ON datediff(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; + ON DATEDIFF(w1.recordDate, w2.recordDate) = 1 AND w1.temperature > w2.temperature; diff --git a/solution/0200-0299/0262.Trips and Users/README.md b/solution/0200-0299/0262.Trips and Users/README.md index 53adf40454d84..11cdb315a09d9 100644 --- a/solution/0200-0299/0262.Trips and Users/README.md +++ b/solution/0200-0299/0262.Trips and Users/README.md @@ -131,7 +131,7 @@ Users 表: # Write your MySQL query statement below SELECT request_at AS Day, - round(avg(status != 'completed'), 2) AS 'Cancellation Rate' + ROUND(AVG(status != 'completed'), 2) AS 'Cancellation Rate' FROM Trips AS t JOIN Users AS u1 ON (t.client_id = u1.users_id AND u1.banned = 'No') diff --git a/solution/0200-0299/0262.Trips and Users/README_EN.md b/solution/0200-0299/0262.Trips and Users/README_EN.md index bbc8b1bcde5de..440adce8e9de5 100644 --- a/solution/0200-0299/0262.Trips and Users/README_EN.md +++ b/solution/0200-0299/0262.Trips and Users/README_EN.md @@ -118,7 +118,7 @@ On 2013-10-03: # Write your MySQL query statement below SELECT request_at AS Day, - round(avg(status != 'completed'), 2) AS 'Cancellation Rate' + ROUND(AVG(status != 'completed'), 2) AS 'Cancellation Rate' FROM Trips AS t JOIN Users AS u1 ON (t.client_id = u1.users_id AND u1.banned = 'No') diff --git a/solution/0200-0299/0262.Trips and Users/Solution.sql b/solution/0200-0299/0262.Trips and Users/Solution.sql index 35f5bfd354872..153e978b0b966 100644 --- a/solution/0200-0299/0262.Trips and Users/Solution.sql +++ b/solution/0200-0299/0262.Trips and Users/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT request_at AS Day, - round(avg(status != 'completed'), 2) AS 'Cancellation Rate' + ROUND(AVG(status != 'completed'), 2) AS 'Cancellation Rate' FROM Trips AS t JOIN Users AS u1 ON (t.client_id = u1.users_id AND u1.banned = 'No') diff --git a/solution/0500-0599/0511.Game Play Analysis I/README.md b/solution/0500-0599/0511.Game Play Analysis I/README.md index bd38ee1441458..5ca0090658796 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README.md @@ -64,7 +64,7 @@ Result 表: ```sql # Write your MySQL query statement below -SELECT player_id, min(event_date) AS first_login +SELECT player_id, MIN(event_date) AS first_login FROM Activity GROUP BY 1; ``` diff --git a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md index 93c17d98f12cc..1b8d9388d0424 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/README_EN.md +++ b/solution/0500-0599/0511.Game Play Analysis I/README_EN.md @@ -65,7 +65,7 @@ We can use `GROUP BY` to group the `player_id` and then take the minimum `event_ ```sql # Write your MySQL query statement below -SELECT player_id, min(event_date) AS first_login +SELECT player_id, MIN(event_date) AS first_login FROM Activity GROUP BY 1; ``` diff --git a/solution/0500-0599/0511.Game Play Analysis I/Solution.sql b/solution/0500-0599/0511.Game Play Analysis I/Solution.sql index 883f271c5424a..a27f29c2de8c2 100644 --- a/solution/0500-0599/0511.Game Play Analysis I/Solution.sql +++ b/solution/0500-0599/0511.Game Play Analysis I/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below -SELECT player_id, min(event_date) AS first_login +SELECT player_id, MIN(event_date) AS first_login FROM Activity GROUP BY 1; diff --git a/solution/0500-0599/0512.Game Play Analysis II/README.md b/solution/0500-0599/0512.Game Play Analysis II/README.md index bbff7f7b19fb1..c25d80bc7d23c 100644 --- a/solution/0500-0599/0512.Game Play Analysis II/README.md +++ b/solution/0500-0599/0512.Game Play Analysis II/README.md @@ -77,7 +77,7 @@ WHERE (player_id, event_date) IN ( SELECT player_id, - min(event_date) AS event_date + MIN(event_date) AS event_date FROM Activity GROUP BY 1 ); @@ -89,7 +89,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY player_id ORDER BY event_date ) AS rk diff --git a/solution/0500-0599/0512.Game Play Analysis II/README_EN.md b/solution/0500-0599/0512.Game Play Analysis II/README_EN.md index 7ecb6dc41ffbc..9ad78ecbb3aea 100644 --- a/solution/0500-0599/0512.Game Play Analysis II/README_EN.md +++ b/solution/0500-0599/0512.Game Play Analysis II/README_EN.md @@ -77,7 +77,7 @@ WHERE (player_id, event_date) IN ( SELECT player_id, - min(event_date) AS event_date + MIN(event_date) AS event_date FROM Activity GROUP BY 1 ); @@ -89,7 +89,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY player_id ORDER BY event_date ) AS rk diff --git a/solution/0500-0599/0512.Game Play Analysis II/Solution.sql b/solution/0500-0599/0512.Game Play Analysis II/Solution.sql index 6d6ad521a8c55..595a7595734a9 100644 --- a/solution/0500-0599/0512.Game Play Analysis II/Solution.sql +++ b/solution/0500-0599/0512.Game Play Analysis II/Solution.sql @@ -7,7 +7,7 @@ WHERE (player_id, event_date) IN ( SELECT player_id, - min(event_date) AS event_date + MIN(event_date) AS event_date FROM Activity GROUP BY 1 ); diff --git a/solution/0500-0599/0534.Game Play Analysis III/README.md b/solution/0500-0599/0534.Game Play Analysis III/README.md index 46b3c88105c5c..6b793484d7efe 100644 --- a/solution/0500-0599/0534.Game Play Analysis III/README.md +++ b/solution/0500-0599/0534.Game Play Analysis III/README.md @@ -83,7 +83,7 @@ Activity table: SELECT player_id, event_date, - sum(games_played) OVER ( + SUM(games_played) OVER ( PARTITION BY player_id ORDER BY event_date ) AS games_played_so_far @@ -95,7 +95,7 @@ FROM Activity; SELECT t1.player_id, t1.event_date, - sum(t2.games_played) AS games_played_so_far + SUM(t2.games_played) AS games_played_so_far FROM Activity AS t1, Activity AS t2 @@ -108,7 +108,7 @@ GROUP BY 1, 2; SELECT t1.player_id, t1.event_date, - sum(t2.games_played) AS games_played_so_far + SUM(t2.games_played) AS games_played_so_far FROM Activity AS t1 CROSS JOIN Activity AS t2 ON t1.player_id = t2.player_id AND t1.event_date >= t2.event_date diff --git a/solution/0500-0599/0534.Game Play Analysis III/README_EN.md b/solution/0500-0599/0534.Game Play Analysis III/README_EN.md index 2d0794e9c9214..2fbca0d36af0e 100644 --- a/solution/0500-0599/0534.Game Play Analysis III/README_EN.md +++ b/solution/0500-0599/0534.Game Play Analysis III/README_EN.md @@ -78,7 +78,7 @@ We can also use a self-join to join the `Activity` table with itself on the cond SELECT player_id, event_date, - sum(games_played) OVER ( + SUM(games_played) OVER ( PARTITION BY player_id ORDER BY event_date ) AS games_played_so_far @@ -90,7 +90,7 @@ FROM Activity; SELECT t1.player_id, t1.event_date, - sum(t2.games_played) AS games_played_so_far + SUM(t2.games_played) AS games_played_so_far FROM Activity AS t1, Activity AS t2 @@ -103,7 +103,7 @@ GROUP BY 1, 2; SELECT t1.player_id, t1.event_date, - sum(t2.games_played) AS games_played_so_far + SUM(t2.games_played) AS games_played_so_far FROM Activity AS t1 CROSS JOIN Activity AS t2 ON t1.player_id = t2.player_id AND t1.event_date >= t2.event_date diff --git a/solution/0500-0599/0534.Game Play Analysis III/Solution.sql b/solution/0500-0599/0534.Game Play Analysis III/Solution.sql index aff33ea8703e1..fe505a83d981d 100644 --- a/solution/0500-0599/0534.Game Play Analysis III/Solution.sql +++ b/solution/0500-0599/0534.Game Play Analysis III/Solution.sql @@ -2,7 +2,7 @@ SELECT player_id, event_date, - sum(games_played) OVER ( + SUM(games_played) OVER ( PARTITION BY player_id ORDER BY event_date ) AS games_played_so_far diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README.md b/solution/0500-0599/0550.Game Play Analysis IV/README.md index 91036fd850afd..f5154837b1494 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README.md @@ -64,7 +64,7 @@ Activity table: ```sql # Write your MySQL query statement below -SELECT round(AVG(b.event_date IS NOT NULL), 2) AS fraction +SELECT ROUND(AVG(b.event_date IS NOT NULL), 2) AS fraction FROM ( SELECT @@ -83,22 +83,22 @@ WITH T AS ( SELECT player_id, - datediff( - lead(event_date) OVER ( + DATEDIFF( + LEAD(event_date) OVER ( PARTITION BY player_id ORDER BY event_date ), event_date ) AS diff, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY player_id ORDER BY event_date ) AS rk FROM Activity ) SELECT - round( - count(DISTINCT if(diff = 1, player_id, NULL)) / count( + ROUND( + COUNT(DISTINCT IF(diff = 1, player_id, NULL)) / COUNT( DISTINCT player_id ), 2 diff --git a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md index d138fb6919ed1..6ab6ebe095480 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md +++ b/solution/0500-0599/0550.Game Play Analysis IV/README_EN.md @@ -59,7 +59,7 @@ Only the player with id 1 logged back in after the first day he had logged in so ```sql # Write your MySQL query statement below -SELECT round(AVG(b.event_date IS NOT NULL), 2) AS fraction +SELECT ROUND(AVG(b.event_date IS NOT NULL), 2) AS fraction FROM ( SELECT @@ -78,22 +78,22 @@ WITH T AS ( SELECT player_id, - datediff( - lead(event_date) OVER ( + DATEDIFF( + LEAD(event_date) OVER ( PARTITION BY player_id ORDER BY event_date ), event_date ) AS diff, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY player_id ORDER BY event_date ) AS rk FROM Activity ) SELECT - round( - count(DISTINCT if(diff = 1, player_id, NULL)) / count( + ROUND( + COUNT(DISTINCT IF(diff = 1, player_id, NULL)) / COUNT( DISTINCT player_id ), 2 diff --git a/solution/0500-0599/0550.Game Play Analysis IV/Solution.sql b/solution/0500-0599/0550.Game Play Analysis IV/Solution.sql index 4b203a25b6e24..c280cdd31172d 100644 --- a/solution/0500-0599/0550.Game Play Analysis IV/Solution.sql +++ b/solution/0500-0599/0550.Game Play Analysis IV/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT round(AVG(b.event_date IS NOT NULL), 2) AS fraction +SELECT ROUND(AVG(b.event_date IS NOT NULL), 2) AS fraction FROM ( SELECT diff --git a/solution/0500-0599/0569.Median Employee Salary/README.md b/solution/0500-0599/0569.Median Employee Salary/README.md index 76b4120223609..ac794abc51609 100644 --- a/solution/0500-0599/0569.Median Employee Salary/README.md +++ b/solution/0500-0599/0569.Median Employee Salary/README.md @@ -86,11 +86,11 @@ WITH t AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY company ORDER BY salary ASC ) AS rk, - count(id) OVER (PARTITION BY company) AS n + COUNT(id) OVER (PARTITION BY company) AS n FROM Employee ) SELECT diff --git a/solution/0500-0599/0569.Median Employee Salary/README_EN.md b/solution/0500-0599/0569.Median Employee Salary/README_EN.md index 1843a078dea4c..637f9e964a2c0 100644 --- a/solution/0500-0599/0569.Median Employee Salary/README_EN.md +++ b/solution/0500-0599/0569.Median Employee Salary/README_EN.md @@ -113,11 +113,11 @@ WITH t AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY company ORDER BY salary ASC ) AS rk, - count(id) OVER (PARTITION BY company) AS n + COUNT(id) OVER (PARTITION BY company) AS n FROM Employee ) SELECT diff --git a/solution/0500-0599/0569.Median Employee Salary/Solution.sql b/solution/0500-0599/0569.Median Employee Salary/Solution.sql index b7ce9a1168be9..863f5dad72c6e 100644 --- a/solution/0500-0599/0569.Median Employee Salary/Solution.sql +++ b/solution/0500-0599/0569.Median Employee Salary/Solution.sql @@ -3,11 +3,11 @@ WITH t AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY company ORDER BY salary ASC ) AS rk, - count(id) OVER (PARTITION BY company) AS n + COUNT(id) OVER (PARTITION BY company) AS n FROM Employee ) SELECT diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md index 19d58f970f77f..93b3874611a6b 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README.md @@ -75,7 +75,7 @@ FROM FROM Employee WHERE managerId IS NOT NULL GROUP BY managerId - HAVING count(1) >= 5 + HAVING COUNT(1) >= 5 ) AS e2 ON e1.id = e2.managerId; ``` @@ -86,7 +86,7 @@ WITH T AS ( SELECT managerId, - count(1) OVER (PARTITION BY managerId) AS cnt + COUNT(1) OVER (PARTITION BY managerId) AS cnt FROM Employee ) SELECT DISTINCT name diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md index aae0b888a5619..ed270d96ce062 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/README_EN.md @@ -71,7 +71,7 @@ FROM FROM Employee WHERE managerId IS NOT NULL GROUP BY managerId - HAVING count(1) >= 5 + HAVING COUNT(1) >= 5 ) AS e2 ON e1.id = e2.managerId; ``` @@ -82,7 +82,7 @@ WITH T AS ( SELECT managerId, - count(1) OVER (PARTITION BY managerId) AS cnt + COUNT(1) OVER (PARTITION BY managerId) AS cnt FROM Employee ) SELECT DISTINCT name diff --git a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/Solution.sql b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/Solution.sql index decc9101caffd..96333f8d5926b 100644 --- a/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/Solution.sql +++ b/solution/0500-0599/0570.Managers with at Least 5 Direct Reports/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT managerId, - count(1) OVER (PARTITION BY managerId) AS cnt + COUNT(1) OVER (PARTITION BY managerId) AS cnt FROM Employee ) SELECT DISTINCT name diff --git a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md index 035955489f4c9..238e70919bf7a 100644 --- a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md +++ b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README.md @@ -72,13 +72,13 @@ WITH t AS ( SELECT *, - sum(frequency) OVER (ORDER BY num ASC) AS rk1, - sum(frequency) OVER (ORDER BY num DESC) AS rk2, - sum(frequency) OVER () AS s + SUM(frequency) OVER (ORDER BY num ASC) AS rk1, + SUM(frequency) OVER (ORDER BY num DESC) AS rk2, + SUM(frequency) OVER () AS s FROM Numbers ) SELECT - round(avg(num), 1) AS median + ROUND(AVG(num), 1) AS median FROM t WHERE rk1 >= s / 2 AND rk2 >= s / 2; ``` diff --git a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md index 9c4da272e97dd..4646064a1bf90 100644 --- a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md +++ b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/README_EN.md @@ -61,13 +61,13 @@ WITH t AS ( SELECT *, - sum(frequency) OVER (ORDER BY num ASC) AS rk1, - sum(frequency) OVER (ORDER BY num DESC) AS rk2, - sum(frequency) OVER () AS s + SUM(frequency) OVER (ORDER BY num ASC) AS rk1, + SUM(frequency) OVER (ORDER BY num DESC) AS rk2, + SUM(frequency) OVER () AS s FROM Numbers ) SELECT - round(avg(num), 1) AS median + ROUND(AVG(num), 1) AS median FROM t WHERE rk1 >= s / 2 AND rk2 >= s / 2; ``` diff --git a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/Solution.sql b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/Solution.sql index 48eda0419aa9a..f0e1e492cdfad 100644 --- a/solution/0500-0599/0571.Find Median Given Frequency of Numbers/Solution.sql +++ b/solution/0500-0599/0571.Find Median Given Frequency of Numbers/Solution.sql @@ -3,12 +3,12 @@ WITH t AS ( SELECT *, - sum(frequency) OVER (ORDER BY num ASC) AS rk1, - sum(frequency) OVER (ORDER BY num DESC) AS rk2, - sum(frequency) OVER () AS s + SUM(frequency) OVER (ORDER BY num ASC) AS rk1, + SUM(frequency) OVER (ORDER BY num DESC) AS rk2, + SUM(frequency) OVER () AS s FROM Numbers ) SELECT - round(avg(num), 1) AS median + ROUND(AVG(num), 1) AS median FROM t WHERE rk1 >= s / 2 AND rk2 >= s / 2; diff --git a/solution/0500-0599/0574.Winning Candidate/README.md b/solution/0500-0599/0574.Winning Candidate/README.md index a22a030733b95..e0c7812d1dc14 100644 --- a/solution/0500-0599/0574.Winning Candidate/README.md +++ b/solution/0500-0599/0574.Winning Candidate/README.md @@ -108,7 +108,7 @@ FROM Candidate AS c LEFT JOIN Vote AS v ON c.id = v.candidateId GROUP BY c.id -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; ``` diff --git a/solution/0500-0599/0574.Winning Candidate/README_EN.md b/solution/0500-0599/0574.Winning Candidate/README_EN.md index 559e3aba26398..f3ead4ae5ded0 100644 --- a/solution/0500-0599/0574.Winning Candidate/README_EN.md +++ b/solution/0500-0599/0574.Winning Candidate/README_EN.md @@ -106,7 +106,7 @@ FROM Candidate AS c LEFT JOIN Vote AS v ON c.id = v.candidateId GROUP BY c.id -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; ``` diff --git a/solution/0500-0599/0574.Winning Candidate/Solution.sql b/solution/0500-0599/0574.Winning Candidate/Solution.sql index d74ffdf51bcad..249034be82a7c 100644 --- a/solution/0500-0599/0574.Winning Candidate/Solution.sql +++ b/solution/0500-0599/0574.Winning Candidate/Solution.sql @@ -4,5 +4,5 @@ FROM Candidate AS c LEFT JOIN Vote AS v ON c.id = v.candidateId GROUP BY c.id -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; diff --git a/solution/0500-0599/0577.Employee Bonus/README.md b/solution/0500-0599/0577.Employee Bonus/README.md index a973bf5be0d89..97ccdd6cbd22f 100644 --- a/solution/0500-0599/0577.Employee Bonus/README.md +++ b/solution/0500-0599/0577.Employee Bonus/README.md @@ -90,7 +90,7 @@ SELECT name, bonus FROM Employee LEFT JOIN Bonus USING (empId) -WHERE ifnull(bonus, 0) < 1000; +WHERE IFNULL(bonus, 0) < 1000; ``` diff --git a/solution/0500-0599/0577.Employee Bonus/README_EN.md b/solution/0500-0599/0577.Employee Bonus/README_EN.md index 049bda9fb9f77..b09a8d2f5f3b3 100644 --- a/solution/0500-0599/0577.Employee Bonus/README_EN.md +++ b/solution/0500-0599/0577.Employee Bonus/README_EN.md @@ -86,7 +86,7 @@ SELECT name, bonus FROM Employee LEFT JOIN Bonus USING (empId) -WHERE ifnull(bonus, 0) < 1000; +WHERE IFNULL(bonus, 0) < 1000; ``` diff --git a/solution/0500-0599/0577.Employee Bonus/Solution.sql b/solution/0500-0599/0577.Employee Bonus/Solution.sql index e4e860f4f1b3d..d8fb44e736ec5 100644 --- a/solution/0500-0599/0577.Employee Bonus/Solution.sql +++ b/solution/0500-0599/0577.Employee Bonus/Solution.sql @@ -3,4 +3,4 @@ SELECT name, bonus FROM Employee LEFT JOIN Bonus USING (empId) -WHERE ifnull(bonus, 0) < 1000; +WHERE IFNULL(bonus, 0) < 1000; diff --git a/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md b/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md index ed120cc5bc9d2..12085390e6f2c 100644 --- a/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md +++ b/solution/0500-0599/0578.Get Highest Answer Rate Question/README.md @@ -77,7 +77,7 @@ SurveyLog table: SELECT question_id AS survey_log FROM SurveyLog GROUP BY 1 -ORDER BY sum(action = 'answer') / sum(action = 'show') DESC, 1 +ORDER BY SUM(action = 'answer') / SUM(action = 'show') DESC, 1 LIMIT 1; ``` @@ -86,8 +86,8 @@ WITH T AS ( SELECT question_id AS survey_log, - (sum(action = 'answer') OVER (PARTITION BY question_id)) / ( - sum(action = 'show') OVER (PARTITION BY question_id) + (SUM(action = 'answer') OVER (PARTITION BY question_id)) / ( + SUM(action = 'show') OVER (PARTITION BY question_id) ) AS ratio FROM SurveyLog ) diff --git a/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md b/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md index a6167d31cb6fa..66c2de49df00e 100644 --- a/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md +++ b/solution/0500-0599/0578.Get Highest Answer Rate Question/README_EN.md @@ -68,7 +68,7 @@ Question 285 has the highest answer rate. SELECT question_id AS survey_log FROM SurveyLog GROUP BY 1 -ORDER BY sum(action = 'answer') / sum(action = 'show') DESC, 1 +ORDER BY SUM(action = 'answer') / SUM(action = 'show') DESC, 1 LIMIT 1; ``` @@ -77,8 +77,8 @@ WITH T AS ( SELECT question_id AS survey_log, - (sum(action = 'answer') OVER (PARTITION BY question_id)) / ( - sum(action = 'show') OVER (PARTITION BY question_id) + (SUM(action = 'answer') OVER (PARTITION BY question_id)) / ( + SUM(action = 'show') OVER (PARTITION BY question_id) ) AS ratio FROM SurveyLog ) diff --git a/solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql b/solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql index fe090d0873f2f..93c2e56a5a56e 100644 --- a/solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql +++ b/solution/0500-0599/0578.Get Highest Answer Rate Question/Solution.sql @@ -2,8 +2,8 @@ WITH T AS ( SELECT question_id AS survey_log, - (sum(action = 'answer') OVER (PARTITION BY question_id)) / ( - sum(action = 'show') OVER (PARTITION BY question_id) + (SUM(action = 'answer') OVER (PARTITION BY question_id)) / ( + SUM(action = 'show') OVER (PARTITION BY question_id) ) AS ratio FROM SurveyLog ) diff --git a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md index 0b2b2a7aea737..c16c5752a9d52 100644 --- a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md +++ b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README.md @@ -121,7 +121,7 @@ Employee table: SELECT id, month, - sum(salary) OVER ( + SUM(salary) OVER ( PARTITION BY id ORDER BY month RANGE 2 PRECEDING @@ -131,7 +131,7 @@ WHERE (id, month) NOT IN ( SELECT id, - max(month) + MAX(month) FROM Employee GROUP BY id ) @@ -145,12 +145,12 @@ WITH SELECT id, month, - sum(salary) OVER ( + SUM(salary) OVER ( PARTITION BY id ORDER BY month RANGE 2 PRECEDING ) AS salary, - rank() OVER ( + RANK() OVER ( PARTITION BY id ORDER BY month DESC ) AS rk diff --git a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md index 5aa5b19041b44..aeb53ff54e10f 100644 --- a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md +++ b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/README_EN.md @@ -117,7 +117,7 @@ So the cumulative salary summary for this employee is: SELECT id, month, - sum(salary) OVER ( + SUM(salary) OVER ( PARTITION BY id ORDER BY month RANGE 2 PRECEDING @@ -127,7 +127,7 @@ WHERE (id, month) NOT IN ( SELECT id, - max(month) + MAX(month) FROM Employee GROUP BY id ) @@ -141,12 +141,12 @@ WITH SELECT id, month, - sum(salary) OVER ( + SUM(salary) OVER ( PARTITION BY id ORDER BY month RANGE 2 PRECEDING ) AS salary, - rank() OVER ( + RANK() OVER ( PARTITION BY id ORDER BY month DESC ) AS rk diff --git a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/Solution.sql b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/Solution.sql index 35dd2db482c31..d7e0629c81a28 100644 --- a/solution/0500-0599/0579.Find Cumulative Salary of an Employee/Solution.sql +++ b/solution/0500-0599/0579.Find Cumulative Salary of an Employee/Solution.sql @@ -4,12 +4,12 @@ WITH SELECT id, month, - sum(salary) OVER ( + SUM(salary) OVER ( PARTITION BY id ORDER BY month RANGE 2 PRECEDING ) AS salary, - rank() OVER ( + RANK() OVER ( PARTITION BY id ORDER BY month DESC ) AS rk diff --git a/solution/0500-0599/0580.Count Student Number in Departments/README.md b/solution/0500-0599/0580.Count Student Number in Departments/README.md index c5446960cf1dd..4f221308f3e3a 100644 --- a/solution/0500-0599/0580.Count Student Number in Departments/README.md +++ b/solution/0500-0599/0580.Count Student Number in Departments/README.md @@ -87,11 +87,11 @@ Department 表: # Write your MySQL query statement below WITH S AS ( - SELECT dept_id, count(1) AS cnt + SELECT dept_id, COUNT(1) AS cnt FROM Student GROUP BY dept_id ) -SELECT dept_name, ifnull(cnt, 0) AS student_number +SELECT dept_name, IFNULL(cnt, 0) AS student_number FROM S RIGHT JOIN Department USING (dept_id) diff --git a/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md b/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md index 14d07736c9c31..7d297977cba32 100644 --- a/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md +++ b/solution/0500-0599/0580.Count Student Number in Departments/README_EN.md @@ -84,11 +84,11 @@ Department table: # Write your MySQL query statement below WITH S AS ( - SELECT dept_id, count(1) AS cnt + SELECT dept_id, COUNT(1) AS cnt FROM Student GROUP BY dept_id ) -SELECT dept_name, ifnull(cnt, 0) AS student_number +SELECT dept_name, IFNULL(cnt, 0) AS student_number FROM S RIGHT JOIN Department USING (dept_id) diff --git a/solution/0500-0599/0580.Count Student Number in Departments/Solution.sql b/solution/0500-0599/0580.Count Student Number in Departments/Solution.sql index 0cf0bdc6003eb..213d8f611ca07 100644 --- a/solution/0500-0599/0580.Count Student Number in Departments/Solution.sql +++ b/solution/0500-0599/0580.Count Student Number in Departments/Solution.sql @@ -1,11 +1,11 @@ # Write your MySQL query statement below WITH S AS ( - SELECT dept_id, count(1) AS cnt + SELECT dept_id, COUNT(1) AS cnt FROM Student GROUP BY dept_id ) -SELECT dept_name, ifnull(cnt, 0) AS student_number +SELECT dept_name, IFNULL(cnt, 0) AS student_number FROM S RIGHT JOIN Department USING (dept_id) diff --git a/solution/0500-0599/0584.Find Customer Referee/README.md b/solution/0500-0599/0584.Find Customer Referee/README.md index 4ce0ec4fa4828..80468389c082d 100644 --- a/solution/0500-0599/0584.Find Customer Referee/README.md +++ b/solution/0500-0599/0584.Find Customer Referee/README.md @@ -64,7 +64,7 @@ Customer 表: # Write your MySQL query statement below SELECT name FROM Customer -WHERE ifnull(referee_id, 0) != 2; +WHERE IFNULL(referee_id, 0) != 2; ``` diff --git a/solution/0500-0599/0584.Find Customer Referee/README_EN.md b/solution/0500-0599/0584.Find Customer Referee/README_EN.md index 200e539b56f05..1467f768c2291 100644 --- a/solution/0500-0599/0584.Find Customer Referee/README_EN.md +++ b/solution/0500-0599/0584.Find Customer Referee/README_EN.md @@ -63,7 +63,7 @@ Customer table: # Write your MySQL query statement below SELECT name FROM Customer -WHERE ifnull(referee_id, 0) != 2; +WHERE IFNULL(referee_id, 0) != 2; ``` diff --git a/solution/0500-0599/0584.Find Customer Referee/Solution.sql b/solution/0500-0599/0584.Find Customer Referee/Solution.sql index f4511718b3518..e31fb9e0da363 100644 --- a/solution/0500-0599/0584.Find Customer Referee/Solution.sql +++ b/solution/0500-0599/0584.Find Customer Referee/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below SELECT name FROM Customer -WHERE ifnull(referee_id, 0) != 2; +WHERE IFNULL(referee_id, 0) != 2; diff --git a/solution/0500-0599/0585.Investments in 2016/README.md b/solution/0500-0599/0585.Investments in 2016/README.md index d55f250a4a82e..ec13524ed04fa 100644 --- a/solution/0500-0599/0585.Investments in 2016/README.md +++ b/solution/0500-0599/0585.Investments in 2016/README.md @@ -84,11 +84,11 @@ WITH T AS ( SELECT tiv_2016, - count(pid) OVER (PARTITION BY tiv_2015) AS cnt1, - count(pid) OVER (PARTITION BY concat(lat, '-', lon)) AS cnt2 + COUNT(pid) OVER (PARTITION BY tiv_2015) AS cnt1, + COUNT(pid) OVER (PARTITION BY CONCAT(lat, '-', lon)) AS cnt2 FROM Insurance ) -SELECT round(ifnull(sum(tiv_2016), 0), 2) AS tiv_2016 +SELECT ROUND(IFNULL(SUM(tiv_2016), 0), 2) AS tiv_2016 FROM T WHERE cnt1 > 1 AND cnt2 = 1; ``` diff --git a/solution/0500-0599/0585.Investments in 2016/README_EN.md b/solution/0500-0599/0585.Investments in 2016/README_EN.md index b8df24a90dcfc..904c272d183c1 100644 --- a/solution/0500-0599/0585.Investments in 2016/README_EN.md +++ b/solution/0500-0599/0585.Investments in 2016/README_EN.md @@ -77,11 +77,11 @@ WITH T AS ( SELECT tiv_2016, - count(pid) OVER (PARTITION BY tiv_2015) AS cnt1, - count(pid) OVER (PARTITION BY concat(lat, '-', lon)) AS cnt2 + COUNT(pid) OVER (PARTITION BY tiv_2015) AS cnt1, + COUNT(pid) OVER (PARTITION BY CONCAT(lat, '-', lon)) AS cnt2 FROM Insurance ) -SELECT round(ifnull(sum(tiv_2016), 0), 2) AS tiv_2016 +SELECT ROUND(IFNULL(SUM(tiv_2016), 0), 2) AS tiv_2016 FROM T WHERE cnt1 > 1 AND cnt2 = 1; ``` diff --git a/solution/0500-0599/0585.Investments in 2016/Solution.sql b/solution/0500-0599/0585.Investments in 2016/Solution.sql index dc5894796dce3..30b95dc8c0837 100644 --- a/solution/0500-0599/0585.Investments in 2016/Solution.sql +++ b/solution/0500-0599/0585.Investments in 2016/Solution.sql @@ -3,10 +3,10 @@ WITH T AS ( SELECT tiv_2016, - count(pid) OVER (PARTITION BY tiv_2015) AS cnt1, - count(pid) OVER (PARTITION BY concat(lat, '-', lon)) AS cnt2 + COUNT(pid) OVER (PARTITION BY tiv_2015) AS cnt1, + COUNT(pid) OVER (PARTITION BY CONCAT(lat, '-', lon)) AS cnt2 FROM Insurance ) -SELECT round(ifnull(sum(tiv_2016), 0), 2) AS tiv_2016 +SELECT ROUND(IFNULL(SUM(tiv_2016), 0), 2) AS tiv_2016 FROM T WHERE cnt1 > 1 AND cnt2 = 1; diff --git a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md index f0ff6183ef92f..eafc852aec46f 100644 --- a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md +++ b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md @@ -75,7 +75,7 @@ SELECT customer_number FROM orders GROUP BY customer_number -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; ``` diff --git a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md index 95dde303f80d3..fcbfd4a22f47b 100644 --- a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md +++ b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md @@ -68,7 +68,7 @@ We can use `GROUP BY` to group the data by `customer_number`, and then sort the SELECT customer_number FROM Orders GROUP BY 1 -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; ``` diff --git a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/Solution.sql b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/Solution.sql index 7bfa331b10f11..d23b1d5e04ed3 100644 --- a/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/Solution.sql +++ b/solution/0500-0599/0586.Customer Placing the Largest Number of Orders/Solution.sql @@ -2,5 +2,5 @@ SELECT customer_number FROM Orders GROUP BY 1 -ORDER BY count(1) DESC +ORDER BY COUNT(1) DESC LIMIT 1; diff --git a/solution/0500-0599/0596.Classes More Than 5 Students/README.md b/solution/0500-0599/0596.Classes More Than 5 Students/README.md index da7216c9bd81c..44b51c1472aa8 100644 --- a/solution/0500-0599/0596.Classes More Than 5 Students/README.md +++ b/solution/0500-0599/0596.Classes More Than 5 Students/README.md @@ -72,7 +72,7 @@ Courses table: SELECT class FROM Courses GROUP BY class -HAVING count(1) >= 5; +HAVING COUNT(1) >= 5; ``` diff --git a/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md b/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md index 4d71a0f4e4573..40f261494c8e1 100644 --- a/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md +++ b/solution/0500-0599/0596.Classes More Than 5 Students/README_EN.md @@ -68,7 +68,7 @@ Courses table: SELECT class FROM Courses GROUP BY class -HAVING count(1) >= 5; +HAVING COUNT(1) >= 5; ``` diff --git a/solution/0500-0599/0596.Classes More Than 5 Students/Solution.sql b/solution/0500-0599/0596.Classes More Than 5 Students/Solution.sql index f1e77df3a05b2..50d82027afa04 100644 --- a/solution/0500-0599/0596.Classes More Than 5 Students/Solution.sql +++ b/solution/0500-0599/0596.Classes More Than 5 Students/Solution.sql @@ -2,4 +2,4 @@ SELECT class FROM Courses GROUP BY class -HAVING count(1) >= 5; +HAVING COUNT(1) >= 5; diff --git a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md index b87ff20dacb2c..88c75eca12e35 100644 --- a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md +++ b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README.md @@ -104,12 +104,12 @@ RequestAccepted 表: ```sql # Write your MySQL query statement below SELECT - round( - ifnull( + ROUND( + IFNULL( ( - SELECT count(DISTINCT requester_id, accepter_id) + SELECT COUNT(DISTINCT requester_id, accepter_id) FROM RequestAccepted - ) / (SELECT count(DISTINCT sender_id, send_to_id) FROM FriendRequest), + ) / (SELECT COUNT(DISTINCT sender_id, send_to_id) FROM FriendRequest), 0 ), 2 diff --git a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md index 7d621e217fdb0..f3234ef182cd2 100644 --- a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md +++ b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/README_EN.md @@ -100,12 +100,12 @@ There are 4 unique accepted requests, and there are 5 requests in total. So the ```sql # Write your MySQL query statement below SELECT - round( - ifnull( + ROUND( + IFNULL( ( - SELECT count(DISTINCT requester_id, accepter_id) + SELECT COUNT(DISTINCT requester_id, accepter_id) FROM RequestAccepted - ) / (SELECT count(DISTINCT sender_id, send_to_id) FROM FriendRequest), + ) / (SELECT COUNT(DISTINCT sender_id, send_to_id) FROM FriendRequest), 0 ), 2 diff --git a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/Solution.sql b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/Solution.sql index aca70ca6aca6a..4cafe4c15c9a0 100644 --- a/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/Solution.sql +++ b/solution/0500-0599/0597.Friend Requests I Overall Acceptance Rate/Solution.sql @@ -1,11 +1,11 @@ # Write your MySQL query statement below SELECT - round( - ifnull( + ROUND( + IFNULL( ( - SELECT count(DISTINCT requester_id, accepter_id) + SELECT COUNT(DISTINCT requester_id, accepter_id) FROM RequestAccepted - ) / (SELECT count(DISTINCT sender_id, send_to_id) FROM FriendRequest), + ) / (SELECT COUNT(DISTINCT sender_id, send_to_id) FROM FriendRequest), 0 ), 2 diff --git a/solution/0600-0699/0601.Human Traffic of Stadium/README.md b/solution/0600-0699/0601.Human Traffic of Stadium/README.md index 6375a5de78037..5f1edc8b8714e 100644 --- a/solution/0600-0699/0601.Human Traffic of Stadium/README.md +++ b/solution/0600-0699/0601.Human Traffic of Stadium/README.md @@ -76,11 +76,11 @@ WITH S AS ( SELECT *, - id - (row_number() OVER (ORDER BY id)) AS rk + id - (ROW_NUMBER() OVER (ORDER BY id)) AS rk FROM Stadium WHERE people >= 100 ), - T AS (SELECT *, count(1) OVER (PARTITION BY rk) AS cnt FROM S) + T AS (SELECT *, COUNT(1) OVER (PARTITION BY rk) AS cnt FROM S) SELECT id, visit_date, people FROM T WHERE cnt >= 3 diff --git a/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md b/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md index 021d8865eadb7..6e84bd6abe0ee 100644 --- a/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md +++ b/solution/0600-0699/0601.Human Traffic of Stadium/README_EN.md @@ -71,11 +71,11 @@ WITH S AS ( SELECT *, - id - (row_number() OVER (ORDER BY id)) AS rk + id - (ROW_NUMBER() OVER (ORDER BY id)) AS rk FROM Stadium WHERE people >= 100 ), - T AS (SELECT *, count(1) OVER (PARTITION BY rk) AS cnt FROM S) + T AS (SELECT *, COUNT(1) OVER (PARTITION BY rk) AS cnt FROM S) SELECT id, visit_date, people FROM T WHERE cnt >= 3 diff --git a/solution/0600-0699/0601.Human Traffic of Stadium/Solution.sql b/solution/0600-0699/0601.Human Traffic of Stadium/Solution.sql index 3b95415d2e5cc..aa3bca81ae7b4 100644 --- a/solution/0600-0699/0601.Human Traffic of Stadium/Solution.sql +++ b/solution/0600-0699/0601.Human Traffic of Stadium/Solution.sql @@ -3,11 +3,11 @@ WITH S AS ( SELECT *, - id - (row_number() OVER (ORDER BY id)) AS rk + id - (ROW_NUMBER() OVER (ORDER BY id)) AS rk FROM Stadium WHERE people >= 100 ), - T AS (SELECT *, count(1) OVER (PARTITION BY rk) AS cnt FROM S) + T AS (SELECT *, COUNT(1) OVER (PARTITION BY rk) AS cnt FROM S) SELECT id, visit_date, people FROM T WHERE cnt >= 3 diff --git a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md index eaa3876653293..b11e75110824f 100644 --- a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md +++ b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md @@ -76,7 +76,7 @@ WITH UNION SELECT accepter_id, requester_id FROM RequestAccepted ) -SELECT requester_id AS id, count(accepter_id) AS num +SELECT requester_id AS id, COUNT(accepter_id) AS num FROM T GROUP BY 1 ORDER BY 2 DESC diff --git a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md index 8dc8211207024..bceb6e7ee85e3 100644 --- a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md +++ b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md @@ -67,7 +67,7 @@ WITH UNION SELECT accepter_id, requester_id FROM RequestAccepted ) -SELECT requester_id AS id, count(accepter_id) AS num +SELECT requester_id AS id, COUNT(accepter_id) AS num FROM T GROUP BY 1 ORDER BY 2 DESC diff --git a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/Solution.sql b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/Solution.sql index 2cbbdb5c6b300..10f961e17997a 100644 --- a/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/Solution.sql +++ b/solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/Solution.sql @@ -5,7 +5,7 @@ WITH UNION SELECT accepter_id, requester_id FROM RequestAccepted ) -SELECT requester_id AS id, count(accepter_id) AS num +SELECT requester_id AS id, COUNT(accepter_id) AS num FROM T GROUP BY 1 ORDER BY 2 DESC diff --git a/solution/0600-0699/0603.Consecutive Available Seats/README.md b/solution/0600-0699/0603.Consecutive Available Seats/README.md index d6e06395229af..0bde738a09166 100644 --- a/solution/0600-0699/0603.Consecutive Available Seats/README.md +++ b/solution/0600-0699/0603.Consecutive Available Seats/README.md @@ -74,7 +74,7 @@ Cinema 表: SELECT DISTINCT a.seat_id FROM Cinema AS a - JOIN Cinema AS b ON abs(a.seat_id - b.seat_id) = 1 AND a.free AND b.free + JOIN Cinema AS b ON ABS(a.seat_id - b.seat_id) = 1 AND a.free AND b.free ORDER BY 1; ``` @@ -84,8 +84,8 @@ WITH T AS ( SELECT seat_id, - (free + (lag(free) OVER (ORDER BY seat_id))) AS a, - (free + (lead(free) OVER (ORDER BY seat_id))) AS b + (free + (LAG(free) OVER (ORDER BY seat_id))) AS a, + (free + (LEAD(free) OVER (ORDER BY seat_id))) AS b FROM Cinema ) SELECT seat_id @@ -99,7 +99,7 @@ WITH T AS ( SELECT *, - sum(free = 1) OVER ( + SUM(free = 1) OVER ( ORDER BY seat_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING ) AS cnt diff --git a/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md b/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md index 25b463562fade..05cc5b8b5d2fc 100644 --- a/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md +++ b/solution/0600-0699/0603.Consecutive Available Seats/README_EN.md @@ -71,7 +71,7 @@ We can use the `LAG` and `LEAD` functions (or `SUM() OVER(ROWS BETWEEN 1 PRECEDI SELECT DISTINCT a.seat_id FROM Cinema AS a - JOIN Cinema AS b ON abs(a.seat_id - b.seat_id) = 1 AND a.free AND b.free + JOIN Cinema AS b ON ABS(a.seat_id - b.seat_id) = 1 AND a.free AND b.free ORDER BY 1; ``` @@ -81,8 +81,8 @@ WITH T AS ( SELECT seat_id, - (free + (lag(free) OVER (ORDER BY seat_id))) AS a, - (free + (lead(free) OVER (ORDER BY seat_id))) AS b + (free + (LAG(free) OVER (ORDER BY seat_id))) AS a, + (free + (LEAD(free) OVER (ORDER BY seat_id))) AS b FROM Cinema ) SELECT seat_id @@ -96,7 +96,7 @@ WITH T AS ( SELECT *, - sum(free = 1) OVER ( + SUM(free = 1) OVER ( ORDER BY seat_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING ) AS cnt diff --git a/solution/0600-0699/0603.Consecutive Available Seats/Solution.sql b/solution/0600-0699/0603.Consecutive Available Seats/Solution.sql index 0b463cd53c4a2..56f8c1130022e 100644 --- a/solution/0600-0699/0603.Consecutive Available Seats/Solution.sql +++ b/solution/0600-0699/0603.Consecutive Available Seats/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - sum(free = 1) OVER ( + SUM(free = 1) OVER ( ORDER BY seat_id ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING ) AS cnt diff --git a/solution/0600-0699/0607.Sales Person/README.md b/solution/0600-0699/0607.Sales Person/README.md index bc083b1f0e57d..9c83e47cd0533 100644 --- a/solution/0600-0699/0607.Sales Person/README.md +++ b/solution/0600-0699/0607.Sales Person/README.md @@ -132,7 +132,7 @@ FROM LEFT JOIN Orders USING (sales_id) LEFT JOIN Company AS c USING (com_id) GROUP BY sales_id -HAVING ifnull(sum(c.name = 'RED'), 0) = 0; +HAVING IFNULL(SUM(c.name = 'RED'), 0) = 0; ``` diff --git a/solution/0600-0699/0607.Sales Person/README_EN.md b/solution/0600-0699/0607.Sales Person/README_EN.md index 3eb5200122ccb..f909cf2f4cf74 100644 --- a/solution/0600-0699/0607.Sales Person/README_EN.md +++ b/solution/0600-0699/0607.Sales Person/README_EN.md @@ -127,7 +127,7 @@ FROM LEFT JOIN Orders USING (sales_id) LEFT JOIN Company AS c USING (com_id) GROUP BY sales_id -HAVING ifnull(sum(c.name = 'RED'), 0) = 0; +HAVING IFNULL(SUM(c.name = 'RED'), 0) = 0; ``` diff --git a/solution/0600-0699/0607.Sales Person/Solution.sql b/solution/0600-0699/0607.Sales Person/Solution.sql index ae6951a1ca545..07afb963f7a8d 100644 --- a/solution/0600-0699/0607.Sales Person/Solution.sql +++ b/solution/0600-0699/0607.Sales Person/Solution.sql @@ -5,4 +5,4 @@ FROM LEFT JOIN Orders USING (sales_id) LEFT JOIN Company AS c USING (com_id) GROUP BY sales_id -HAVING ifnull(sum(c.name = 'RED'), 0) = 0; +HAVING IFNULL(SUM(c.name = 'RED'), 0) = 0; diff --git a/solution/0600-0699/0610.Triangle Judgement/README.md b/solution/0600-0699/0610.Triangle Judgement/README.md index 248121cf463ff..9f3ce9f9e8dca 100644 --- a/solution/0600-0699/0610.Triangle Judgement/README.md +++ b/solution/0600-0699/0610.Triangle Judgement/README.md @@ -65,7 +65,7 @@ Triangle 表: # Write your MySQL query statement below SELECT *, - if(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle + IF(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle FROM Triangle; ``` diff --git a/solution/0600-0699/0610.Triangle Judgement/README_EN.md b/solution/0600-0699/0610.Triangle Judgement/README_EN.md index 0eacb880efd0a..23e65b7319406 100644 --- a/solution/0600-0699/0610.Triangle Judgement/README_EN.md +++ b/solution/0600-0699/0610.Triangle Judgement/README_EN.md @@ -57,7 +57,7 @@ Triangle table: # Write your MySQL query statement below SELECT *, - if(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle + IF(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle FROM Triangle; ``` diff --git a/solution/0600-0699/0610.Triangle Judgement/Solution.sql b/solution/0600-0699/0610.Triangle Judgement/Solution.sql index 2058636aa90cb..d21d325806ac5 100644 --- a/solution/0600-0699/0610.Triangle Judgement/Solution.sql +++ b/solution/0600-0699/0610.Triangle Judgement/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below SELECT *, - if(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle + IF(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle FROM Triangle; diff --git a/solution/0600-0699/0612.Shortest Distance in a Plane/README.md b/solution/0600-0699/0612.Shortest Distance in a Plane/README.md index d1fb0460c3f99..8f6c5d549d159 100644 --- a/solution/0600-0699/0612.Shortest Distance in a Plane/README.md +++ b/solution/0600-0699/0612.Shortest Distance in a Plane/README.md @@ -66,7 +66,7 @@ Point2D table: ```sql # Write your MySQL query statement below -SELECT round(sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)), 2) AS shortest +SELECT ROUND(SQRT(POW(p1.x - p2.x, 2) + POW(p1.y - p2.y, 2)), 2) AS shortest FROM Point2D AS p1, Point2D AS p2 diff --git a/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md b/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md index 59033c4dbbfbd..2deea7674cfa9 100644 --- a/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md +++ b/solution/0600-0699/0612.Shortest Distance in a Plane/README_EN.md @@ -55,7 +55,7 @@ Point2D table: ```sql # Write your MySQL query statement below -SELECT round(sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)), 2) AS shortest +SELECT ROUND(SQRT(POW(p1.x - p2.x, 2) + POW(p1.y - p2.y, 2)), 2) AS shortest FROM Point2D AS p1, Point2D AS p2 diff --git a/solution/0600-0699/0612.Shortest Distance in a Plane/Solution.sql b/solution/0600-0699/0612.Shortest Distance in a Plane/Solution.sql index 0af1db638c9f5..9d4abcdfe721f 100644 --- a/solution/0600-0699/0612.Shortest Distance in a Plane/Solution.sql +++ b/solution/0600-0699/0612.Shortest Distance in a Plane/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT round(sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)), 2) AS shortest +SELECT ROUND(SQRT(POW(p1.x - p2.x, 2) + POW(p1.y - p2.y, 2)), 2) AS shortest FROM Point2D AS p1, Point2D AS p2 diff --git a/solution/0600-0699/0613.Shortest Distance in a Line/README.md b/solution/0600-0699/0613.Shortest Distance in a Line/README.md index 89097ed5228ef..61fecefd34955 100644 --- a/solution/0600-0699/0613.Shortest Distance in a Line/README.md +++ b/solution/0600-0699/0613.Shortest Distance in a Line/README.md @@ -69,7 +69,7 @@ Point 表: ```sql # Write your MySQL query statement below -SELECT min(p2.x - p1.x) AS shortest +SELECT MIN(p2.x - p1.x) AS shortest FROM Point AS p1 JOIN Point AS p2 ON p1.x < p2.x; @@ -77,7 +77,7 @@ FROM ```sql # Write your MySQL query statement below -SELECT x - lag(x) OVER (ORDER BY x) AS shortest +SELECT x - LAG(x) OVER (ORDER BY x) AS shortest FROM Point ORDER BY 1 LIMIT 1, 1; diff --git a/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md b/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md index 6adfefbd7ddf5..0b74932392d10 100644 --- a/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md +++ b/solution/0600-0699/0613.Shortest Distance in a Line/README_EN.md @@ -63,7 +63,7 @@ We can use a window function to sort the points in the table by their $x$ values ```sql # Write your MySQL query statement below -SELECT min(p2.x - p1.x) AS shortest +SELECT MIN(p2.x - p1.x) AS shortest FROM Point AS p1 JOIN Point AS p2 ON p1.x < p2.x; @@ -71,7 +71,7 @@ FROM ```sql # Write your MySQL query statement below -SELECT x - lag(x) OVER (ORDER BY x) AS shortest +SELECT x - LAG(x) OVER (ORDER BY x) AS shortest FROM Point ORDER BY 1 LIMIT 1, 1; diff --git a/solution/0600-0699/0613.Shortest Distance in a Line/Solution.sql b/solution/0600-0699/0613.Shortest Distance in a Line/Solution.sql index fb04d9632c873..9f56e6650b656 100644 --- a/solution/0600-0699/0613.Shortest Distance in a Line/Solution.sql +++ b/solution/0600-0699/0613.Shortest Distance in a Line/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT min(p2.x - p1.x) AS shortest +SELECT MIN(p2.x - p1.x) AS shortest FROM Point AS p1 JOIN Point AS p2 ON p1.x < p2.x; diff --git a/solution/0600-0699/0614.Second Degree Follower/README.md b/solution/0600-0699/0614.Second Degree Follower/README.md index 5400aefc7414b..fdf748c1f7f88 100644 --- a/solution/0600-0699/0614.Second Degree Follower/README.md +++ b/solution/0600-0699/0614.Second Degree Follower/README.md @@ -79,7 +79,7 @@ WITH Follow AS f1 JOIN Follow AS f2 ON f1.follower = f2.followee ) -SELECT follower, count(DISTINCT followee) AS num +SELECT follower, COUNT(DISTINCT followee) AS num FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/0600-0699/0614.Second Degree Follower/README_EN.md b/solution/0600-0699/0614.Second Degree Follower/README_EN.md index c1f85f55bda30..eea159abdaaa9 100644 --- a/solution/0600-0699/0614.Second Degree Follower/README_EN.md +++ b/solution/0600-0699/0614.Second Degree Follower/README_EN.md @@ -75,7 +75,7 @@ WITH Follow AS f1 JOIN Follow AS f2 ON f1.follower = f2.followee ) -SELECT follower, count(DISTINCT followee) AS num +SELECT follower, COUNT(DISTINCT followee) AS num FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/0600-0699/0614.Second Degree Follower/Solution.sql b/solution/0600-0699/0614.Second Degree Follower/Solution.sql index 7fc84d6e07401..48d93e1fd32a3 100644 --- a/solution/0600-0699/0614.Second Degree Follower/Solution.sql +++ b/solution/0600-0699/0614.Second Degree Follower/Solution.sql @@ -6,7 +6,7 @@ WITH Follow AS f1 JOIN Follow AS f2 ON f1.follower = f2.followee ) -SELECT follower, count(DISTINCT followee) AS num +SELECT follower, COUNT(DISTINCT followee) AS num FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/0600-0699/0615.Average Salary Departments VS Company/README.md b/solution/0600-0699/0615.Average Salary Departments VS Company/README.md index 034bf3947b27c..7cdcc605fb0ce 100644 --- a/solution/0600-0699/0615.Average Salary Departments VS Company/README.md +++ b/solution/0600-0699/0615.Average Salary Departments VS Company/README.md @@ -97,10 +97,10 @@ Employee 表: WITH t AS ( SELECT - date_format(pay_date, '%Y-%m') AS pay_month, + DATE_FORMAT(pay_date, '%Y-%m') AS pay_month, department_id, - avg(amount) OVER (PARTITION BY pay_date) AS company_avg_amount, - avg(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg_amount + AVG(amount) OVER (PARTITION BY pay_date) AS company_avg_amount, + AVG(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg_amount FROM Salary AS s JOIN Employee AS e ON s.employee_id = e.employee_id @@ -127,18 +127,18 @@ WITH ), T AS ( SELECT - date_format(pay_date, '%Y-%m') AS pay_month, + DATE_FORMAT(pay_date, '%Y-%m') AS pay_month, department_id, - avg(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, - avg(amount) OVER (PARTITION BY pay_date) AS company_avg + AVG(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, + AVG(amount) OVER (PARTITION BY pay_date) AS company_avg FROM S ) SELECT pay_month, department_id, CASE - WHEN avg(department_avg) > avg(company_avg) THEN 'higher' - WHEN avg(department_avg) < avg(company_avg) THEN 'lower' + WHEN AVG(department_avg) > AVG(company_avg) THEN 'higher' + WHEN AVG(department_avg) < AVG(company_avg) THEN 'lower' ELSE 'same' END AS comparison FROM T diff --git a/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md b/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md index c66e4dae75671..2ac2c26fae64e 100644 --- a/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md +++ b/solution/0600-0699/0615.Average Salary Departments VS Company/README_EN.md @@ -95,10 +95,10 @@ With he same formula for the average salary comparison in February, the result i WITH t AS ( SELECT - date_format(pay_date, '%Y-%m') AS pay_month, + DATE_FORMAT(pay_date, '%Y-%m') AS pay_month, department_id, - avg(amount) OVER (PARTITION BY pay_date) AS company_avg_amount, - avg(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg_amount + AVG(amount) OVER (PARTITION BY pay_date) AS company_avg_amount, + AVG(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg_amount FROM Salary AS s JOIN Employee AS e ON s.employee_id = e.employee_id @@ -125,18 +125,18 @@ WITH ), T AS ( SELECT - date_format(pay_date, '%Y-%m') AS pay_month, + DATE_FORMAT(pay_date, '%Y-%m') AS pay_month, department_id, - avg(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, - avg(amount) OVER (PARTITION BY pay_date) AS company_avg + AVG(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, + AVG(amount) OVER (PARTITION BY pay_date) AS company_avg FROM S ) SELECT pay_month, department_id, CASE - WHEN avg(department_avg) > avg(company_avg) THEN 'higher' - WHEN avg(department_avg) < avg(company_avg) THEN 'lower' + WHEN AVG(department_avg) > AVG(company_avg) THEN 'higher' + WHEN AVG(department_avg) < AVG(company_avg) THEN 'lower' ELSE 'same' END AS comparison FROM T diff --git a/solution/0600-0699/0615.Average Salary Departments VS Company/Solution.sql b/solution/0600-0699/0615.Average Salary Departments VS Company/Solution.sql index 5dd16a896821a..43c33cc8e0e6f 100644 --- a/solution/0600-0699/0615.Average Salary Departments VS Company/Solution.sql +++ b/solution/0600-0699/0615.Average Salary Departments VS Company/Solution.sql @@ -8,18 +8,18 @@ WITH ), T AS ( SELECT - date_format(pay_date, '%Y-%m') AS pay_month, + DATE_FORMAT(pay_date, '%Y-%m') AS pay_month, department_id, - avg(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, - avg(amount) OVER (PARTITION BY pay_date) AS company_avg + AVG(amount) OVER (PARTITION BY pay_date, department_id) AS department_avg, + AVG(amount) OVER (PARTITION BY pay_date) AS company_avg FROM S ) SELECT pay_month, department_id, CASE - WHEN avg(department_avg) > avg(company_avg) THEN 'higher' - WHEN avg(department_avg) < avg(company_avg) THEN 'lower' + WHEN AVG(department_avg) > AVG(company_avg) THEN 'higher' + WHEN AVG(department_avg) < AVG(company_avg) THEN 'lower' ELSE 'same' END AS comparison FROM T diff --git a/solution/0600-0699/0618.Students Report By Geography/README.md b/solution/0600-0699/0618.Students Report By Geography/README.md index cd3e4656640aa..ad9cf0de0152f 100644 --- a/solution/0600-0699/0618.Students Report By Geography/README.md +++ b/solution/0600-0699/0618.Students Report By Geography/README.md @@ -74,16 +74,16 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY continent ORDER BY name ) AS rk FROM Student ) SELECT - max(if(continent = 'America', name, NULL)) AS 'America', - max(if(continent = 'Asia', name, NULL)) AS 'Asia', - max(if(continent = 'Europe', name, NULL)) AS 'Europe' + MAX(IF(continent = 'America', name, NULL)) AS 'America', + MAX(IF(continent = 'Asia', name, NULL)) AS 'Asia', + MAX(IF(continent = 'Europe', name, NULL)) AS 'Europe' FROM T GROUP BY rk; ``` diff --git a/solution/0600-0699/0618.Students Report By Geography/README_EN.md b/solution/0600-0699/0618.Students Report By Geography/README_EN.md index 80634d13421c9..bfb9b28981bc0 100644 --- a/solution/0600-0699/0618.Students Report By Geography/README_EN.md +++ b/solution/0600-0699/0618.Students Report By Geography/README_EN.md @@ -65,16 +65,16 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY continent ORDER BY name ) AS rk FROM Student ) SELECT - max(if(continent = 'America', name, NULL)) AS 'America', - max(if(continent = 'Asia', name, NULL)) AS 'Asia', - max(if(continent = 'Europe', name, NULL)) AS 'Europe' + MAX(IF(continent = 'America', name, NULL)) AS 'America', + MAX(IF(continent = 'Asia', name, NULL)) AS 'Asia', + MAX(IF(continent = 'Europe', name, NULL)) AS 'Europe' FROM T GROUP BY rk; ``` diff --git a/solution/0600-0699/0618.Students Report By Geography/Solution.sql b/solution/0600-0699/0618.Students Report By Geography/Solution.sql index 527785f1431e0..8e0ba046f6697 100644 --- a/solution/0600-0699/0618.Students Report By Geography/Solution.sql +++ b/solution/0600-0699/0618.Students Report By Geography/Solution.sql @@ -3,15 +3,15 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY continent ORDER BY name ) AS rk FROM Student ) SELECT - max(if(continent = 'America', name, NULL)) AS 'America', - max(if(continent = 'Asia', name, NULL)) AS 'Asia', - max(if(continent = 'Europe', name, NULL)) AS 'Europe' + MAX(IF(continent = 'America', name, NULL)) AS 'America', + MAX(IF(continent = 'Asia', name, NULL)) AS 'Asia', + MAX(IF(continent = 'Europe', name, NULL)) AS 'Europe' FROM T GROUP BY rk; diff --git a/solution/0600-0699/0619.Biggest Single Number/README.md b/solution/0600-0699/0619.Biggest Single Number/README.md index 405ee75761ca0..cbb64e6a165dd 100644 --- a/solution/0600-0699/0619.Biggest Single Number/README.md +++ b/solution/0600-0699/0619.Biggest Single Number/README.md @@ -97,13 +97,13 @@ MyNumbers table: ```sql # Write your MySQL query statement below -SELECT max(num) AS num +SELECT MAX(num) AS num FROM ( SELECT num FROM MyNumbers GROUP BY num - HAVING count(1) = 1 + HAVING COUNT(1) = 1 ) AS t; ``` @@ -111,7 +111,7 @@ FROM # Write your MySQL query statement below SELECT CASE - WHEN count(1) = 1 THEN num + WHEN COUNT(1) = 1 THEN num ELSE NULL END AS num FROM MyNumbers diff --git a/solution/0600-0699/0619.Biggest Single Number/README_EN.md b/solution/0600-0699/0619.Biggest Single Number/README_EN.md index f76684767b501..3bd9e0e9bfe03 100644 --- a/solution/0600-0699/0619.Biggest Single Number/README_EN.md +++ b/solution/0600-0699/0619.Biggest Single Number/README_EN.md @@ -85,13 +85,13 @@ MyNumbers table: ```sql # Write your MySQL query statement below -SELECT max(num) AS num +SELECT MAX(num) AS num FROM ( SELECT num FROM MyNumbers GROUP BY num - HAVING count(1) = 1 + HAVING COUNT(1) = 1 ) AS t; ``` @@ -99,7 +99,7 @@ FROM # Write your MySQL query statement below SELECT CASE - WHEN count(1) = 1 THEN num + WHEN COUNT(1) = 1 THEN num ELSE NULL END AS num FROM MyNumbers diff --git a/solution/0600-0699/0619.Biggest Single Number/Solution.sql b/solution/0600-0699/0619.Biggest Single Number/Solution.sql index 445f06644a945..1ae9adc9b5eb9 100644 --- a/solution/0600-0699/0619.Biggest Single Number/Solution.sql +++ b/solution/0600-0699/0619.Biggest Single Number/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT CASE - WHEN count(1) = 1 THEN num + WHEN COUNT(1) = 1 THEN num ELSE NULL END AS num FROM MyNumbers diff --git a/solution/0600-0699/0626.Exchange Seats/README.md b/solution/0600-0699/0626.Exchange Seats/README.md index 2cce3b09051ed..6fd817c4edbf7 100644 --- a/solution/0600-0699/0626.Exchange Seats/README.md +++ b/solution/0600-0699/0626.Exchange Seats/README.md @@ -94,7 +94,7 @@ ORDER BY id; ```sql # Write your MySQL query statement below select - rank() over( + RANK() over( order by (id -1) ^ 1 ) as id, @@ -108,7 +108,7 @@ from SELECT CASE WHEN id & 1 = 0 THEN id - 1 - WHEN row_number() OVER (ORDER BY id) != count(id) OVER () THEN id + 1 + WHEN ROW_NUMBER() OVER (ORDER BY id) != COUNT(id) OVER () THEN id + 1 ELSE id END AS id, student diff --git a/solution/0600-0699/0626.Exchange Seats/README_EN.md b/solution/0600-0699/0626.Exchange Seats/README_EN.md index ed6891d5f544b..3ffc3f5ebf818 100644 --- a/solution/0600-0699/0626.Exchange Seats/README_EN.md +++ b/solution/0600-0699/0626.Exchange Seats/README_EN.md @@ -90,7 +90,7 @@ ORDER BY id; ```sql # Write your MySQL query statement below select - rank() over( + RANK() over( order by (id -1) ^ 1 ) as id, @@ -104,7 +104,7 @@ from SELECT CASE WHEN id & 1 = 0 THEN id - 1 - WHEN row_number() OVER (ORDER BY id) != count(id) OVER () THEN id + 1 + WHEN ROW_NUMBER() OVER (ORDER BY id) != COUNT(id) OVER () THEN id + 1 ELSE id END AS id, student diff --git a/solution/0600-0699/0627.Swap Salary/README.md b/solution/0600-0699/0627.Swap Salary/README.md index 36dc0d44a84e1..f700b7450ebdd 100644 --- a/solution/0600-0699/0627.Swap Salary/README.md +++ b/solution/0600-0699/0627.Swap Salary/README.md @@ -81,7 +81,7 @@ END; ```sql # Write your MySQL query statement below UPDATE Salary -SET sex = if(sex = 'f', 'm', 'f'); +SET sex = IF(sex = 'f', 'm', 'f'); ``` diff --git a/solution/0600-0699/0627.Swap Salary/README_EN.md b/solution/0600-0699/0627.Swap Salary/README_EN.md index 5446242cc7a9f..d761752363b0c 100644 --- a/solution/0600-0699/0627.Swap Salary/README_EN.md +++ b/solution/0600-0699/0627.Swap Salary/README_EN.md @@ -73,7 +73,7 @@ END; ```sql # Write your MySQL query statement below UPDATE Salary -SET sex = if(sex = 'f', 'm', 'f'); +SET sex = IF(sex = 'f', 'm', 'f'); ``` diff --git a/solution/0600-0699/0627.Swap Salary/Solution.sql b/solution/0600-0699/0627.Swap Salary/Solution.sql index 5084524b81cf0..91ff515211582 100644 --- a/solution/0600-0699/0627.Swap Salary/Solution.sql +++ b/solution/0600-0699/0627.Swap Salary/Solution.sql @@ -1,3 +1,3 @@ # Write your MySQL query statement below UPDATE Salary -SET sex = if(sex = 'f', 'm', 'f'); +SET sex = IF(sex = 'f', 'm', 'f'); diff --git a/solution/1000-1099/1045.Customers Who Bought All Products/README.md b/solution/1000-1099/1045.Customers Who Bought All Products/README.md index bc873ff81fdef..173bef646cd48 100644 --- a/solution/1000-1099/1045.Customers Who Bought All Products/README.md +++ b/solution/1000-1099/1045.Customers Who Bought All Products/README.md @@ -90,7 +90,7 @@ Product 表: SELECT customer_id FROM Customer GROUP BY 1 -HAVING count(DISTINCT product_key) = (SELECT count(1) FROM Product); +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(1) FROM Product); ``` diff --git a/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md b/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md index ccedd64d42842..668ff2957be6d 100644 --- a/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md +++ b/solution/1000-1099/1045.Customers Who Bought All Products/README_EN.md @@ -83,7 +83,7 @@ The customers who bought all the products (5 and 6) are customers with IDs 1 and SELECT customer_id FROM Customer GROUP BY 1 -HAVING count(DISTINCT product_key) = (SELECT count(1) FROM Product); +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(1) FROM Product); ``` diff --git a/solution/1000-1099/1045.Customers Who Bought All Products/Solution.sql b/solution/1000-1099/1045.Customers Who Bought All Products/Solution.sql index 6ec5c9985d884..b1e807a661ebc 100644 --- a/solution/1000-1099/1045.Customers Who Bought All Products/Solution.sql +++ b/solution/1000-1099/1045.Customers Who Bought All Products/Solution.sql @@ -2,4 +2,4 @@ SELECT customer_id FROM Customer GROUP BY 1 -HAVING count(DISTINCT product_key) = (SELECT count(1) FROM Product); +HAVING COUNT(DISTINCT product_key) = (SELECT COUNT(1) FROM Product); diff --git a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md index 8c85d23ebead2..7dde7ff3bf88b 100644 --- a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md +++ b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README.md @@ -67,7 +67,7 @@ ActorDirector 表: SELECT actor_id, director_id FROM ActorDirector GROUP BY 1, 2 -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md index 87f42913c00bb..0606cb8a3031d 100644 --- a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md +++ b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/README_EN.md @@ -66,7 +66,7 @@ We can use the `GROUP BY` statement to group the data by the `actor_id` and `dir SELECT actor_id, director_id FROM ActorDirector GROUP BY 1, 2 -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/Solution.sql b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/Solution.sql index 37c825437b465..37d31ba103e43 100644 --- a/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/Solution.sql +++ b/solution/1000-1099/1050.Actors and Directors Who Cooperated At Least Three Times/Solution.sql @@ -2,4 +2,4 @@ SELECT actor_id, director_id FROM ActorDirector GROUP BY 1, 2 -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; diff --git a/solution/1000-1099/1069.Product Sales Analysis II/README.md b/solution/1000-1099/1069.Product Sales Analysis II/README.md index 65718b7935956..6614f94c0d0af 100644 --- a/solution/1000-1099/1069.Product Sales Analysis II/README.md +++ b/solution/1000-1099/1069.Product Sales Analysis II/README.md @@ -89,7 +89,7 @@ Product 表: ```sql # Write your MySQL query statement below -SELECT product_id, sum(quantity) AS total_quantity +SELECT product_id, SUM(quantity) AS total_quantity FROM Sales GROUP BY 1; ``` diff --git a/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md b/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md index a73f44520bf34..06c9a926b2241 100644 --- a/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md +++ b/solution/1000-1099/1069.Product Sales Analysis II/README_EN.md @@ -83,7 +83,7 @@ Product table: ```sql # Write your MySQL query statement below -SELECT product_id, sum(quantity) AS total_quantity +SELECT product_id, SUM(quantity) AS total_quantity FROM Sales GROUP BY 1; ``` diff --git a/solution/1000-1099/1069.Product Sales Analysis II/Solution.sql b/solution/1000-1099/1069.Product Sales Analysis II/Solution.sql index 509e32bf47165..09864a8a1b7af 100644 --- a/solution/1000-1099/1069.Product Sales Analysis II/Solution.sql +++ b/solution/1000-1099/1069.Product Sales Analysis II/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below -SELECT product_id, sum(quantity) AS total_quantity +SELECT product_id, SUM(quantity) AS total_quantity FROM Sales GROUP BY 1; diff --git a/solution/1000-1099/1070.Product Sales Analysis III/README.md b/solution/1000-1099/1070.Product Sales Analysis III/README.md index 81abd4682e212..d4415cfc364d0 100644 --- a/solution/1000-1099/1070.Product Sales Analysis III/README.md +++ b/solution/1000-1099/1070.Product Sales Analysis III/README.md @@ -96,7 +96,7 @@ WHERE (product_id, year) IN ( SELECT product_id, - min(year) AS year + MIN(year) AS year FROM Sales GROUP BY product_id ); @@ -108,7 +108,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY year ) AS rk diff --git a/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md b/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md index e7b71be93c7af..00ea082ef49ea 100644 --- a/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md +++ b/solution/1000-1099/1070.Product Sales Analysis III/README_EN.md @@ -93,7 +93,7 @@ WHERE (product_id, year) IN ( SELECT product_id, - min(year) AS year + MIN(year) AS year FROM Sales GROUP BY product_id ); @@ -105,7 +105,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY year ) AS rk diff --git a/solution/1000-1099/1070.Product Sales Analysis III/Solution.sql b/solution/1000-1099/1070.Product Sales Analysis III/Solution.sql index e2d64dadff69b..a4248aa86df71 100644 --- a/solution/1000-1099/1070.Product Sales Analysis III/Solution.sql +++ b/solution/1000-1099/1070.Product Sales Analysis III/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY year ) AS rk diff --git a/solution/1000-1099/1075.Project Employees I/README.md b/solution/1000-1099/1075.Project Employees I/README.md index 2fae001bb67cc..9c75a27f9f432 100644 --- a/solution/1000-1099/1075.Project Employees I/README.md +++ b/solution/1000-1099/1075.Project Employees I/README.md @@ -84,7 +84,7 @@ Result 表: ```sql # Write your MySQL query statement -SELECT project_id, round(avg(experience_years), 2) AS average_years +SELECT project_id, ROUND(AVG(experience_years), 2) AS average_years FROM Project JOIN Employee USING (employee_id) diff --git a/solution/1000-1099/1075.Project Employees I/README_EN.md b/solution/1000-1099/1075.Project Employees I/README_EN.md index bc699f46fc5d5..cd179cb4a6455 100644 --- a/solution/1000-1099/1075.Project Employees I/README_EN.md +++ b/solution/1000-1099/1075.Project Employees I/README_EN.md @@ -84,7 +84,7 @@ Employee table: ```sql # Write your MySQL query statement -SELECT project_id, round(avg(experience_years), 2) AS average_years +SELECT project_id, ROUND(AVG(experience_years), 2) AS average_years FROM Project JOIN Employee USING (employee_id) diff --git a/solution/1000-1099/1075.Project Employees I/Solution.sql b/solution/1000-1099/1075.Project Employees I/Solution.sql index 10bdbc392bbde..d99e15c1cc4dc 100644 --- a/solution/1000-1099/1075.Project Employees I/Solution.sql +++ b/solution/1000-1099/1075.Project Employees I/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement -SELECT project_id, round(avg(experience_years), 2) AS average_years +SELECT project_id, ROUND(AVG(experience_years), 2) AS average_years FROM Project JOIN Employee USING (employee_id) diff --git a/solution/1000-1099/1076.Project Employees II/README.md b/solution/1000-1099/1076.Project Employees II/README.md index 8b3edd1f9e41f..33045f0bb20d5 100644 --- a/solution/1000-1099/1076.Project Employees II/README.md +++ b/solution/1000-1099/1076.Project Employees II/README.md @@ -89,8 +89,8 @@ SELECT project_id FROM Project GROUP BY 1 HAVING - count(1) >= all( - SELECT count(1) + COUNT(1) >= all( + SELECT COUNT(1) FROM Project GROUP BY project_id ); @@ -102,7 +102,7 @@ WITH T AS ( SELECT project_id, - rank() OVER (ORDER BY count(employee_id) DESC) AS rk + RANK() OVER (ORDER BY COUNT(employee_id) DESC) AS rk FROM Project GROUP BY 1 ) diff --git a/solution/1000-1099/1076.Project Employees II/README_EN.md b/solution/1000-1099/1076.Project Employees II/README_EN.md index c433e8bd1bfb6..9a94746993527 100644 --- a/solution/1000-1099/1076.Project Employees II/README_EN.md +++ b/solution/1000-1099/1076.Project Employees II/README_EN.md @@ -87,8 +87,8 @@ SELECT project_id FROM Project GROUP BY 1 HAVING - count(1) >= all( - SELECT count(1) + COUNT(1) >= all( + SELECT COUNT(1) FROM Project GROUP BY project_id ); @@ -100,7 +100,7 @@ WITH T AS ( SELECT project_id, - rank() OVER (ORDER BY count(employee_id) DESC) AS rk + RANK() OVER (ORDER BY COUNT(employee_id) DESC) AS rk FROM Project GROUP BY 1 ) diff --git a/solution/1000-1099/1076.Project Employees II/Solution.sql b/solution/1000-1099/1076.Project Employees II/Solution.sql index 33764ab346fcb..fe5891819ae71 100644 --- a/solution/1000-1099/1076.Project Employees II/Solution.sql +++ b/solution/1000-1099/1076.Project Employees II/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT project_id, - rank() OVER (ORDER BY count(employee_id) DESC) AS rk + RANK() OVER (ORDER BY COUNT(employee_id) DESC) AS rk FROM Project GROUP BY 1 ) diff --git a/solution/1000-1099/1077.Project Employees III/README.md b/solution/1000-1099/1077.Project Employees III/README.md index 096236399a629..1dfeae3400ca8 100644 --- a/solution/1000-1099/1077.Project Employees III/README.md +++ b/solution/1000-1099/1077.Project Employees III/README.md @@ -96,7 +96,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY project_id ORDER BY experience_years DESC ) AS rk diff --git a/solution/1000-1099/1077.Project Employees III/README_EN.md b/solution/1000-1099/1077.Project Employees III/README_EN.md index 982eaac83bdc6..c7094cff98efa 100644 --- a/solution/1000-1099/1077.Project Employees III/README_EN.md +++ b/solution/1000-1099/1077.Project Employees III/README_EN.md @@ -93,7 +93,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY project_id ORDER BY experience_years DESC ) AS rk diff --git a/solution/1000-1099/1077.Project Employees III/Solution.sql b/solution/1000-1099/1077.Project Employees III/Solution.sql index a1cb136371da7..17756b281e022 100644 --- a/solution/1000-1099/1077.Project Employees III/Solution.sql +++ b/solution/1000-1099/1077.Project Employees III/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY project_id ORDER BY experience_years DESC ) AS rk diff --git a/solution/1000-1099/1082.Sales Analysis I/README.md b/solution/1000-1099/1082.Sales Analysis I/README.md index 5e2e3fe6b7df7..7bdb1c698fba2 100644 --- a/solution/1000-1099/1082.Sales Analysis I/README.md +++ b/solution/1000-1099/1082.Sales Analysis I/README.md @@ -105,8 +105,8 @@ WITH T AS ( SELECT seller_id, - sum(price) AS tot, - rank() OVER (ORDER BY sum(price) DESC) AS rk + SUM(price) AS tot, + RANK() OVER (ORDER BY SUM(price) DESC) AS rk FROM Sales GROUP BY seller_id ) diff --git a/solution/1000-1099/1082.Sales Analysis I/README_EN.md b/solution/1000-1099/1082.Sales Analysis I/README_EN.md index c61a6ff48ff57..4252d408c2345 100644 --- a/solution/1000-1099/1082.Sales Analysis I/README_EN.md +++ b/solution/1000-1099/1082.Sales Analysis I/README_EN.md @@ -101,8 +101,8 @@ WITH T AS ( SELECT seller_id, - sum(price) AS tot, - rank() OVER (ORDER BY sum(price) DESC) AS rk + SUM(price) AS tot, + RANK() OVER (ORDER BY SUM(price) DESC) AS rk FROM Sales GROUP BY seller_id ) diff --git a/solution/1000-1099/1082.Sales Analysis I/Solution.sql b/solution/1000-1099/1082.Sales Analysis I/Solution.sql index cebc533bbd165..9bee619e096dd 100644 --- a/solution/1000-1099/1082.Sales Analysis I/Solution.sql +++ b/solution/1000-1099/1082.Sales Analysis I/Solution.sql @@ -2,8 +2,8 @@ WITH T AS ( SELECT seller_id, - sum(price) AS tot, - rank() OVER (ORDER BY sum(price) DESC) AS rk + SUM(price) AS tot, + RANK() OVER (ORDER BY SUM(price) DESC) AS rk FROM Sales GROUP BY seller_id ) diff --git a/solution/1000-1099/1083.Sales Analysis II/README.md b/solution/1000-1099/1083.Sales Analysis II/README.md index a88d8ecf940bc..d4cd15c379029 100644 --- a/solution/1000-1099/1083.Sales Analysis II/README.md +++ b/solution/1000-1099/1083.Sales Analysis II/README.md @@ -100,7 +100,7 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING sum(product_name = 'S8') > 0 AND sum(product_name = 'iPhone') = 0; +HAVING SUM(product_name = 'S8') > 0 AND SUM(product_name = 'iPhone') = 0; ``` diff --git a/solution/1000-1099/1083.Sales Analysis II/README_EN.md b/solution/1000-1099/1083.Sales Analysis II/README_EN.md index 139d7729fc47b..619de6881529d 100644 --- a/solution/1000-1099/1083.Sales Analysis II/README_EN.md +++ b/solution/1000-1099/1083.Sales Analysis II/README_EN.md @@ -90,7 +90,7 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING sum(product_name = 'S8') > 0 AND sum(product_name = 'iPhone') = 0; +HAVING SUM(product_name = 'S8') > 0 AND SUM(product_name = 'iPhone') = 0; ``` diff --git a/solution/1000-1099/1083.Sales Analysis II/Solution.sql b/solution/1000-1099/1083.Sales Analysis II/Solution.sql index 3823ddb590201..32cfc7b44af14 100644 --- a/solution/1000-1099/1083.Sales Analysis II/Solution.sql +++ b/solution/1000-1099/1083.Sales Analysis II/Solution.sql @@ -4,4 +4,4 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING sum(product_name = 'S8') > 0 AND sum(product_name = 'iPhone') = 0; +HAVING SUM(product_name = 'S8') > 0 AND SUM(product_name = 'iPhone') = 0; diff --git a/solution/1000-1099/1084.Sales Analysis III/README.md b/solution/1000-1099/1084.Sales Analysis III/README.md index 8a6f6ae57ba8b..44a00d317897a 100644 --- a/solution/1000-1099/1084.Sales Analysis III/README.md +++ b/solution/1000-1099/1084.Sales Analysis III/README.md @@ -100,7 +100,7 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING count(1) = sum(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); +HAVING COUNT(1) = SUM(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); ``` diff --git a/solution/1000-1099/1084.Sales Analysis III/README_EN.md b/solution/1000-1099/1084.Sales Analysis III/README_EN.md index e3ade7c73f009..6a4e8f2173d6d 100644 --- a/solution/1000-1099/1084.Sales Analysis III/README_EN.md +++ b/solution/1000-1099/1084.Sales Analysis III/README_EN.md @@ -92,7 +92,7 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING count(1) = sum(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); +HAVING COUNT(1) = SUM(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); ``` diff --git a/solution/1000-1099/1084.Sales Analysis III/Solution.sql b/solution/1000-1099/1084.Sales Analysis III/Solution.sql index 37dba67a0543a..4912bb952e27e 100644 --- a/solution/1000-1099/1084.Sales Analysis III/Solution.sql +++ b/solution/1000-1099/1084.Sales Analysis III/Solution.sql @@ -4,4 +4,4 @@ FROM Sales JOIN Product USING (product_id) GROUP BY 1 -HAVING count(1) = sum(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); +HAVING COUNT(1) = SUM(sale_date BETWEEN '2019-01-01' AND '2019-03-31'); diff --git a/solution/1000-1099/1097.Game Play Analysis V/README.md b/solution/1000-1099/1097.Game Play Analysis V/README.md index 154500b4b2632..3ffbf5e628de1 100644 --- a/solution/1000-1099/1097.Game Play Analysis V/README.md +++ b/solution/1000-1099/1097.Game Play Analysis V/README.md @@ -77,14 +77,14 @@ WITH SELECT player_id, event_date, - min(event_date) OVER (PARTITION BY player_id) AS install_dt + MIN(event_date) OVER (PARTITION BY player_id) AS install_dt FROM Activity ) SELECT install_dt, - count(DISTINCT player_id) AS installs, - round( - sum(datediff(event_date, install_dt) = 1) / count(DISTINCT player_id), + COUNT(DISTINCT player_id) AS installs, + ROUND( + SUM(DATEDIFF(event_date, install_dt) = 1) / COUNT(DISTINCT player_id), 2 ) AS day1_retention FROM T diff --git a/solution/1000-1099/1097.Game Play Analysis V/README_EN.md b/solution/1000-1099/1097.Game Play Analysis V/README_EN.md index 7d69e8e2f2cf4..00406d1ece260 100644 --- a/solution/1000-1099/1097.Game Play Analysis V/README_EN.md +++ b/solution/1000-1099/1097.Game Play Analysis V/README_EN.md @@ -72,14 +72,14 @@ WITH SELECT player_id, event_date, - min(event_date) OVER (PARTITION BY player_id) AS install_dt + MIN(event_date) OVER (PARTITION BY player_id) AS install_dt FROM Activity ) SELECT install_dt, - count(DISTINCT player_id) AS installs, - round( - sum(datediff(event_date, install_dt) = 1) / count(DISTINCT player_id), + COUNT(DISTINCT player_id) AS installs, + ROUND( + SUM(DATEDIFF(event_date, install_dt) = 1) / COUNT(DISTINCT player_id), 2 ) AS day1_retention FROM T diff --git a/solution/1000-1099/1097.Game Play Analysis V/Solution.sql b/solution/1000-1099/1097.Game Play Analysis V/Solution.sql index 979827c210872..ca813b24003ce 100644 --- a/solution/1000-1099/1097.Game Play Analysis V/Solution.sql +++ b/solution/1000-1099/1097.Game Play Analysis V/Solution.sql @@ -4,14 +4,14 @@ WITH SELECT player_id, event_date, - min(event_date) OVER (PARTITION BY player_id) AS install_dt + MIN(event_date) OVER (PARTITION BY player_id) AS install_dt FROM Activity ) SELECT install_dt, - count(DISTINCT player_id) AS installs, - round( - sum(datediff(event_date, install_dt) = 1) / count(DISTINCT player_id), + COUNT(DISTINCT player_id) AS installs, + ROUND( + SUM(DATEDIFF(event_date, install_dt) = 1) / COUNT(DISTINCT player_id), 2 ) AS day1_retention FROM T diff --git a/solution/1000-1099/1098.Unpopular Books/README.md b/solution/1000-1099/1098.Unpopular Books/README.md index dd3f4846aa883..971afbc3f4b4b 100644 --- a/solution/1000-1099/1098.Unpopular Books/README.md +++ b/solution/1000-1099/1098.Unpopular Books/README.md @@ -96,7 +96,7 @@ FROM LEFT JOIN Orders USING (book_id) WHERE available_from < '2019-05-23' GROUP BY 1 -HAVING sum(if(dispatch_date >= '2018-06-23', quantity, 0)) < 10; +HAVING SUM(IF(dispatch_date >= '2018-06-23', quantity, 0)) < 10; ``` diff --git a/solution/1000-1099/1098.Unpopular Books/README_EN.md b/solution/1000-1099/1098.Unpopular Books/README_EN.md index 68d8162e7c0de..e61f8dc371497 100644 --- a/solution/1000-1099/1098.Unpopular Books/README_EN.md +++ b/solution/1000-1099/1098.Unpopular Books/README_EN.md @@ -93,7 +93,7 @@ FROM LEFT JOIN Orders USING (book_id) WHERE available_from < '2019-05-23' GROUP BY 1 -HAVING sum(if(dispatch_date >= '2018-06-23', quantity, 0)) < 10; +HAVING SUM(IF(dispatch_date >= '2018-06-23', quantity, 0)) < 10; ``` diff --git a/solution/1000-1099/1098.Unpopular Books/Solution.sql b/solution/1000-1099/1098.Unpopular Books/Solution.sql index 1fc3ea8951b08..2cebd8b4f67e3 100644 --- a/solution/1000-1099/1098.Unpopular Books/Solution.sql +++ b/solution/1000-1099/1098.Unpopular Books/Solution.sql @@ -5,4 +5,4 @@ FROM LEFT JOIN Orders USING (book_id) WHERE available_from < '2019-05-23' GROUP BY 1 -HAVING sum(if(dispatch_date >= '2018-06-23', quantity, 0)) < 10; +HAVING SUM(IF(dispatch_date >= '2018-06-23', quantity, 0)) < 10; diff --git a/solution/1100-1199/1107.New Users Daily Count/README.md b/solution/1100-1199/1107.New Users Daily Count/README.md index aa1d982c791b1..68dbf6c463bd1 100644 --- a/solution/1100-1199/1107.New Users Daily Count/README.md +++ b/solution/1100-1199/1107.New Users Daily Count/README.md @@ -83,13 +83,13 @@ WITH T AS ( SELECT user_id, - min(activity_date) OVER (PARTITION BY user_id) AS login_date + MIN(activity_date) OVER (PARTITION BY user_id) AS login_date FROM Traffic WHERE activity = 'login' ) -SELECT login_date, count(DISTINCT user_id) AS user_count +SELECT login_date, COUNT(DISTINCT user_id) AS user_count FROM T -WHERE datediff('2019-06-30', login_date) <= 90 +WHERE DATEDIFF('2019-06-30', login_date) <= 90 GROUP BY 1; ``` diff --git a/solution/1100-1199/1107.New Users Daily Count/README_EN.md b/solution/1100-1199/1107.New Users Daily Count/README_EN.md index 985a2450c33fd..f9b5074a78346 100644 --- a/solution/1100-1199/1107.New Users Daily Count/README_EN.md +++ b/solution/1100-1199/1107.New Users Daily Count/README_EN.md @@ -75,13 +75,13 @@ WITH T AS ( SELECT user_id, - min(activity_date) OVER (PARTITION BY user_id) AS login_date + MIN(activity_date) OVER (PARTITION BY user_id) AS login_date FROM Traffic WHERE activity = 'login' ) -SELECT login_date, count(DISTINCT user_id) AS user_count +SELECT login_date, COUNT(DISTINCT user_id) AS user_count FROM T -WHERE datediff('2019-06-30', login_date) <= 90 +WHERE DATEDIFF('2019-06-30', login_date) <= 90 GROUP BY 1; ``` diff --git a/solution/1100-1199/1107.New Users Daily Count/Solution.sql b/solution/1100-1199/1107.New Users Daily Count/Solution.sql index 228dd25c04ce4..c9eaa707742c7 100644 --- a/solution/1100-1199/1107.New Users Daily Count/Solution.sql +++ b/solution/1100-1199/1107.New Users Daily Count/Solution.sql @@ -3,11 +3,11 @@ WITH T AS ( SELECT user_id, - min(activity_date) OVER (PARTITION BY user_id) AS login_date + MIN(activity_date) OVER (PARTITION BY user_id) AS login_date FROM Traffic WHERE activity = 'login' ) -SELECT login_date, count(DISTINCT user_id) AS user_count +SELECT login_date, COUNT(DISTINCT user_id) AS user_count FROM T -WHERE datediff('2019-06-30', login_date) <= 90 +WHERE DATEDIFF('2019-06-30', login_date) <= 90 GROUP BY 1; diff --git a/solution/1100-1199/1112.Highest Grade For Each Student/README.md b/solution/1100-1199/1112.Highest Grade For Each Student/README.md index 49950d43f1dde..429886536dd4a 100644 --- a/solution/1100-1199/1112.Highest Grade For Each Student/README.md +++ b/solution/1100-1199/1112.Highest Grade For Each Student/README.md @@ -76,7 +76,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY student_id ORDER BY grade DESC, course_id ) AS rk @@ -90,11 +90,11 @@ ORDER BY student_id; ```sql # Write your MySQL query statement below -SELECT student_id, min(course_id) AS course_id, grade +SELECT student_id, MIN(course_id) AS course_id, grade FROM Enrollments WHERE (student_id, grade) IN ( - SELECT student_id, max(grade) AS grade + SELECT student_id, MAX(grade) AS grade FROM Enrollments GROUP BY 1 ) diff --git a/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md b/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md index 01dc00922c4a6..5d6dca731aac7 100644 --- a/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md +++ b/solution/1100-1199/1112.Highest Grade For Each Student/README_EN.md @@ -73,7 +73,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY student_id ORDER BY grade DESC, course_id ) AS rk @@ -87,11 +87,11 @@ ORDER BY student_id; ```sql # Write your MySQL query statement below -SELECT student_id, min(course_id) AS course_id, grade +SELECT student_id, MIN(course_id) AS course_id, grade FROM Enrollments WHERE (student_id, grade) IN ( - SELECT student_id, max(grade) AS grade + SELECT student_id, MAX(grade) AS grade FROM Enrollments GROUP BY 1 ) diff --git a/solution/1100-1199/1112.Highest Grade For Each Student/Solution.sql b/solution/1100-1199/1112.Highest Grade For Each Student/Solution.sql index 3ba4c2990958f..8f1d25a898265 100644 --- a/solution/1100-1199/1112.Highest Grade For Each Student/Solution.sql +++ b/solution/1100-1199/1112.Highest Grade For Each Student/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY student_id ORDER BY grade DESC, course_id ) AS rk diff --git a/solution/1100-1199/1113.Reported Posts/README.md b/solution/1100-1199/1113.Reported Posts/README.md index 9c86697e34ad4..8f9b88cb38ba5 100644 --- a/solution/1100-1199/1113.Reported Posts/README.md +++ b/solution/1100-1199/1113.Reported Posts/README.md @@ -76,7 +76,7 @@ Actions table: ```sql # Write your MySQL query statement below -SELECT extra AS report_reason, count(DISTINCT post_id) AS report_count +SELECT extra AS report_reason, COUNT(DISTINCT post_id) AS report_count FROM Actions WHERE action_date = '2019-07-04' AND action = 'report' GROUP BY 1; diff --git a/solution/1100-1199/1113.Reported Posts/README_EN.md b/solution/1100-1199/1113.Reported Posts/README_EN.md index b04bb78687c33..3a704eba98253 100644 --- a/solution/1100-1199/1113.Reported Posts/README_EN.md +++ b/solution/1100-1199/1113.Reported Posts/README_EN.md @@ -71,7 +71,7 @@ Actions table: ```sql # Write your MySQL query statement below -SELECT extra AS report_reason, count(DISTINCT post_id) AS report_count +SELECT extra AS report_reason, COUNT(DISTINCT post_id) AS report_count FROM Actions WHERE action_date = '2019-07-04' AND action = 'report' GROUP BY 1; diff --git a/solution/1100-1199/1113.Reported Posts/Solution.sql b/solution/1100-1199/1113.Reported Posts/Solution.sql index cacb58ff39af6..7b1d6af5757bb 100644 --- a/solution/1100-1199/1113.Reported Posts/Solution.sql +++ b/solution/1100-1199/1113.Reported Posts/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT extra AS report_reason, count(DISTINCT post_id) AS report_count +SELECT extra AS report_reason, COUNT(DISTINCT post_id) AS report_count FROM Actions WHERE action_date = '2019-07-04' AND action = 'report' GROUP BY 1; diff --git a/solution/1100-1199/1126.Active Businesses/README.md b/solution/1100-1199/1126.Active Businesses/README.md index 38fa82f73eab1..5d5031104abfd 100644 --- a/solution/1100-1199/1126.Active Businesses/README.md +++ b/solution/1100-1199/1126.Active Businesses/README.md @@ -95,14 +95,14 @@ WITH T AS ( SELECT business_id, - occurences > avg(occurences) OVER (PARTITION BY event_type) AS mark + occurences > AVG(occurences) OVER (PARTITION BY event_type) AS mark FROM Events ) SELECT business_id FROM T WHERE mark = 1 GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; ``` diff --git a/solution/1100-1199/1126.Active Businesses/README_EN.md b/solution/1100-1199/1126.Active Businesses/README_EN.md index b2cb4636e05c0..512a8dc299c8e 100644 --- a/solution/1100-1199/1126.Active Businesses/README_EN.md +++ b/solution/1100-1199/1126.Active Businesses/README_EN.md @@ -91,14 +91,14 @@ WITH T AS ( SELECT business_id, - occurences > avg(occurences) OVER (PARTITION BY event_type) AS mark + occurences > AVG(occurences) OVER (PARTITION BY event_type) AS mark FROM Events ) SELECT business_id FROM T WHERE mark = 1 GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; ``` diff --git a/solution/1100-1199/1126.Active Businesses/Solution.sql b/solution/1100-1199/1126.Active Businesses/Solution.sql index 25a7f1d2c9566..f1d2acff6d660 100644 --- a/solution/1100-1199/1126.Active Businesses/Solution.sql +++ b/solution/1100-1199/1126.Active Businesses/Solution.sql @@ -3,11 +3,11 @@ WITH T AS ( SELECT business_id, - occurences > avg(occurences) OVER (PARTITION BY event_type) AS mark + occurences > AVG(occurences) OVER (PARTITION BY event_type) AS mark FROM Events ) SELECT business_id FROM T WHERE mark = 1 GROUP BY 1 -HAVING count(1) > 1; +HAVING COUNT(1) > 1; diff --git a/solution/1100-1199/1127.User Purchase Platform/README.md b/solution/1100-1199/1127.User Purchase Platform/README.md index 50eadd7d1eafd..96dddad57215b 100644 --- a/solution/1100-1199/1127.User Purchase Platform/README.md +++ b/solution/1100-1199/1127.User Purchase Platform/README.md @@ -83,15 +83,15 @@ WITH SELECT user_id, spend_date, - sum(amount) AS amount, - if(count(platform) = 1, platform, 'both') AS platform + SUM(amount) AS amount, + IF(COUNT(platform) = 1, platform, 'both') AS platform FROM Spending GROUP BY 1, 2 ) SELECT p.*, - ifnull(sum(amount), 0) AS total_amount, - count(t.user_id) AS total_users + IFNULL(SUM(amount), 0) AS total_amount, + COUNT(t.user_id) AS total_users FROM P AS p LEFT JOIN T AS t USING (spend_date, platform) diff --git a/solution/1100-1199/1127.User Purchase Platform/README_EN.md b/solution/1100-1199/1127.User Purchase Platform/README_EN.md index 5a218570410ed..99fcf71bc5ab4 100644 --- a/solution/1100-1199/1127.User Purchase Platform/README_EN.md +++ b/solution/1100-1199/1127.User Purchase Platform/README_EN.md @@ -80,15 +80,15 @@ WITH SELECT user_id, spend_date, - sum(amount) AS amount, - if(count(platform) = 1, platform, 'both') AS platform + SUM(amount) AS amount, + IF(COUNT(platform) = 1, platform, 'both') AS platform FROM Spending GROUP BY 1, 2 ) SELECT p.*, - ifnull(sum(amount), 0) AS total_amount, - count(t.user_id) AS total_users + IFNULL(SUM(amount), 0) AS total_amount, + COUNT(t.user_id) AS total_users FROM P AS p LEFT JOIN T AS t USING (spend_date, platform) diff --git a/solution/1100-1199/1127.User Purchase Platform/Solution.sql b/solution/1100-1199/1127.User Purchase Platform/Solution.sql index ce96567abb255..39965bb62be79 100644 --- a/solution/1100-1199/1127.User Purchase Platform/Solution.sql +++ b/solution/1100-1199/1127.User Purchase Platform/Solution.sql @@ -11,15 +11,15 @@ WITH SELECT user_id, spend_date, - sum(amount) AS amount, - if(count(platform) = 1, platform, 'both') AS platform + SUM(amount) AS amount, + IF(COUNT(platform) = 1, platform, 'both') AS platform FROM Spending GROUP BY 1, 2 ) SELECT p.*, - ifnull(sum(amount), 0) AS total_amount, - count(t.user_id) AS total_users + IFNULL(SUM(amount), 0) AS total_amount, + COUNT(t.user_id) AS total_users FROM P AS p LEFT JOIN T AS t USING (spend_date, platform) diff --git a/solution/1100-1199/1132.Reported Posts II/README.md b/solution/1100-1199/1132.Reported Posts II/README.md index 4b758b63d3971..588d22785e073 100644 --- a/solution/1100-1199/1132.Reported Posts II/README.md +++ b/solution/1100-1199/1132.Reported Posts II/README.md @@ -99,14 +99,14 @@ Removals table: WITH T AS ( SELECT - count(DISTINCT t2.post_id) / count(DISTINCT t1.post_id) * 100 AS percent + COUNT(DISTINCT t2.post_id) / COUNT(DISTINCT t1.post_id) * 100 AS percent FROM Actions AS t1 LEFT JOIN Removals AS t2 ON t1.post_id = t2.post_id WHERE extra = 'spam' GROUP BY action_date ) -SELECT round(avg(percent), 2) AS average_daily_percent +SELECT ROUND(AVG(percent), 2) AS average_daily_percent FROM T; ``` diff --git a/solution/1100-1199/1132.Reported Posts II/README_EN.md b/solution/1100-1199/1132.Reported Posts II/README_EN.md index 04d226ca87e0d..afbab657cdd7a 100644 --- a/solution/1100-1199/1132.Reported Posts II/README_EN.md +++ b/solution/1100-1199/1132.Reported Posts II/README_EN.md @@ -96,14 +96,14 @@ Note that the output is only one number and that we do not care about the remove WITH T AS ( SELECT - count(DISTINCT t2.post_id) / count(DISTINCT t1.post_id) * 100 AS percent + COUNT(DISTINCT t2.post_id) / COUNT(DISTINCT t1.post_id) * 100 AS percent FROM Actions AS t1 LEFT JOIN Removals AS t2 ON t1.post_id = t2.post_id WHERE extra = 'spam' GROUP BY action_date ) -SELECT round(avg(percent), 2) AS average_daily_percent +SELECT ROUND(AVG(percent), 2) AS average_daily_percent FROM T; ``` diff --git a/solution/1100-1199/1132.Reported Posts II/Solution.sql b/solution/1100-1199/1132.Reported Posts II/Solution.sql index 93e9c8f3ea11b..d8ba6f214a22a 100644 --- a/solution/1100-1199/1132.Reported Posts II/Solution.sql +++ b/solution/1100-1199/1132.Reported Posts II/Solution.sql @@ -2,12 +2,12 @@ WITH T AS ( SELECT - count(DISTINCT t2.post_id) / count(DISTINCT t1.post_id) * 100 AS percent + COUNT(DISTINCT t2.post_id) / COUNT(DISTINCT t1.post_id) * 100 AS percent FROM Actions AS t1 LEFT JOIN Removals AS t2 ON t1.post_id = t2.post_id WHERE extra = 'spam' GROUP BY action_date ) -SELECT round(avg(percent), 2) AS average_daily_percent +SELECT ROUND(AVG(percent), 2) AS average_daily_percent FROM T; diff --git a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md index 4a9f1a6092d3a..7a58f193bd73c 100644 --- a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md +++ b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README.md @@ -76,9 +76,9 @@ Activity table: ```sql # Write your MySQL query statement below -SELECT activity_date AS day, count(DISTINCT user_id) AS active_users +SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users FROM Activity -WHERE activity_date <= '2019-07-27' AND datediff('2019-07-27', activity_date) < 30 +WHERE activity_date <= '2019-07-27' AND DATEDIFF('2019-07-27', activity_date) < 30 GROUP BY 1; ``` diff --git a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md index 1787a2a864174..1bc0ee33e8def 100644 --- a/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md +++ b/solution/1100-1199/1141.User Activity for the Past 30 Days I/README_EN.md @@ -68,9 +68,9 @@ Activity table: ```sql # Write your MySQL query statement below -SELECT activity_date AS day, count(DISTINCT user_id) AS active_users +SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users FROM Activity -WHERE activity_date <= '2019-07-27' AND datediff('2019-07-27', activity_date) < 30 +WHERE activity_date <= '2019-07-27' AND DATEDIFF('2019-07-27', activity_date) < 30 GROUP BY 1; ``` diff --git a/solution/1100-1199/1141.User Activity for the Past 30 Days I/Solution.sql b/solution/1100-1199/1141.User Activity for the Past 30 Days I/Solution.sql index 57e203e332ca1..f85b16a217397 100644 --- a/solution/1100-1199/1141.User Activity for the Past 30 Days I/Solution.sql +++ b/solution/1100-1199/1141.User Activity for the Past 30 Days I/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT activity_date AS day, count(DISTINCT user_id) AS active_users +SELECT activity_date AS day, COUNT(DISTINCT user_id) AS active_users FROM Activity -WHERE activity_date <= '2019-07-27' AND datediff('2019-07-27', activity_date) < 30 +WHERE activity_date <= '2019-07-27' AND DATEDIFF('2019-07-27', activity_date) < 30 GROUP BY 1; diff --git a/solution/1100-1199/1149.Article Views II/README.md b/solution/1100-1199/1149.Article Views II/README.md index f86a19d44f3ab..4382e051564d5 100644 --- a/solution/1100-1199/1149.Article Views II/README.md +++ b/solution/1100-1199/1149.Article Views II/README.md @@ -74,7 +74,7 @@ Views 表: SELECT DISTINCT viewer_id AS id FROM Views GROUP BY viewer_id, view_date -HAVING count(DISTINCT article_id) > 1 +HAVING COUNT(DISTINCT article_id) > 1 ORDER BY 1; ``` diff --git a/solution/1100-1199/1149.Article Views II/README_EN.md b/solution/1100-1199/1149.Article Views II/README_EN.md index 29f809b018a4c..3b0704dfd6665 100644 --- a/solution/1100-1199/1149.Article Views II/README_EN.md +++ b/solution/1100-1199/1149.Article Views II/README_EN.md @@ -65,7 +65,7 @@ Views table: SELECT DISTINCT viewer_id AS id FROM Views GROUP BY viewer_id, view_date -HAVING count(DISTINCT article_id) > 1 +HAVING COUNT(DISTINCT article_id) > 1 ORDER BY 1; ``` diff --git a/solution/1100-1199/1149.Article Views II/Solution.sql b/solution/1100-1199/1149.Article Views II/Solution.sql index 55402d92887bc..5bbb9f555839d 100644 --- a/solution/1100-1199/1149.Article Views II/Solution.sql +++ b/solution/1100-1199/1149.Article Views II/Solution.sql @@ -2,5 +2,5 @@ SELECT DISTINCT viewer_id AS id FROM Views GROUP BY viewer_id, view_date -HAVING count(DISTINCT article_id) > 1 +HAVING COUNT(DISTINCT article_id) > 1 ORDER BY 1; diff --git a/solution/1100-1199/1158.Market Analysis I/README.md b/solution/1100-1199/1158.Market Analysis I/README.md index 0e1cfe63ba093..8dcace792ff8e 100644 --- a/solution/1100-1199/1158.Market Analysis I/README.md +++ b/solution/1100-1199/1158.Market Analysis I/README.md @@ -119,7 +119,7 @@ Items 表: SELECT u.user_id AS buyer_id, u.join_date, - count(order_id) AS orders_in_2019 + COUNT(order_id) AS orders_in_2019 FROM Users AS u LEFT JOIN Orders AS o ON u.user_id = o.buyer_id AND YEAR(order_date) = 2019 @@ -131,7 +131,7 @@ GROUP BY user_id; SELECT user_id AS buyer_id, join_date, - ifnull(sum(year(order_date) = 2019), 0) AS orders_in_2019 + IFNULL(SUM(YEAR(order_date) = 2019), 0) AS orders_in_2019 FROM Users AS u LEFT JOIN Orders AS o ON u.user_id = buyer_id diff --git a/solution/1100-1199/1158.Market Analysis I/README_EN.md b/solution/1100-1199/1158.Market Analysis I/README_EN.md index f168645969787..2a932414bf806 100644 --- a/solution/1100-1199/1158.Market Analysis I/README_EN.md +++ b/solution/1100-1199/1158.Market Analysis I/README_EN.md @@ -115,7 +115,7 @@ Items table: SELECT u.user_id AS buyer_id, u.join_date, - count(order_id) AS orders_in_2019 + COUNT(order_id) AS orders_in_2019 FROM Users AS u LEFT JOIN Orders AS o ON u.user_id = o.buyer_id AND YEAR(order_date) = 2019 @@ -127,7 +127,7 @@ GROUP BY user_id; SELECT user_id AS buyer_id, join_date, - ifnull(sum(year(order_date) = 2019), 0) AS orders_in_2019 + IFNULL(SUM(YEAR(order_date) = 2019), 0) AS orders_in_2019 FROM Users AS u LEFT JOIN Orders AS o ON u.user_id = buyer_id diff --git a/solution/1100-1199/1158.Market Analysis I/Solution.sql b/solution/1100-1199/1158.Market Analysis I/Solution.sql index c350404e187e9..975977bb202a6 100644 --- a/solution/1100-1199/1158.Market Analysis I/Solution.sql +++ b/solution/1100-1199/1158.Market Analysis I/Solution.sql @@ -2,7 +2,7 @@ SELECT user_id AS buyer_id, join_date, - ifnull(sum(year(order_date) = 2019), 0) AS orders_in_2019 + IFNULL(SUM(YEAR(order_date) = 2019), 0) AS orders_in_2019 FROM Users AS u LEFT JOIN Orders AS o ON u.user_id = buyer_id diff --git a/solution/1100-1199/1159.Market Analysis II/README.md b/solution/1100-1199/1159.Market Analysis II/README.md index 68c4005aa4b6e..b84500830fc0a 100644 --- a/solution/1100-1199/1159.Market Analysis II/README.md +++ b/solution/1100-1199/1159.Market Analysis II/README.md @@ -130,7 +130,7 @@ FROM order_date, item_id, seller_id, - rank() OVER ( + RANK() OVER ( PARTITION BY seller_id ORDER BY order_date ) AS rk diff --git a/solution/1100-1199/1159.Market Analysis II/README_EN.md b/solution/1100-1199/1159.Market Analysis II/README_EN.md index e9c05cd2813c8..e9e4242a8f58f 100644 --- a/solution/1100-1199/1159.Market Analysis II/README_EN.md +++ b/solution/1100-1199/1159.Market Analysis II/README_EN.md @@ -129,7 +129,7 @@ FROM order_date, item_id, seller_id, - rank() OVER ( + RANK() OVER ( PARTITION BY seller_id ORDER BY order_date ) AS rk diff --git a/solution/1100-1199/1159.Market Analysis II/Solution.sql b/solution/1100-1199/1159.Market Analysis II/Solution.sql index ce9dc1cdeb8c1..2e041d3945d9c 100644 --- a/solution/1100-1199/1159.Market Analysis II/Solution.sql +++ b/solution/1100-1199/1159.Market Analysis II/Solution.sql @@ -12,7 +12,7 @@ FROM order_date, item_id, seller_id, - rank() OVER ( + RANK() OVER ( PARTITION BY seller_id ORDER BY order_date ) AS rk diff --git a/solution/1100-1199/1164.Product Price at a Given Date/README.md b/solution/1100-1199/1164.Product Price at a Given Date/README.md index 5e5e909ad2488..7ae6227ce9667 100644 --- a/solution/1100-1199/1164.Product Price at a Given Date/README.md +++ b/solution/1100-1199/1164.Product Price at a Given Date/README.md @@ -65,7 +65,7 @@ Products 表: # Write your MySQL query statement below SELECT p1.product_id AS product_id, - ifnull(p2.price, 10) AS price + IFNULL(p2.price, 10) AS price FROM ( SELECT DISTINCT @@ -81,7 +81,7 @@ FROM JOIN ( SELECT product_id, - max(change_date) AS change_date + MAX(change_date) AS change_date FROM Products WHERE change_date <= '2019-08-16' GROUP BY product_id @@ -107,13 +107,13 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY change_date DESC ) AS rk FROM P ) -SELECT product_id, ifnull(new_price, 10) AS price +SELECT product_id, IFNULL(new_price, 10) AS price FROM T WHERE rk = 1; ``` diff --git a/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md b/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md index 4a37652a0179c..e95eb633962dc 100644 --- a/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md +++ b/solution/1100-1199/1164.Product Price at a Given Date/README_EN.md @@ -61,7 +61,7 @@ Products table: # Write your MySQL query statement below SELECT p1.product_id AS product_id, - ifnull(p2.price, 10) AS price + IFNULL(p2.price, 10) AS price FROM ( SELECT DISTINCT @@ -77,7 +77,7 @@ FROM JOIN ( SELECT product_id, - max(change_date) AS change_date + MAX(change_date) AS change_date FROM Products WHERE change_date <= '2019-08-16' GROUP BY product_id @@ -103,13 +103,13 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY change_date DESC ) AS rk FROM P ) -SELECT product_id, ifnull(new_price, 10) AS price +SELECT product_id, IFNULL(new_price, 10) AS price FROM T WHERE rk = 1; ``` diff --git a/solution/1100-1199/1164.Product Price at a Given Date/Solution.sql b/solution/1100-1199/1164.Product Price at a Given Date/Solution.sql index 4412db38ce132..3fd9654261903 100644 --- a/solution/1100-1199/1164.Product Price at a Given Date/Solution.sql +++ b/solution/1100-1199/1164.Product Price at a Given Date/Solution.sql @@ -13,12 +13,12 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY change_date DESC ) AS rk FROM P ) -SELECT product_id, ifnull(new_price, 10) AS price +SELECT product_id, IFNULL(new_price, 10) AS price FROM T WHERE rk = 1; diff --git a/solution/1100-1199/1173.Immediate Food Delivery I/README.md b/solution/1100-1199/1173.Immediate Food Delivery I/README.md index 2c4669c7acbdf..965d725c3d891 100644 --- a/solution/1100-1199/1173.Immediate Food Delivery I/README.md +++ b/solution/1100-1199/1173.Immediate Food Delivery I/README.md @@ -69,7 +69,7 @@ Delivery 表: ```sql # Write your MySQL query statement below SELECT - round(sum(order_date = customer_pref_delivery_date) / count(1) * 100, 2) AS immediate_percentage + ROUND(SUM(order_date = customer_pref_delivery_date) / COUNT(1) * 100, 2) AS immediate_percentage FROM Delivery; ``` diff --git a/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md b/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md index af5edad7b0c53..1cbe2667e9bbc 100644 --- a/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md +++ b/solution/1100-1199/1173.Immediate Food Delivery I/README_EN.md @@ -65,7 +65,7 @@ We can use the `sum` function to count the number of instant orders, and then di ```sql # Write your MySQL query statement below SELECT - round(sum(order_date = customer_pref_delivery_date) / count(1) * 100, 2) AS immediate_percentage + ROUND(SUM(order_date = customer_pref_delivery_date) / COUNT(1) * 100, 2) AS immediate_percentage FROM Delivery; ``` diff --git a/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql b/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql index 02eda428e78e5..bc2530cc05926 100644 --- a/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql +++ b/solution/1100-1199/1173.Immediate Food Delivery I/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below SELECT - round(sum(order_date = customer_pref_delivery_date) / count(1) * 100, 2) AS immediate_percentage + ROUND(SUM(order_date = customer_pref_delivery_date) / COUNT(1) * 100, 2) AS immediate_percentage FROM Delivery; diff --git a/solution/1100-1199/1174.Immediate Food Delivery II/README.md b/solution/1100-1199/1174.Immediate Food Delivery II/README.md index 70c773b319a80..10ae920f517d9 100644 --- a/solution/1100-1199/1174.Immediate Food Delivery II/README.md +++ b/solution/1100-1199/1174.Immediate Food Delivery II/README.md @@ -74,14 +74,14 @@ Delivery 表: ```sql # Write your MySQL query statement below select - round( - sum( - if( + ROUND( + SUM( + IF( t1.order_date = t1.customer_pref_delivery_date, 1, 0 ) - ) / count(1) * 100, + ) / COUNT(1) * 100, 2 ) as immediate_percentage from @@ -89,7 +89,7 @@ from right join ( select customer_id, - min(order_date) as order_date + MIN(order_date) as order_date from Delivery group by diff --git a/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md b/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md index ab5bc5fbf466f..599308ce3e177 100644 --- a/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md +++ b/solution/1100-1199/1174.Immediate Food Delivery II/README_EN.md @@ -69,14 +69,14 @@ Hence, half the customers have immediate first orders. ```sql # Write your MySQL query statement below select - round( - sum( - if( + ROUND( + SUM( + IF( t1.order_date = t1.customer_pref_delivery_date, 1, 0 ) - ) / count(1) * 100, + ) / COUNT(1) * 100, 2 ) as immediate_percentage from @@ -84,7 +84,7 @@ from right join ( select customer_id, - min(order_date) as order_date + MIN(order_date) as order_date from Delivery group by diff --git a/solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql b/solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql index 6531195e94701..c687af9eabb47 100644 --- a/solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql +++ b/solution/1100-1199/1174.Immediate Food Delivery II/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT - round( - sum(if(t1.order_date = t1.customer_pref_delivery_date, 1, 0)) / count(1) * 100, + ROUND( + SUM(IF(t1.order_date = t1.customer_pref_delivery_date, 1, 0)) / COUNT(1) * 100, 2 ) AS immediate_percentage FROM @@ -9,7 +9,7 @@ FROM RIGHT JOIN ( SELECT customer_id, - min(order_date) AS order_date + MIN(order_date) AS order_date FROM Delivery GROUP BY customer_id ) AS t2 diff --git a/solution/1100-1199/1179.Reformat Department Table/README.md b/solution/1100-1199/1179.Reformat Department Table/README.md index b7c8e2f3d1800..506928b5f0737 100644 --- a/solution/1100-1199/1179.Reformat Department Table/README.md +++ b/solution/1100-1199/1179.Reformat Department Table/README.md @@ -68,62 +68,62 @@ Department table: # Write your MySQL query statement below SELECT id, - sum( + SUM( CASE month WHEN 'Jan' THEN revenue END ) AS Jan_Revenue, - sum( + SUM( CASE month WHEN 'Feb' THEN revenue END ) AS Feb_Revenue, - sum( + SUM( CASE month WHEN 'Mar' THEN revenue END ) AS Mar_Revenue, - sum( + SUM( CASE month WHEN 'Apr' THEN revenue END ) AS Apr_Revenue, - sum( + SUM( CASE month WHEN 'May' THEN revenue END ) AS May_Revenue, - sum( + SUM( CASE month WHEN 'Jun' THEN revenue END ) AS Jun_Revenue, - sum( + SUM( CASE month WHEN 'Jul' THEN revenue END ) AS Jul_Revenue, - sum( + SUM( CASE month WHEN 'Aug' THEN revenue END ) AS Aug_Revenue, - sum( + SUM( CASE month WHEN 'Sep' THEN revenue END ) AS Sep_Revenue, - sum( + SUM( CASE month WHEN 'Oct' THEN revenue END ) AS Oct_Revenue, - sum( + SUM( CASE month WHEN 'Nov' THEN revenue END ) AS Nov_Revenue, - sum( + SUM( CASE month WHEN 'Dec' THEN revenue END diff --git a/solution/1100-1199/1179.Reformat Department Table/README_EN.md b/solution/1100-1199/1179.Reformat Department Table/README_EN.md index 74938d82d38a8..821d56ed71a7f 100644 --- a/solution/1100-1199/1179.Reformat Department Table/README_EN.md +++ b/solution/1100-1199/1179.Reformat Department Table/README_EN.md @@ -64,62 +64,62 @@ Note that the result table has 13 columns (1 for the department id + 12 for the # Write your MySQL query statement below SELECT id, - sum( + SUM( CASE month WHEN 'Jan' THEN revenue END ) AS Jan_Revenue, - sum( + SUM( CASE month WHEN 'Feb' THEN revenue END ) AS Feb_Revenue, - sum( + SUM( CASE month WHEN 'Mar' THEN revenue END ) AS Mar_Revenue, - sum( + SUM( CASE month WHEN 'Apr' THEN revenue END ) AS Apr_Revenue, - sum( + SUM( CASE month WHEN 'May' THEN revenue END ) AS May_Revenue, - sum( + SUM( CASE month WHEN 'Jun' THEN revenue END ) AS Jun_Revenue, - sum( + SUM( CASE month WHEN 'Jul' THEN revenue END ) AS Jul_Revenue, - sum( + SUM( CASE month WHEN 'Aug' THEN revenue END ) AS Aug_Revenue, - sum( + SUM( CASE month WHEN 'Sep' THEN revenue END ) AS Sep_Revenue, - sum( + SUM( CASE month WHEN 'Oct' THEN revenue END ) AS Oct_Revenue, - sum( + SUM( CASE month WHEN 'Nov' THEN revenue END ) AS Nov_Revenue, - sum( + SUM( CASE month WHEN 'Dec' THEN revenue END diff --git a/solution/1100-1199/1179.Reformat Department Table/Solution.sql b/solution/1100-1199/1179.Reformat Department Table/Solution.sql index c91f0cafddf12..7a6fa21e5aa84 100644 --- a/solution/1100-1199/1179.Reformat Department Table/Solution.sql +++ b/solution/1100-1199/1179.Reformat Department Table/Solution.sql @@ -1,62 +1,62 @@ # Write your MySQL query statement below SELECT id, - sum( + SUM( CASE month WHEN 'Jan' THEN revenue END ) AS Jan_Revenue, - sum( + SUM( CASE month WHEN 'Feb' THEN revenue END ) AS Feb_Revenue, - sum( + SUM( CASE month WHEN 'Mar' THEN revenue END ) AS Mar_Revenue, - sum( + SUM( CASE month WHEN 'Apr' THEN revenue END ) AS Apr_Revenue, - sum( + SUM( CASE month WHEN 'May' THEN revenue END ) AS May_Revenue, - sum( + SUM( CASE month WHEN 'Jun' THEN revenue END ) AS Jun_Revenue, - sum( + SUM( CASE month WHEN 'Jul' THEN revenue END ) AS Jul_Revenue, - sum( + SUM( CASE month WHEN 'Aug' THEN revenue END ) AS Aug_Revenue, - sum( + SUM( CASE month WHEN 'Sep' THEN revenue END ) AS Sep_Revenue, - sum( + SUM( CASE month WHEN 'Oct' THEN revenue END ) AS Oct_Revenue, - sum( + SUM( CASE month WHEN 'Nov' THEN revenue END ) AS Nov_Revenue, - sum( + SUM( CASE month WHEN 'Dec' THEN revenue END diff --git a/solution/1100-1199/1193.Monthly Transactions I/README.md b/solution/1100-1199/1193.Monthly Transactions I/README.md index f1b9ccc24595c..28faabb50ce11 100644 --- a/solution/1100-1199/1193.Monthly Transactions I/README.md +++ b/solution/1100-1199/1193.Monthly Transactions I/README.md @@ -66,12 +66,12 @@ Transactions table: ```sql # Write your MySQL query statement below SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - count(1) AS trans_count, - sum(state = 'approved') AS approved_count, - sum(amount) AS trans_total_amount, - sum(if(state = 'approved', amount, 0)) AS approved_total_amount + COUNT(1) AS trans_count, + SUM(state = 'approved') AS approved_count, + SUM(amount) AS trans_total_amount, + SUM(IF(state = 'approved', amount, 0)) AS approved_total_amount FROM Transactions GROUP BY 1, 2; ``` diff --git a/solution/1100-1199/1193.Monthly Transactions I/README_EN.md b/solution/1100-1199/1193.Monthly Transactions I/README_EN.md index 01c46ca79c6d2..138fa1a798037 100644 --- a/solution/1100-1199/1193.Monthly Transactions I/README_EN.md +++ b/solution/1100-1199/1193.Monthly Transactions I/README_EN.md @@ -62,12 +62,12 @@ Transactions table: ```sql # Write your MySQL query statement below SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - count(1) AS trans_count, - sum(state = 'approved') AS approved_count, - sum(amount) AS trans_total_amount, - sum(if(state = 'approved', amount, 0)) AS approved_total_amount + COUNT(1) AS trans_count, + SUM(state = 'approved') AS approved_count, + SUM(amount) AS trans_total_amount, + SUM(IF(state = 'approved', amount, 0)) AS approved_total_amount FROM Transactions GROUP BY 1, 2; ``` diff --git a/solution/1100-1199/1193.Monthly Transactions I/Solution.sql b/solution/1100-1199/1193.Monthly Transactions I/Solution.sql index 3da7c133a1832..fd10326384a87 100644 --- a/solution/1100-1199/1193.Monthly Transactions I/Solution.sql +++ b/solution/1100-1199/1193.Monthly Transactions I/Solution.sql @@ -1,10 +1,10 @@ # Write your MySQL query statement below SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - count(1) AS trans_count, - sum(state = 'approved') AS approved_count, - sum(amount) AS trans_total_amount, - sum(if(state = 'approved', amount, 0)) AS approved_total_amount + COUNT(1) AS trans_count, + SUM(state = 'approved') AS approved_count, + SUM(amount) AS trans_total_amount, + SUM(IF(state = 'approved', amount, 0)) AS approved_total_amount FROM Transactions GROUP BY 1, 2; diff --git a/solution/1100-1199/1194.Tournament Winners/README.md b/solution/1100-1199/1194.Tournament Winners/README.md index b487762f8fb33..e8dbfbe109255 100644 --- a/solution/1100-1199/1194.Tournament Winners/README.md +++ b/solution/1100-1199/1194.Tournament Winners/README.md @@ -109,7 +109,7 @@ WITH JOIN Players AS p ON m.second_player = p.player_id ), t AS ( - SELECT group_id, player_id, sum(score) AS scores + SELECT group_id, player_id, SUM(score) AS scores FROM s GROUP BY player_id ), @@ -117,7 +117,7 @@ WITH SELECT group_id, player_id, - rank() OVER ( + RANK() OVER ( PARTITION BY group_id ORDER BY scores DESC, player_id ) AS rk diff --git a/solution/1100-1199/1194.Tournament Winners/README_EN.md b/solution/1100-1199/1194.Tournament Winners/README_EN.md index 69e8849644b1a..3981f34c86648 100644 --- a/solution/1100-1199/1194.Tournament Winners/README_EN.md +++ b/solution/1100-1199/1194.Tournament Winners/README_EN.md @@ -105,7 +105,7 @@ WITH JOIN Players AS p ON m.second_player = p.player_id ), t AS ( - SELECT group_id, player_id, sum(score) AS scores + SELECT group_id, player_id, SUM(score) AS scores FROM s GROUP BY player_id ), @@ -113,7 +113,7 @@ WITH SELECT group_id, player_id, - rank() OVER ( + RANK() OVER ( PARTITION BY group_id ORDER BY scores DESC, player_id ) AS rk diff --git a/solution/1100-1199/1194.Tournament Winners/Solution.sql b/solution/1100-1199/1194.Tournament Winners/Solution.sql index 53543b93e00e6..8344980ccf352 100644 --- a/solution/1100-1199/1194.Tournament Winners/Solution.sql +++ b/solution/1100-1199/1194.Tournament Winners/Solution.sql @@ -12,7 +12,7 @@ WITH JOIN Players AS p ON m.second_player = p.player_id ), t AS ( - SELECT group_id, player_id, sum(score) AS scores + SELECT group_id, player_id, SUM(score) AS scores FROM s GROUP BY player_id ), @@ -20,7 +20,7 @@ WITH SELECT group_id, player_id, - rank() OVER ( + RANK() OVER ( PARTITION BY group_id ORDER BY scores DESC, player_id ) AS rk diff --git a/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md b/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md index ee7d98027be76..6033776507fe9 100644 --- a/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md +++ b/solution/1200-1299/1204.Last Person to Fit in the Bus/README.md @@ -97,7 +97,7 @@ WITH T AS ( SELECT person_name, - sum(weight) OVER (ORDER BY turn) AS s + SUM(weight) OVER (ORDER BY turn) AS s FROM Queue ) SELECT person_name diff --git a/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md b/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md index 6f482f4d6bd2e..fefc742fa5996 100644 --- a/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md +++ b/solution/1200-1299/1204.Last Person to Fit in the Bus/README_EN.md @@ -90,7 +90,7 @@ WITH T AS ( SELECT person_name, - sum(weight) OVER (ORDER BY turn) AS s + SUM(weight) OVER (ORDER BY turn) AS s FROM Queue ) SELECT person_name diff --git a/solution/1200-1299/1204.Last Person to Fit in the Bus/Solution.sql b/solution/1200-1299/1204.Last Person to Fit in the Bus/Solution.sql index 1fc50f98a556f..a117e6e2df58e 100644 --- a/solution/1200-1299/1204.Last Person to Fit in the Bus/Solution.sql +++ b/solution/1200-1299/1204.Last Person to Fit in the Bus/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT person_name, - sum(weight) OVER (ORDER BY turn) AS s + SUM(weight) OVER (ORDER BY turn) AS s FROM Queue ) SELECT person_name diff --git a/solution/1200-1299/1205.Monthly Transactions II/README.md b/solution/1200-1299/1205.Monthly Transactions II/README.md index 9663c12193427..748c77681b98f 100644 --- a/solution/1200-1299/1205.Monthly Transactions II/README.md +++ b/solution/1200-1299/1205.Monthly Transactions II/README.md @@ -98,12 +98,12 @@ WITH JOIN Chargebacks AS c ON t.id = c.trans_id ) SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - sum(state = 'approved') AS approved_count, - sum(if(state = 'approved', amount, 0)) AS approved_amount, - sum(state = 'chargeback') AS chargeback_count, - sum(if(state = 'chargeback', amount, 0)) AS chargeback_amount + SUM(state = 'approved') AS approved_count, + SUM(IF(state = 'approved', amount, 0)) AS approved_amount, + SUM(state = 'chargeback') AS chargeback_count, + SUM(IF(state = 'chargeback', amount, 0)) AS chargeback_amount FROM T GROUP BY 1, 2 HAVING approved_amount OR chargeback_amount; diff --git a/solution/1200-1299/1205.Monthly Transactions II/README_EN.md b/solution/1200-1299/1205.Monthly Transactions II/README_EN.md index e068d7a099edd..ebe2ccd214236 100644 --- a/solution/1200-1299/1205.Monthly Transactions II/README_EN.md +++ b/solution/1200-1299/1205.Monthly Transactions II/README_EN.md @@ -95,12 +95,12 @@ WITH JOIN Chargebacks AS c ON t.id = c.trans_id ) SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - sum(state = 'approved') AS approved_count, - sum(if(state = 'approved', amount, 0)) AS approved_amount, - sum(state = 'chargeback') AS chargeback_count, - sum(if(state = 'chargeback', amount, 0)) AS chargeback_amount + SUM(state = 'approved') AS approved_count, + SUM(IF(state = 'approved', amount, 0)) AS approved_amount, + SUM(state = 'chargeback') AS chargeback_count, + SUM(IF(state = 'chargeback', amount, 0)) AS chargeback_amount FROM T GROUP BY 1, 2 HAVING approved_amount OR chargeback_amount; diff --git a/solution/1200-1299/1205.Monthly Transactions II/Solution.sql b/solution/1200-1299/1205.Monthly Transactions II/Solution.sql index 04059a380885c..86ae79bad3cc9 100644 --- a/solution/1200-1299/1205.Monthly Transactions II/Solution.sql +++ b/solution/1200-1299/1205.Monthly Transactions II/Solution.sql @@ -9,12 +9,12 @@ WITH JOIN Chargebacks AS c ON t.id = c.trans_id ) SELECT - date_format(trans_date, '%Y-%m') AS month, + DATE_FORMAT(trans_date, '%Y-%m') AS month, country, - sum(state = 'approved') AS approved_count, - sum(if(state = 'approved', amount, 0)) AS approved_amount, - sum(state = 'chargeback') AS chargeback_count, - sum(if(state = 'chargeback', amount, 0)) AS chargeback_amount + SUM(state = 'approved') AS approved_count, + SUM(IF(state = 'approved', amount, 0)) AS approved_amount, + SUM(state = 'chargeback') AS chargeback_count, + SUM(IF(state = 'chargeback', amount, 0)) AS chargeback_amount FROM T GROUP BY 1, 2 HAVING approved_amount OR chargeback_amount; diff --git a/solution/1200-1299/1212.Team Scores in Football Tournament/README.md b/solution/1200-1299/1212.Team Scores in Football Tournament/README.md index 85ab972efba73..9452e3350aad3 100644 --- a/solution/1200-1299/1212.Team Scores in Football Tournament/README.md +++ b/solution/1200-1299/1212.Team Scores in Football Tournament/README.md @@ -116,7 +116,7 @@ Teams table: SELECT team_id, team_name, - sum( + SUM( CASE WHEN team_id = host_team AND host_goals > guest_goals THEN 3 diff --git a/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md b/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md index 0a0d043714aa3..d0801f4fed39d 100644 --- a/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md +++ b/solution/1200-1299/1212.Team Scores in Football Tournament/README_EN.md @@ -111,7 +111,7 @@ Finally, we sort the result by points in descending order, and if the points are SELECT team_id, team_name, - sum( + SUM( CASE WHEN team_id = host_team AND host_goals > guest_goals THEN 3 diff --git a/solution/1200-1299/1212.Team Scores in Football Tournament/Solution.sql b/solution/1200-1299/1212.Team Scores in Football Tournament/Solution.sql index 536374a7f73b3..22add7e8117a4 100644 --- a/solution/1200-1299/1212.Team Scores in Football Tournament/Solution.sql +++ b/solution/1200-1299/1212.Team Scores in Football Tournament/Solution.sql @@ -2,7 +2,7 @@ SELECT team_id, team_name, - sum( + SUM( CASE WHEN team_id = host_team AND host_goals > guest_goals THEN 3 diff --git a/solution/1200-1299/1225.Report Contiguous Dates/README.md b/solution/1200-1299/1225.Report Contiguous Dates/README.md index fb83690dac5f7..2318bac22fb18 100644 --- a/solution/1200-1299/1225.Report Contiguous Dates/README.md +++ b/solution/1200-1299/1225.Report Contiguous Dates/README.md @@ -101,23 +101,23 @@ WITH T AS ( SELECT fail_date AS dt, 'failed' AS st FROM Failed - WHERE year(fail_date) = 2019 + WHERE YEAR(fail_date) = 2019 UNION ALL SELECT success_date AS dt, 'succeeded' AS st FROM Succeeded - WHERE year(success_date) = 2019 + WHERE YEAR(success_date) = 2019 ) SELECT st AS period_state, - min(dt) AS start_date, - max(dt) AS end_date + MIN(dt) AS start_date, + MAX(dt) AS end_date FROM ( SELECT *, - subdate( + SUBDATE( dt, - rank() OVER ( + RANK() OVER ( PARTITION BY st ORDER BY dt ) diff --git a/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md b/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md index f1adb08ec97e7..7d1c776e159c4 100644 --- a/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md +++ b/solution/1200-1299/1225.Report Contiguous Dates/README_EN.md @@ -98,23 +98,23 @@ WITH T AS ( SELECT fail_date AS dt, 'failed' AS st FROM Failed - WHERE year(fail_date) = 2019 + WHERE YEAR(fail_date) = 2019 UNION ALL SELECT success_date AS dt, 'succeeded' AS st FROM Succeeded - WHERE year(success_date) = 2019 + WHERE YEAR(success_date) = 2019 ) SELECT st AS period_state, - min(dt) AS start_date, - max(dt) AS end_date + MIN(dt) AS start_date, + MAX(dt) AS end_date FROM ( SELECT *, - subdate( + SUBDATE( dt, - rank() OVER ( + RANK() OVER ( PARTITION BY st ORDER BY dt ) diff --git a/solution/1200-1299/1225.Report Contiguous Dates/Solution.sql b/solution/1200-1299/1225.Report Contiguous Dates/Solution.sql index eeab5824d0c52..a31a66063dd63 100644 --- a/solution/1200-1299/1225.Report Contiguous Dates/Solution.sql +++ b/solution/1200-1299/1225.Report Contiguous Dates/Solution.sql @@ -3,23 +3,23 @@ WITH T AS ( SELECT fail_date AS dt, 'failed' AS st FROM Failed - WHERE year(fail_date) = 2019 + WHERE YEAR(fail_date) = 2019 UNION ALL SELECT success_date AS dt, 'succeeded' AS st FROM Succeeded - WHERE year(success_date) = 2019 + WHERE YEAR(success_date) = 2019 ) SELECT st AS period_state, - min(dt) AS start_date, - max(dt) AS end_date + MIN(dt) AS start_date, + MAX(dt) AS end_date FROM ( SELECT *, - subdate( + SUBDATE( dt, - rank() OVER ( + RANK() OVER ( PARTITION BY st ORDER BY dt ) diff --git a/solution/1200-1299/1241.Number of Comments per Post/README.md b/solution/1200-1299/1241.Number of Comments per Post/README.md index b93c60d3de870..3b171991e7a15 100644 --- a/solution/1200-1299/1241.Number of Comments per Post/README.md +++ b/solution/1200-1299/1241.Number of Comments per Post/README.md @@ -89,7 +89,7 @@ WITH LEFT JOIN Submissions AS s2 ON s1.sub_id = s2.parent_id WHERE s1.parent_id IS NULL ) -SELECT post_id, count(sub_id) AS number_of_comments +SELECT post_id, COUNT(sub_id) AS number_of_comments FROM t GROUP BY post_id ORDER BY post_id; diff --git a/solution/1200-1299/1241.Number of Comments per Post/README_EN.md b/solution/1200-1299/1241.Number of Comments per Post/README_EN.md index b4e3906e07f9d..71c5d24b200bf 100644 --- a/solution/1200-1299/1241.Number of Comments per Post/README_EN.md +++ b/solution/1200-1299/1241.Number of Comments per Post/README_EN.md @@ -83,7 +83,7 @@ WITH LEFT JOIN Submissions AS s2 ON s1.sub_id = s2.parent_id WHERE s1.parent_id IS NULL ) -SELECT post_id, count(sub_id) AS number_of_comments +SELECT post_id, COUNT(sub_id) AS number_of_comments FROM t GROUP BY post_id ORDER BY post_id; diff --git a/solution/1200-1299/1241.Number of Comments per Post/Solution.sql b/solution/1200-1299/1241.Number of Comments per Post/Solution.sql index daac44ccff060..92792fb5f1a00 100644 --- a/solution/1200-1299/1241.Number of Comments per Post/Solution.sql +++ b/solution/1200-1299/1241.Number of Comments per Post/Solution.sql @@ -7,7 +7,7 @@ WITH LEFT JOIN Submissions AS s2 ON s1.sub_id = s2.parent_id WHERE s1.parent_id IS NULL ) -SELECT post_id, count(sub_id) AS number_of_comments +SELECT post_id, COUNT(sub_id) AS number_of_comments FROM t GROUP BY post_id ORDER BY post_id; diff --git a/solution/1200-1299/1251.Average Selling Price/README.md b/solution/1200-1299/1251.Average Selling Price/README.md index 080cb22555733..1c9bedd4be2a4 100644 --- a/solution/1200-1299/1251.Average Selling Price/README.md +++ b/solution/1200-1299/1251.Average Selling Price/README.md @@ -91,7 +91,7 @@ UnitsSold table: ```sql SELECT p.product_id, - IFNULL(Round(Sum(units * price) / Sum(units), 2), 0) AS average_price + IFNULL(ROUND(SUM(units * price) / SUM(units), 2), 0) AS average_price FROM Prices AS p LEFT JOIN UnitsSold AS u diff --git a/solution/1200-1299/1251.Average Selling Price/README_EN.md b/solution/1200-1299/1251.Average Selling Price/README_EN.md index e9d249fdae65f..cb0fe1edb979b 100644 --- a/solution/1200-1299/1251.Average Selling Price/README_EN.md +++ b/solution/1200-1299/1251.Average Selling Price/README_EN.md @@ -89,7 +89,7 @@ Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96 ```sql SELECT p.product_id, - IFNULL(Round(Sum(units * price) / Sum(units), 2), 0) AS average_price + IFNULL(ROUND(SUM(units * price) / SUM(units), 2), 0) AS average_price FROM Prices AS p LEFT JOIN UnitsSold AS u diff --git a/solution/1200-1299/1251.Average Selling Price/Solution.sql b/solution/1200-1299/1251.Average Selling Price/Solution.sql index d42fa662c51b1..4976e3f9f8636 100644 --- a/solution/1200-1299/1251.Average Selling Price/Solution.sql +++ b/solution/1200-1299/1251.Average Selling Price/Solution.sql @@ -1,6 +1,6 @@ SELECT p.product_id, - IFNULL(Round(Sum(units * price) / Sum(units), 2), 0) AS average_price + IFNULL(ROUND(SUM(units * price) / SUM(units), 2), 0) AS average_price FROM Prices AS p LEFT JOIN UnitsSold AS u diff --git a/solution/1200-1299/1280.Students and Examinations/README.md b/solution/1200-1299/1280.Students and Examinations/README.md index e0e26f0f50113..a1c6458fec86f 100644 --- a/solution/1200-1299/1280.Students and Examinations/README.md +++ b/solution/1200-1299/1280.Students and Examinations/README.md @@ -133,7 +133,7 @@ SELECT a.student_id, student_name, b.subject_name, - count(c.subject_name) AS attended_exams + COUNT(c.subject_name) AS attended_exams FROM Students AS a CROSS JOIN Subjects AS b diff --git a/solution/1200-1299/1280.Students and Examinations/README_EN.md b/solution/1200-1299/1280.Students and Examinations/README_EN.md index 29f865d4872eb..40545968262c8 100644 --- a/solution/1200-1299/1280.Students and Examinations/README_EN.md +++ b/solution/1200-1299/1280.Students and Examinations/README_EN.md @@ -130,7 +130,7 @@ SELECT a.student_id, student_name, b.subject_name, - count(c.subject_name) AS attended_exams + COUNT(c.subject_name) AS attended_exams FROM Students AS a CROSS JOIN Subjects AS b diff --git a/solution/1200-1299/1280.Students and Examinations/Solution.sql b/solution/1200-1299/1280.Students and Examinations/Solution.sql index ee4d84da5faa6..8d0b08089f84a 100644 --- a/solution/1200-1299/1280.Students and Examinations/Solution.sql +++ b/solution/1200-1299/1280.Students and Examinations/Solution.sql @@ -3,7 +3,7 @@ SELECT a.student_id, student_name, b.subject_name, - count(c.subject_name) AS attended_exams + COUNT(c.subject_name) AS attended_exams FROM Students AS a CROSS JOIN Subjects AS b diff --git a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md index 376f4040cb128..c987160468c72 100644 --- a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md +++ b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README.md @@ -82,16 +82,16 @@ WITH T AS ( SELECT log_id, - sum(delta) OVER (ORDER BY log_id) AS pid + SUM(delta) OVER (ORDER BY log_id) AS pid FROM ( SELECT log_id, - if((log_id - lag(log_id) OVER (ORDER BY log_id)) = 1, 0, 1) AS delta + IF((log_id - LAG(log_id) OVER (ORDER BY log_id)) = 1, 0, 1) AS delta FROM Logs ) AS t ) -SELECT min(log_id) AS start_id, max(log_id) AS end_id +SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id FROM T GROUP BY pid; ``` @@ -102,10 +102,10 @@ WITH T AS ( SELECT log_id, - log_id - row_number() OVER (ORDER BY log_id) AS pid + log_id - ROW_NUMBER() OVER (ORDER BY log_id) AS pid FROM Logs ) -SELECT min(log_id) AS start_id, max(log_id) AS end_id +SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id FROM T GROUP BY pid; ``` diff --git a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md index 8ec77fc7c46a3..a607a0207bf8f 100644 --- a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md +++ b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/README_EN.md @@ -78,16 +78,16 @@ WITH T AS ( SELECT log_id, - sum(delta) OVER (ORDER BY log_id) AS pid + SUM(delta) OVER (ORDER BY log_id) AS pid FROM ( SELECT log_id, - if((log_id - lag(log_id) OVER (ORDER BY log_id)) = 1, 0, 1) AS delta + IF((log_id - LAG(log_id) OVER (ORDER BY log_id)) = 1, 0, 1) AS delta FROM Logs ) AS t ) -SELECT min(log_id) AS start_id, max(log_id) AS end_id +SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id FROM T GROUP BY pid; ``` @@ -98,10 +98,10 @@ WITH T AS ( SELECT log_id, - log_id - row_number() OVER (ORDER BY log_id) AS pid + log_id - ROW_NUMBER() OVER (ORDER BY log_id) AS pid FROM Logs ) -SELECT min(log_id) AS start_id, max(log_id) AS end_id +SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id FROM T GROUP BY pid; ``` diff --git a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql index 3bf1dc8356ccf..42aad40c48e6d 100644 --- a/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql +++ b/solution/1200-1299/1285.Find the Start and End Number of Continuous Ranges/Solution.sql @@ -3,9 +3,9 @@ WITH T AS ( SELECT log_id, - log_id-row_number() OVER (ORDER BY log_id) AS pid + log_id-ROW_NUMBER() OVER (ORDER BY log_id) AS pid FROM Logs ) -SELECT min(log_id) AS start_id, max(log_id) AS end_id +SELECT MIN(log_id) AS start_id, MAX(log_id) AS end_id FROM T GROUP BY pid; diff --git a/solution/1300-1399/1303.Find the Team Size/README.md b/solution/1300-1399/1303.Find the Team Size/README.md index 4b2194d0d4d8b..d13471385d6a0 100644 --- a/solution/1300-1399/1303.Find the Team Size/README.md +++ b/solution/1300-1399/1303.Find the Team Size/README.md @@ -81,7 +81,7 @@ ID 为 5、6 的员工是 team_id 为 9 的团队的成员。 # Write your MySQL query statement below WITH T AS ( - SELECT team_id, count(1) AS team_size + SELECT team_id, COUNT(1) AS team_size FROM Employee GROUP BY 1 ) @@ -93,7 +93,7 @@ FROM ```sql # Write your MySQL query statement below -SELECT e1.employee_id, count(1) AS team_size +SELECT e1.employee_id, COUNT(1) AS team_size FROM Employee AS e1 LEFT JOIN Employee AS e2 USING (team_id) diff --git a/solution/1300-1399/1303.Find the Team Size/README_EN.md b/solution/1300-1399/1303.Find the Team Size/README_EN.md index 8ad52757b78b8..d2fe3ebd15eab 100644 --- a/solution/1300-1399/1303.Find the Team Size/README_EN.md +++ b/solution/1300-1399/1303.Find the Team Size/README_EN.md @@ -76,7 +76,7 @@ We can also use a left join to join the `Employee` table with itself based on `t # Write your MySQL query statement below WITH T AS ( - SELECT team_id, count(1) AS team_size + SELECT team_id, COUNT(1) AS team_size FROM Employee GROUP BY 1 ) @@ -88,7 +88,7 @@ FROM ```sql # Write your MySQL query statement below -SELECT e1.employee_id, count(1) AS team_size +SELECT e1.employee_id, COUNT(1) AS team_size FROM Employee AS e1 LEFT JOIN Employee AS e2 USING (team_id) diff --git a/solution/1300-1399/1303.Find the Team Size/Solution.sql b/solution/1300-1399/1303.Find the Team Size/Solution.sql index e74f3d1501c74..73a15026525e7 100644 --- a/solution/1300-1399/1303.Find the Team Size/Solution.sql +++ b/solution/1300-1399/1303.Find the Team Size/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT e1.employee_id, count(1) AS team_size +SELECT e1.employee_id, COUNT(1) AS team_size FROM Employee AS e1 LEFT JOIN Employee AS e2 USING (team_id) diff --git a/solution/1300-1399/1308.Running Total for Different Genders/README.md b/solution/1300-1399/1308.Running Total for Different Genders/README.md index f9e55795328f4..c84aed84969ee 100644 --- a/solution/1300-1399/1308.Running Total for Different Genders/README.md +++ b/solution/1300-1399/1308.Running Total for Different Genders/README.md @@ -92,7 +92,7 @@ Scores表: SELECT gender, day, - sum(score_points) OVER ( + SUM(score_points) OVER ( PARTITION BY gender ORDER BY gender, day ) AS total diff --git a/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md b/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md index 4b859208cac05..b0eba97940ac1 100644 --- a/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md +++ b/solution/1300-1399/1308.Running Total for Different Genders/README_EN.md @@ -88,7 +88,7 @@ The fifth day is 2020-01-07, Bajrang scored 7 points and the total score for the SELECT gender, day, - sum(score_points) OVER ( + SUM(score_points) OVER ( PARTITION BY gender ORDER BY gender, day ) AS total diff --git a/solution/1300-1399/1308.Running Total for Different Genders/Solution.sql b/solution/1300-1399/1308.Running Total for Different Genders/Solution.sql index 52c09eb2e9327..2d66139b60775 100644 --- a/solution/1300-1399/1308.Running Total for Different Genders/Solution.sql +++ b/solution/1300-1399/1308.Running Total for Different Genders/Solution.sql @@ -2,7 +2,7 @@ SELECT gender, day, - sum(score_points) OVER ( + SUM(score_points) OVER ( PARTITION BY gender ORDER BY gender, day ) AS total diff --git a/solution/1300-1399/1321.Restaurant Growth/README.md b/solution/1300-1399/1321.Restaurant Growth/README.md index 6528eda911198..1fe8b4e3532d4 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README.md +++ b/solution/1300-1399/1321.Restaurant Growth/README.md @@ -84,22 +84,22 @@ WITH t AS ( SELECT visited_on, - sum(amount) OVER ( + SUM(amount) OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS amount, - rank() OVER ( + RANK() OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS rk FROM ( - SELECT visited_on, sum(amount) AS amount + SELECT visited_on, SUM(amount) AS amount FROM Customer GROUP BY visited_on ) AS tt ) -SELECT visited_on, amount, round(amount / 7, 2) AS average_amount +SELECT visited_on, amount, ROUND(amount / 7, 2) AS average_amount FROM t WHERE rk > 6; ``` diff --git a/solution/1300-1399/1321.Restaurant Growth/README_EN.md b/solution/1300-1399/1321.Restaurant Growth/README_EN.md index 874fb37dae755..5f60697e754ce 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README_EN.md +++ b/solution/1300-1399/1321.Restaurant Growth/README_EN.md @@ -80,22 +80,22 @@ WITH t AS ( SELECT visited_on, - sum(amount) OVER ( + SUM(amount) OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS amount, - rank() OVER ( + RANK() OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS rk FROM ( - SELECT visited_on, sum(amount) AS amount + SELECT visited_on, SUM(amount) AS amount FROM Customer GROUP BY visited_on ) AS tt ) -SELECT visited_on, amount, round(amount / 7, 2) AS average_amount +SELECT visited_on, amount, ROUND(amount / 7, 2) AS average_amount FROM t WHERE rk > 6; ``` diff --git a/solution/1300-1399/1321.Restaurant Growth/Solution.sql b/solution/1300-1399/1321.Restaurant Growth/Solution.sql index c36b256ccdf41..2e4e409218cb0 100644 --- a/solution/1300-1399/1321.Restaurant Growth/Solution.sql +++ b/solution/1300-1399/1321.Restaurant Growth/Solution.sql @@ -3,21 +3,21 @@ WITH t AS ( SELECT visited_on, - sum(amount) OVER ( + SUM(amount) OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS amount, - rank() OVER ( + RANK() OVER ( ORDER BY visited_on ROWS 6 PRECEDING ) AS rk FROM ( - SELECT visited_on, sum(amount) AS amount + SELECT visited_on, SUM(amount) AS amount FROM Customer GROUP BY visited_on ) AS tt ) -SELECT visited_on, amount, round(amount / 7, 2) AS average_amount +SELECT visited_on, amount, ROUND(amount / 7, 2) AS average_amount FROM t WHERE rk > 6; diff --git a/solution/1300-1399/1322.Ads Performance/README.md b/solution/1300-1399/1322.Ads Performance/README.md index 8374d04fc59a5..7142ac18f2de3 100644 --- a/solution/1300-1399/1322.Ads Performance/README.md +++ b/solution/1300-1399/1322.Ads Performance/README.md @@ -84,7 +84,7 @@ Ads 表: ```sql SELECT ad_id, - Ifnull(ROUND(AVG(CASE + IFNULL(ROUND(AVG(CASE WHEN action = 'Clicked' THEN 1 WHEN action = 'Viewed' THEN 0 ELSE NULL diff --git a/solution/1300-1399/1322.Ads Performance/README_EN.md b/solution/1300-1399/1322.Ads Performance/README_EN.md index fed4efe6eec8e..639466315e3b1 100644 --- a/solution/1300-1399/1322.Ads Performance/README_EN.md +++ b/solution/1300-1399/1322.Ads Performance/README_EN.md @@ -77,7 +77,7 @@ Note that we do not care about Ignored Ads. ```sql SELECT ad_id, - Ifnull(ROUND(AVG(CASE + IFNULL(ROUND(AVG(CASE WHEN action = 'Clicked' THEN 1 WHEN action = 'Viewed' THEN 0 ELSE NULL diff --git a/solution/1300-1399/1322.Ads Performance/Solution.sql b/solution/1300-1399/1322.Ads Performance/Solution.sql index f1c47a2661dff..8c22509445dd3 100644 --- a/solution/1300-1399/1322.Ads Performance/Solution.sql +++ b/solution/1300-1399/1322.Ads Performance/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT ad_id, - Ifnull( + IFNULL( ROUND( AVG( CASE diff --git a/solution/1300-1399/1327.List the Products Ordered in a Period/README.md b/solution/1300-1399/1327.List the Products Ordered in a Period/README.md index a9be24cc40bcb..f0bb2e1b1b2af 100644 --- a/solution/1300-1399/1327.List the Products Ordered in a Period/README.md +++ b/solution/1300-1399/1327.List the Products Ordered in a Period/README.md @@ -102,11 +102,11 @@ Orders 表: ```sql # Write your MySQL query statement below -SELECT product_name, sum(unit) AS unit +SELECT product_name, SUM(unit) AS unit FROM Orders AS o JOIN Products AS p ON o.product_id = p.product_id -WHERE date_format(order_date, '%Y-%m') = '2020-02' +WHERE DATE_FORMAT(order_date, '%Y-%m') = '2020-02' GROUP BY o.product_id HAVING unit >= 100; ``` diff --git a/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md b/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md index ef28a328651e6..819f3f5ea8e7f 100644 --- a/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md +++ b/solution/1300-1399/1327.List the Products Ordered in a Period/README_EN.md @@ -98,11 +98,11 @@ Products with product_id = 5 is ordered in February a total of (50 + 50) = 100. ```sql # Write your MySQL query statement below -SELECT product_name, sum(unit) AS unit +SELECT product_name, SUM(unit) AS unit FROM Orders AS o JOIN Products AS p ON o.product_id = p.product_id -WHERE date_format(order_date, '%Y-%m') = '2020-02' +WHERE DATE_FORMAT(order_date, '%Y-%m') = '2020-02' GROUP BY o.product_id HAVING unit >= 100; ``` diff --git a/solution/1300-1399/1327.List the Products Ordered in a Period/Solution.sql b/solution/1300-1399/1327.List the Products Ordered in a Period/Solution.sql index afce61ec61283..86d760f95273f 100644 --- a/solution/1300-1399/1327.List the Products Ordered in a Period/Solution.sql +++ b/solution/1300-1399/1327.List the Products Ordered in a Period/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below -SELECT product_name, sum(unit) AS unit +SELECT product_name, SUM(unit) AS unit FROM Orders AS o JOIN Products AS p ON o.product_id = p.product_id -WHERE date_format(order_date, '%Y-%m') = '2020-02' +WHERE DATE_FORMAT(order_date, '%Y-%m') = '2020-02' GROUP BY o.product_id HAVING unit >= 100; diff --git a/solution/1300-1399/1336.Number of Transactions per Visit/README.md b/solution/1300-1399/1336.Number of Transactions per Visit/README.md index 75553c94df8cb..bb5804db30a49 100644 --- a/solution/1300-1399/1336.Number of Transactions per Visit/README.md +++ b/solution/1300-1399/1336.Number of Transactions per Visit/README.md @@ -126,27 +126,27 @@ WITH RECURSIVE FROM S WHERE n < ( - SELECT max(cnt) + SELECT MAX(cnt) FROM ( - SELECT count(1) AS cnt + SELECT COUNT(1) AS cnt FROM Transactions GROUP BY user_id, transaction_date ) AS t ) ), T AS ( - SELECT v.user_id, visit_date, ifnull(cnt, 0) AS cnt + SELECT v.user_id, visit_date, IFNULL(cnt, 0) AS cnt FROM Visits AS v LEFT JOIN ( - SELECT user_id, transaction_date, count(1) AS cnt + SELECT user_id, transaction_date, COUNT(1) AS cnt FROM Transactions GROUP BY 1, 2 ) AS t ON v.user_id = t.user_id AND v.visit_date = t.transaction_date ) -SELECT n AS transactions_count, count(user_id) AS visits_count +SELECT n AS transactions_count, COUNT(user_id) AS visits_count FROM S AS s LEFT JOIN T AS t ON s.n = t.cnt diff --git a/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md b/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md index 8422253526742..51afba48b52b6 100644 --- a/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md +++ b/solution/1300-1399/1336.Number of Transactions per Visit/README_EN.md @@ -119,27 +119,27 @@ WITH RECURSIVE FROM S WHERE n < ( - SELECT max(cnt) + SELECT MAX(cnt) FROM ( - SELECT count(1) AS cnt + SELECT COUNT(1) AS cnt FROM Transactions GROUP BY user_id, transaction_date ) AS t ) ), T AS ( - SELECT v.user_id, visit_date, ifnull(cnt, 0) AS cnt + SELECT v.user_id, visit_date, IFNULL(cnt, 0) AS cnt FROM Visits AS v LEFT JOIN ( - SELECT user_id, transaction_date, count(1) AS cnt + SELECT user_id, transaction_date, COUNT(1) AS cnt FROM Transactions GROUP BY 1, 2 ) AS t ON v.user_id = t.user_id AND v.visit_date = t.transaction_date ) -SELECT n AS transactions_count, count(user_id) AS visits_count +SELECT n AS transactions_count, COUNT(user_id) AS visits_count FROM S AS s LEFT JOIN T AS t ON s.n = t.cnt diff --git a/solution/1300-1399/1336.Number of Transactions per Visit/Solution.sql b/solution/1300-1399/1336.Number of Transactions per Visit/Solution.sql index 59d43f0ff7dba..f57bf054ef16c 100644 --- a/solution/1300-1399/1336.Number of Transactions per Visit/Solution.sql +++ b/solution/1300-1399/1336.Number of Transactions per Visit/Solution.sql @@ -7,27 +7,27 @@ WITH RECURSIVE FROM S WHERE n < ( - SELECT max(cnt) + SELECT MAX(cnt) FROM ( - SELECT count(1) AS cnt + SELECT COUNT(1) AS cnt FROM Transactions GROUP BY user_id, transaction_date ) AS t ) ), T AS ( - SELECT v.user_id, visit_date, ifnull(cnt, 0) AS cnt + SELECT v.user_id, visit_date, IFNULL(cnt, 0) AS cnt FROM Visits AS v LEFT JOIN ( - SELECT user_id, transaction_date, count(1) AS cnt + SELECT user_id, transaction_date, COUNT(1) AS cnt FROM Transactions GROUP BY 1, 2 ) AS t ON v.user_id = t.user_id AND v.visit_date = t.transaction_date ) -SELECT n AS transactions_count, count(user_id) AS visits_count +SELECT n AS transactions_count, COUNT(user_id) AS visits_count FROM S AS s LEFT JOIN T AS t ON s.n = t.cnt diff --git a/solution/1300-1399/1341.Movie Rating/README.md b/solution/1300-1399/1341.Movie Rating/README.md index 40d68658c3e5b..be45ff2b80c99 100644 --- a/solution/1300-1399/1341.Movie Rating/README.md +++ b/solution/1300-1399/1341.Movie Rating/README.md @@ -130,7 +130,7 @@ Frozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序 Users JOIN MovieRating USING (user_id) GROUP BY user_id - ORDER BY count(1) DESC, name + ORDER BY COUNT(1) DESC, name LIMIT 1 ) UNION ALL @@ -139,9 +139,9 @@ UNION ALL FROM MovieRating JOIN Movies USING (movie_id) - WHERE date_format(created_at, '%Y-%m') = '2020-02' + WHERE DATE_FORMAT(created_at, '%Y-%m') = '2020-02' GROUP BY movie_id - ORDER BY avg(rating) DESC, title + ORDER BY AVG(rating) DESC, title LIMIT 1 ); ``` diff --git a/solution/1300-1399/1341.Movie Rating/README_EN.md b/solution/1300-1399/1341.Movie Rating/README_EN.md index 1d409d67b12c8..81a3830fbf061 100644 --- a/solution/1300-1399/1341.Movie Rating/README_EN.md +++ b/solution/1300-1399/1341.Movie Rating/README_EN.md @@ -122,7 +122,7 @@ Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smal Users JOIN MovieRating USING (user_id) GROUP BY user_id - ORDER BY count(1) DESC, name + ORDER BY COUNT(1) DESC, name LIMIT 1 ) UNION ALL @@ -131,9 +131,9 @@ UNION ALL FROM MovieRating JOIN Movies USING (movie_id) - WHERE date_format(created_at, '%Y-%m') = '2020-02' + WHERE DATE_FORMAT(created_at, '%Y-%m') = '2020-02' GROUP BY movie_id - ORDER BY avg(rating) DESC, title + ORDER BY AVG(rating) DESC, title LIMIT 1 ); ``` diff --git a/solution/1300-1399/1341.Movie Rating/Solution.sql b/solution/1300-1399/1341.Movie Rating/Solution.sql index c4ab5c2d3f949..7bceecc9da464 100644 --- a/solution/1300-1399/1341.Movie Rating/Solution.sql +++ b/solution/1300-1399/1341.Movie Rating/Solution.sql @@ -5,7 +5,7 @@ Users JOIN MovieRating USING (user_id) GROUP BY user_id - ORDER BY count(1) DESC, name + ORDER BY COUNT(1) DESC, name LIMIT 1 ) UNION ALL @@ -14,8 +14,8 @@ UNION ALL FROM MovieRating JOIN Movies USING (movie_id) - WHERE date_format(created_at, '%Y-%m') = '2020-02' + WHERE DATE_FORMAT(created_at, '%Y-%m') = '2020-02' GROUP BY movie_id - ORDER BY avg(rating) DESC, title + ORDER BY AVG(rating) DESC, title LIMIT 1 ); diff --git a/solution/1300-1399/1355.Activity Participants/README.md b/solution/1300-1399/1355.Activity Participants/README.md index db273926560ea..b12d4e1466354 100644 --- a/solution/1300-1399/1355.Activity Participants/README.md +++ b/solution/1300-1399/1355.Activity Participants/README.md @@ -94,13 +94,13 @@ Singing 活动有两个人参加 (Victor J. and Jade W.) # Write your MySQL query statement below WITH t AS ( - SELECT activity, count(1) AS cnt + SELECT activity, COUNT(1) AS cnt FROM Friends GROUP BY activity ) SELECT activity FROM t -WHERE cnt > (SELECT min(cnt) FROM t) AND cnt < (SELECT max(cnt) FROM t); +WHERE cnt > (SELECT MIN(cnt) FROM t) AND cnt < (SELECT MAX(cnt) FROM t); ``` diff --git a/solution/1300-1399/1355.Activity Participants/README_EN.md b/solution/1300-1399/1355.Activity Participants/README_EN.md index fa457580debf8..a1528a292eb25 100644 --- a/solution/1300-1399/1355.Activity Participants/README_EN.md +++ b/solution/1300-1399/1355.Activity Participants/README_EN.md @@ -90,13 +90,13 @@ Singing is performed by 2 friends (Victor J. and Jade W.) # Write your MySQL query statement below WITH t AS ( - SELECT activity, count(1) AS cnt + SELECT activity, COUNT(1) AS cnt FROM Friends GROUP BY activity ) SELECT activity FROM t -WHERE cnt > (SELECT min(cnt) FROM t) AND cnt < (SELECT max(cnt) FROM t); +WHERE cnt > (SELECT MIN(cnt) FROM t) AND cnt < (SELECT MAX(cnt) FROM t); ``` diff --git a/solution/1300-1399/1355.Activity Participants/Solution.sql b/solution/1300-1399/1355.Activity Participants/Solution.sql index e62a05b60cf77..daf0e8e34bd45 100644 --- a/solution/1300-1399/1355.Activity Participants/Solution.sql +++ b/solution/1300-1399/1355.Activity Participants/Solution.sql @@ -1,10 +1,10 @@ # Write your MySQL query statement below WITH t AS ( - SELECT activity, count(1) AS cnt + SELECT activity, COUNT(1) AS cnt FROM Friends GROUP BY activity ) SELECT activity FROM t -WHERE cnt > (SELECT min(cnt) FROM t) AND cnt < (SELECT max(cnt) FROM t); +WHERE cnt > (SELECT MIN(cnt) FROM t) AND cnt < (SELECT MAX(cnt) FROM t); diff --git a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md index f841cc2b1e681..794aa2907ff72 100644 --- a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md +++ b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README.md @@ -137,8 +137,8 @@ SELECT invoice_id, t2.customer_name, price, - count(t3.user_id) AS contacts_cnt, - count(t4.email) AS trusted_contacts_cnt + COUNT(t3.user_id) AS contacts_cnt, + COUNT(t4.email) AS trusted_contacts_cnt FROM Invoices AS t1 LEFT JOIN Customers AS t2 ON t1.user_id = t2.customer_id diff --git a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md index 24f16abab17cb..d25fd21d3c078 100644 --- a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md +++ b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/README_EN.md @@ -132,8 +132,8 @@ SELECT invoice_id, t2.customer_name, price, - count(t3.user_id) AS contacts_cnt, - count(t4.email) AS trusted_contacts_cnt + COUNT(t3.user_id) AS contacts_cnt, + COUNT(t4.email) AS trusted_contacts_cnt FROM Invoices AS t1 LEFT JOIN Customers AS t2 ON t1.user_id = t2.customer_id diff --git a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/Solution.sql b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/Solution.sql index bc5e116d96e68..ef12d33011d53 100644 --- a/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/Solution.sql +++ b/solution/1300-1399/1364.Number of Trusted Contacts of a Customer/Solution.sql @@ -3,8 +3,8 @@ SELECT invoice_id, t2.customer_name, price, - count(t3.user_id) AS contacts_cnt, - count(t4.email) AS trusted_contacts_cnt + COUNT(t3.user_id) AS contacts_cnt, + COUNT(t4.email) AS trusted_contacts_cnt FROM Invoices AS t1 LEFT JOIN Customers AS t2 ON t1.user_id = t2.customer_id diff --git a/solution/1300-1399/1384.Total Sales Amount by Year/README.md b/solution/1300-1399/1384.Total Sales Amount by Year/README.md index 8072e8b356a33..e30d0fa765add 100644 --- a/solution/1300-1399/1384.Total Sales Amount by Year/README.md +++ b/solution/1300-1399/1384.Total Sales Amount by Year/README.md @@ -99,14 +99,14 @@ SELECT p.product_name, y.YEAR report_year, s.average_daily_sales * ( - IF ( - YEAR (s.period_end) > y.YEAR, + IF( + YEAR(s.period_end) > y.YEAR, y.days_of_year, - dayofyear(s.period_end) - ) - IF ( - YEAR (s.period_start) < y.YEAR, + DAYOFYEAR(s.period_end) + ) - IF( + YEAR(s.period_start) < y.YEAR, 1, - dayofyear(s.period_start) + DAYOFYEAR(s.period_start) ) + 1 ) total_amount FROM @@ -125,8 +125,8 @@ FROM SELECT '2020' YEAR, 366 days_of_year - ) y ON YEAR (s.period_start) <= y.YEAR - AND YEAR (s.period_end) >= y.YEAR + ) y ON YEAR(s.period_start) <= y.YEAR + AND YEAR(s.period_end) >= y.YEAR INNER JOIN Product p ON p.product_id = s.product_id ORDER BY s.product_id, diff --git a/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md b/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md index f825933ff2f03..410ca2456a16c 100644 --- a/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md +++ b/solution/1300-1399/1384.Total Sales Amount by Year/README_EN.md @@ -95,14 +95,14 @@ SELECT p.product_name, y.YEAR report_year, s.average_daily_sales * ( - IF ( - YEAR (s.period_end) > y.YEAR, + IF( + YEAR(s.period_end) > y.YEAR, y.days_of_year, - dayofyear(s.period_end) - ) - IF ( - YEAR (s.period_start) < y.YEAR, + DAYOFYEAR(s.period_end) + ) - IF( + YEAR(s.period_start) < y.YEAR, 1, - dayofyear(s.period_start) + DAYOFYEAR(s.period_start) ) + 1 ) total_amount FROM @@ -121,8 +121,8 @@ FROM SELECT '2020' YEAR, 366 days_of_year - ) y ON YEAR (s.period_start) <= y.YEAR - AND YEAR (s.period_end) >= y.YEAR + ) y ON YEAR(s.period_start) <= y.YEAR + AND YEAR(s.period_end) >= y.YEAR INNER JOIN Product p ON p.product_id = s.product_id ORDER BY s.product_id, diff --git a/solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql b/solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql index 57b1387b3632b..3fee88191fc23 100644 --- a/solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql +++ b/solution/1300-1399/1384.Total Sales Amount by Year/Solution.sql @@ -4,10 +4,10 @@ SELECT p.product_name, y.YEAR AS report_year, s.average_daily_sales * ( - IF(YEAR(s.period_end) > y.YEAR, y.days_of_year, dayofyear(s.period_end)) - IF( + IF(YEAR(s.period_end) > y.YEAR, y.days_of_year, DAYOFYEAR(s.period_end)) - IF( YEAR(s.period_start) < y.YEAR, 1, - dayofyear(s.period_start) + DAYOFYEAR(s.period_start) ) + 1 ) AS total_amount FROM diff --git a/solution/1300-1399/1393.Capital GainLoss/README.md b/solution/1300-1399/1393.Capital GainLoss/README.md index 1c95164896b8c..d373e5c015940 100644 --- a/solution/1300-1399/1393.Capital GainLoss/README.md +++ b/solution/1300-1399/1393.Capital GainLoss/README.md @@ -84,7 +84,7 @@ Corona Masks 股票在第1天以10美元的价格买入,在第3天以1010美 # Write your MySQL query statement below SELECT stock_name, - sum(if(operation = 'Buy', -price, price)) AS capital_gain_loss + SUM(IF(operation = 'Buy', -price, price)) AS capital_gain_loss FROM Stocks GROUP BY 1; ``` diff --git a/solution/1300-1399/1393.Capital GainLoss/README_EN.md b/solution/1300-1399/1393.Capital GainLoss/README_EN.md index 728576f456c8e..ce9bd1dffb553 100644 --- a/solution/1300-1399/1393.Capital GainLoss/README_EN.md +++ b/solution/1300-1399/1393.Capital GainLoss/README_EN.md @@ -75,7 +75,7 @@ Corona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. # Write your MySQL query statement below SELECT stock_name, - sum(if(operation = 'Buy', -price, price)) AS capital_gain_loss + SUM(IF(operation = 'Buy', -price, price)) AS capital_gain_loss FROM Stocks GROUP BY 1; ``` diff --git a/solution/1300-1399/1393.Capital GainLoss/Solution.sql b/solution/1300-1399/1393.Capital GainLoss/Solution.sql index a8fe65dbebd5f..2a3b710dec8a2 100644 --- a/solution/1300-1399/1393.Capital GainLoss/Solution.sql +++ b/solution/1300-1399/1393.Capital GainLoss/Solution.sql @@ -1,6 +1,6 @@ # Write your MySQL query statement below SELECT stock_name, - sum(if(operation = 'Buy', -price, price)) AS capital_gain_loss + SUM(IF(operation = 'Buy', -price, price)) AS capital_gain_loss FROM Stocks GROUP BY 1; diff --git a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md index 521ea163e5a85..15245dea69032 100644 --- a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md +++ b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README.md @@ -100,7 +100,7 @@ FROM Customers LEFT JOIN Orders USING (customer_id) GROUP BY 1 -HAVING sum(product_name = 'A') > 0 AND sum(product_name = 'B') > 0 AND sum(product_name = 'C') = 0 +HAVING SUM(product_name = 'A') > 0 AND SUM(product_name = 'B') > 0 AND SUM(product_name = 'C') = 0 ORDER BY 1; ``` diff --git a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md index 3ec0ebb5d65fa..4f2f79ffaf01b 100644 --- a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md +++ b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/README_EN.md @@ -94,7 +94,7 @@ FROM Customers LEFT JOIN Orders USING (customer_id) GROUP BY 1 -HAVING sum(product_name = 'A') > 0 AND sum(product_name = 'B') > 0 AND sum(product_name = 'C') = 0 +HAVING SUM(product_name = 'A') > 0 AND SUM(product_name = 'B') > 0 AND SUM(product_name = 'C') = 0 ORDER BY 1; ``` diff --git a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql index 735f6646cd394..a26d0259073c1 100644 --- a/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql +++ b/solution/1300-1399/1398.Customers Who Bought Products A and B but Not C/Solution.sql @@ -4,5 +4,5 @@ FROM Customers LEFT JOIN Orders USING (customer_id) GROUP BY 1 -HAVING sum(product_name = 'A') > 0 AND sum(product_name = 'B') > 0 AND sum(product_name = 'C') = 0 +HAVING SUM(product_name = 'A') > 0 AND SUM(product_name = 'B') > 0 AND SUM(product_name = 'C') = 0 ORDER BY 1; diff --git a/solution/1400-1499/1407.Top Travellers/README.md b/solution/1400-1499/1407.Top Travellers/README.md index 2c1d1a85a63e1..64eb05d82ef5e 100644 --- a/solution/1400-1499/1407.Top Travellers/README.md +++ b/solution/1400-1499/1407.Top Travellers/README.md @@ -107,7 +107,7 @@ Donald 没有任何行程, 他的旅行距离为 0。 ```sql # Write your MySQL query statement below -SELECT name, ifnull(sum(distance), 0) AS travelled_distance +SELECT name, IFNULL(SUM(distance), 0) AS travelled_distance FROM Users AS u LEFT JOIN Rides AS r ON u.id = r.user_id diff --git a/solution/1400-1499/1407.Top Travellers/README_EN.md b/solution/1400-1499/1407.Top Travellers/README_EN.md index d4fc1c476b4c8..0302c0af89e01 100644 --- a/solution/1400-1499/1407.Top Travellers/README_EN.md +++ b/solution/1400-1499/1407.Top Travellers/README_EN.md @@ -102,7 +102,7 @@ We can use a left join to join the `Users` table with the `Rides` table on the c ```sql # Write your MySQL query statement below -SELECT name, ifnull(sum(distance), 0) AS travelled_distance +SELECT name, IFNULL(SUM(distance), 0) AS travelled_distance FROM Users AS u LEFT JOIN Rides AS r ON u.id = r.user_id diff --git a/solution/1400-1499/1407.Top Travellers/Solution.sql b/solution/1400-1499/1407.Top Travellers/Solution.sql index c0bdc190b09ee..c69ce6429b71b 100644 --- a/solution/1400-1499/1407.Top Travellers/Solution.sql +++ b/solution/1400-1499/1407.Top Travellers/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT name, ifnull(sum(distance), 0) AS travelled_distance +SELECT name, IFNULL(SUM(distance), 0) AS travelled_distance FROM Users AS u LEFT JOIN Rides AS r ON u.id = r.user_id diff --git a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md index d23cbb8ab126e..0f50e42d94a93 100644 --- a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md +++ b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README.md @@ -109,11 +109,11 @@ WITH T AS ( SELECT student_id, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score ) AS rk1, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score DESC ) AS rk2 @@ -124,7 +124,7 @@ FROM T JOIN Student USING (student_id) GROUP BY 1 -HAVING sum(rk1 = 1) = 0 AND sum(rk2 = 1) = 0 +HAVING SUM(rk1 = 1) = 0 AND SUM(rk2 = 1) = 0 ORDER BY 1; ``` diff --git a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md index 8ce24a660a334..a9c2ebc5372a4 100644 --- a/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md +++ b/solution/1400-1499/1412.Find the Quiet Students in All Exams/README_EN.md @@ -105,11 +105,11 @@ WITH T AS ( SELECT student_id, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score ) AS rk1, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score DESC ) AS rk2 @@ -120,7 +120,7 @@ FROM T JOIN Student USING (student_id) GROUP BY 1 -HAVING sum(rk1 = 1) = 0 AND sum(rk2 = 1) = 0 +HAVING SUM(rk1 = 1) = 0 AND SUM(rk2 = 1) = 0 ORDER BY 1; ``` diff --git a/solution/1400-1499/1412.Find the Quiet Students in All Exams/Solution.sql b/solution/1400-1499/1412.Find the Quiet Students in All Exams/Solution.sql index 5dfa41a6ebc1e..fbc2bcc58682e 100644 --- a/solution/1400-1499/1412.Find the Quiet Students in All Exams/Solution.sql +++ b/solution/1400-1499/1412.Find the Quiet Students in All Exams/Solution.sql @@ -3,11 +3,11 @@ WITH T AS ( SELECT student_id, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score ) AS rk1, - rank() OVER ( + RANK() OVER ( PARTITION BY exam_id ORDER BY score DESC ) AS rk2 @@ -18,5 +18,5 @@ FROM T JOIN Student USING (student_id) GROUP BY 1 -HAVING sum(rk1 = 1) = 0 AND sum(rk2 = 1) = 0 +HAVING SUM(rk1 = 1) = 0 AND SUM(rk2 = 1) = 0 ORDER BY 1; diff --git a/solution/1400-1499/1421.NPV Queries/README.md b/solution/1400-1499/1421.NPV Queries/README.md index b3b342a004926..d982ae2444bbc 100644 --- a/solution/1400-1499/1421.NPV Queries/README.md +++ b/solution/1400-1499/1421.NPV Queries/README.md @@ -102,7 +102,7 @@ Queries 表: ```sql # Write your MySQL query statement below -SELECT q.*, ifnull(npv, 0) AS npv +SELECT q.*, IFNULL(npv, 0) AS npv FROM Queries AS q LEFT JOIN NPV AS n USING (id, year); diff --git a/solution/1400-1499/1421.NPV Queries/README_EN.md b/solution/1400-1499/1421.NPV Queries/README_EN.md index b7dc3344a7e8d..f451a4956686f 100644 --- a/solution/1400-1499/1421.NPV Queries/README_EN.md +++ b/solution/1400-1499/1421.NPV Queries/README_EN.md @@ -96,7 +96,7 @@ The npv values of all other queries can be found in the NPV table. ```sql # Write your MySQL query statement below -SELECT q.*, ifnull(npv, 0) AS npv +SELECT q.*, IFNULL(npv, 0) AS npv FROM Queries AS q LEFT JOIN NPV AS n USING (id, year); diff --git a/solution/1400-1499/1421.NPV Queries/Solution.sql b/solution/1400-1499/1421.NPV Queries/Solution.sql index 690052be2e7a5..c417f87140422 100644 --- a/solution/1400-1499/1421.NPV Queries/Solution.sql +++ b/solution/1400-1499/1421.NPV Queries/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT q.*, ifnull(npv, 0) AS npv +SELECT q.*, IFNULL(npv, 0) AS npv FROM Queries AS q LEFT JOIN NPV AS n USING (id, year); diff --git a/solution/1400-1499/1445.Apples & Oranges/README.md b/solution/1400-1499/1445.Apples & Oranges/README.md index 4598b25cee8b7..588352c42af30 100644 --- a/solution/1400-1499/1445.Apples & Oranges/README.md +++ b/solution/1400-1499/1445.Apples & Oranges/README.md @@ -79,7 +79,7 @@ Sales 表: # Write your MySQL query statement below SELECT sale_date, - sum(if(fruit = 'apples', sold_num, -sold_num)) AS diff + SUM(IF(fruit = 'apples', sold_num, -sold_num)) AS diff FROM Sales GROUP BY 1 ORDER BY 1; diff --git a/solution/1400-1499/1445.Apples & Oranges/README_EN.md b/solution/1400-1499/1445.Apples & Oranges/README_EN.md index 18cfcecfb9b9d..f4a386197b035 100644 --- a/solution/1400-1499/1445.Apples & Oranges/README_EN.md +++ b/solution/1400-1499/1445.Apples & Oranges/README_EN.md @@ -74,7 +74,7 @@ We can group the data by date, and then use the `sum` function to calculate the # Write your MySQL query statement below SELECT sale_date, - sum(if(fruit = 'apples', sold_num, -sold_num)) AS diff + SUM(IF(fruit = 'apples', sold_num, -sold_num)) AS diff FROM Sales GROUP BY 1 ORDER BY 1; diff --git a/solution/1400-1499/1445.Apples & Oranges/Solution.sql b/solution/1400-1499/1445.Apples & Oranges/Solution.sql index 2b7eb80a5973f..35a05824014dd 100644 --- a/solution/1400-1499/1445.Apples & Oranges/Solution.sql +++ b/solution/1400-1499/1445.Apples & Oranges/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT sale_date, - sum(if(fruit = 'apples', sold_num, -sold_num)) AS diff + SUM(IF(fruit = 'apples', sold_num, -sold_num)) AS diff FROM Sales GROUP BY 1 ORDER BY 1; diff --git a/solution/1400-1499/1454.Active Users/README.md b/solution/1400-1499/1454.Active Users/README.md index 6b13bd94262ce..07c3993c990d0 100644 --- a/solution/1400-1499/1454.Active Users/README.md +++ b/solution/1400-1499/1454.Active Users/README.md @@ -100,7 +100,7 @@ id = 7 的用户 Jonathon 在不同的 6 天内登录了 7 次, , 6 天中有 5 # Write your MySQL query statement below WITH t AS (SELECT *, - sum(id) over(partition by id + SUM(id) over(partition by id ORDER BY login_date range interval 4 day preceding)/id cnt FROM (SELECT DISTINCT * diff --git a/solution/1400-1499/1454.Active Users/README_EN.md b/solution/1400-1499/1454.Active Users/README_EN.md index 0a05564854218..6a758c69c7314 100644 --- a/solution/1400-1499/1454.Active Users/README_EN.md +++ b/solution/1400-1499/1454.Active Users/README_EN.md @@ -92,7 +92,7 @@ User Jonathan with id = 7 logged in 7 times in 6 different days, five of them we # Write your MySQL query statement below WITH t AS (SELECT *, - sum(id) over(partition by id + SUM(id) over(partition by id ORDER BY login_date range interval 4 day preceding)/id cnt FROM (SELECT DISTINCT * diff --git a/solution/1400-1499/1454.Active Users/Solution.sql b/solution/1400-1499/1454.Active Users/Solution.sql index f1787bdd9a81b..5da5fda07fa8b 100644 --- a/solution/1400-1499/1454.Active Users/Solution.sql +++ b/solution/1400-1499/1454.Active Users/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below WITH t AS (SELECT *, - sum(id) over(partition by id + SUM(id) over(partition by id ORDER BY login_date range interval 4 day preceding)/id cnt FROM (SELECT DISTINCT * diff --git a/solution/1400-1499/1459.Rectangles Area/README.md b/solution/1400-1499/1459.Rectangles Area/README.md index fdf63f39775ef..b0e738205b308 100644 --- a/solution/1400-1499/1459.Rectangles Area/README.md +++ b/solution/1400-1499/1459.Rectangles Area/README.md @@ -76,7 +76,7 @@ p1 = 1 且 p2 = 3 时, 是不可能为矩形的, 面积等于 0 SELECT p1.id AS p1, p2.id AS p2, - abs(p1.x_value - p2.x_value) * abs(p1.y_value - p2.y_value) AS area + ABS(p1.x_value - p2.x_value) * ABS(p1.y_value - p2.y_value) AS area FROM Points AS p1 JOIN Points AS p2 ON p1.id < p2.id diff --git a/solution/1400-1499/1459.Rectangles Area/README_EN.md b/solution/1400-1499/1459.Rectangles Area/README_EN.md index a7e6bda6dd643..30a490b2e2e12 100644 --- a/solution/1400-1499/1459.Rectangles Area/README_EN.md +++ b/solution/1400-1499/1459.Rectangles Area/README_EN.md @@ -69,7 +69,7 @@ Note that the rectangle formed by p1 = 1 and p2 = 3 is invalid because the area SELECT p1.id AS p1, p2.id AS p2, - abs(p1.x_value - p2.x_value) * abs(p1.y_value - p2.y_value) AS area + ABS(p1.x_value - p2.x_value) * ABS(p1.y_value - p2.y_value) AS area FROM Points AS p1 JOIN Points AS p2 ON p1.id < p2.id diff --git a/solution/1400-1499/1459.Rectangles Area/Solution.sql b/solution/1400-1499/1459.Rectangles Area/Solution.sql index e295a4f881f32..8bb46b9a28a7c 100644 --- a/solution/1400-1499/1459.Rectangles Area/Solution.sql +++ b/solution/1400-1499/1459.Rectangles Area/Solution.sql @@ -2,7 +2,7 @@ SELECT p1.id AS p1, p2.id AS p2, - abs(p1.x_value - p2.x_value) * abs(p1.y_value - p2.y_value) AS area + ABS(p1.x_value - p2.x_value) * ABS(p1.y_value - p2.y_value) AS area FROM Points AS p1 JOIN Points AS p2 ON p1.id < p2.id diff --git a/solution/1400-1499/1468.Calculate Salaries/README.md b/solution/1400-1499/1468.Calculate Salaries/README.md index cbe669591cb84..901f4df2e3615 100644 --- a/solution/1400-1499/1468.Calculate Salaries/README.md +++ b/solution/1400-1499/1468.Calculate Salaries/README.md @@ -94,7 +94,7 @@ SELECT s.company_id, employee_id, employee_name, - round( + ROUND( CASE WHEN top < 1000 THEN salary WHEN top >= 1000 @@ -105,7 +105,7 @@ SELECT FROM Salaries AS s JOIN ( - SELECT company_id, max(salary) AS top + SELECT company_id, MAX(salary) AS top FROM Salaries GROUP BY company_id ) AS t diff --git a/solution/1400-1499/1468.Calculate Salaries/README_EN.md b/solution/1400-1499/1468.Calculate Salaries/README_EN.md index a78ffbdcbcacb..80133acfd2471 100644 --- a/solution/1400-1499/1468.Calculate Salaries/README_EN.md +++ b/solution/1400-1499/1468.Calculate Salaries/README_EN.md @@ -90,7 +90,7 @@ SELECT s.company_id, employee_id, employee_name, - round( + ROUND( CASE WHEN top < 1000 THEN salary WHEN top >= 1000 @@ -101,7 +101,7 @@ SELECT FROM Salaries AS s JOIN ( - SELECT company_id, max(salary) AS top + SELECT company_id, MAX(salary) AS top FROM Salaries GROUP BY company_id ) AS t diff --git a/solution/1400-1499/1468.Calculate Salaries/Solution.sql b/solution/1400-1499/1468.Calculate Salaries/Solution.sql index 0c0c059b99170..61fdcfa8970e2 100644 --- a/solution/1400-1499/1468.Calculate Salaries/Solution.sql +++ b/solution/1400-1499/1468.Calculate Salaries/Solution.sql @@ -3,7 +3,7 @@ SELECT s.company_id, employee_id, employee_name, - round( + ROUND( CASE WHEN top < 1000 THEN salary WHEN top >= 1000 @@ -14,7 +14,7 @@ SELECT FROM Salaries AS s JOIN ( - SELECT company_id, max(salary) AS top + SELECT company_id, MAX(salary) AS top FROM Salaries GROUP BY company_id ) AS t diff --git a/solution/1400-1499/1479.Sales by Day of the Week/README.md b/solution/1400-1499/1479.Sales by Day of the Week/README.md index 522b4d89d910f..9632b165f7e6d 100644 --- a/solution/1400-1499/1479.Sales by Day of the Week/README.md +++ b/solution/1400-1499/1479.Sales by Day of the Week/README.md @@ -110,13 +110,13 @@ Orders 表: # Write your MySQL query statement below SELECT item_category AS category, - sum(if(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, - sum(if(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, - sum(if(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, - sum(if(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, - sum(if(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, - sum(if(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, - sum(if(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday + SUM(IF(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, + SUM(IF(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, + SUM(IF(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, + SUM(IF(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, + SUM(IF(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, + SUM(IF(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, + SUM(IF(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday FROM Orders AS o RIGHT JOIN Items AS i ON o.item_id = i.item_id diff --git a/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md b/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md index aa72c20d2c453..b1f41e4f28315 100644 --- a/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md +++ b/solution/1400-1499/1479.Sales by Day of the Week/README_EN.md @@ -108,13 +108,13 @@ There are no sales of T-shirts. # Write your MySQL query statement below SELECT item_category AS category, - sum(if(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, - sum(if(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, - sum(if(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, - sum(if(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, - sum(if(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, - sum(if(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, - sum(if(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday + SUM(IF(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, + SUM(IF(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, + SUM(IF(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, + SUM(IF(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, + SUM(IF(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, + SUM(IF(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, + SUM(IF(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday FROM Orders AS o RIGHT JOIN Items AS i ON o.item_id = i.item_id diff --git a/solution/1400-1499/1479.Sales by Day of the Week/Solution.sql b/solution/1400-1499/1479.Sales by Day of the Week/Solution.sql index ea04185b9d411..2464fbff1a441 100644 --- a/solution/1400-1499/1479.Sales by Day of the Week/Solution.sql +++ b/solution/1400-1499/1479.Sales by Day of the Week/Solution.sql @@ -1,13 +1,13 @@ # Write your MySQL query statement below SELECT item_category AS category, - sum(if(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, - sum(if(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, - sum(if(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, - sum(if(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, - sum(if(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, - sum(if(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, - sum(if(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday + SUM(IF(DAYOFWEEK(order_date) = '2', quantity, 0)) AS Monday, + SUM(IF(DAYOFWEEK(order_date) = '3', quantity, 0)) AS Tuesday, + SUM(IF(DAYOFWEEK(order_date) = '4', quantity, 0)) AS Wednesday, + SUM(IF(DAYOFWEEK(order_date) = '5', quantity, 0)) AS Thursday, + SUM(IF(DAYOFWEEK(order_date) = '6', quantity, 0)) AS Friday, + SUM(IF(DAYOFWEEK(order_date) = '7', quantity, 0)) AS Saturday, + SUM(IF(DAYOFWEEK(order_date) = '1', quantity, 0)) AS Sunday FROM Orders AS o RIGHT JOIN Items AS i ON o.item_id = i.item_id diff --git a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md index 60a54f7d04787..68d86d16ea7aa 100644 --- a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md +++ b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README.md @@ -106,7 +106,7 @@ FROM TVProgram JOIN Content USING (content_id) WHERE - date_format(program_date, '%Y%m') = '202006' + DATE_FORMAT(program_date, '%Y%m') = '202006' AND kids_content = 'Y' AND content_type = 'Movies'; ``` diff --git a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md index b3e14e81307ba..9b9981f1c5c20 100644 --- a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md +++ b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/README_EN.md @@ -100,7 +100,7 @@ FROM TVProgram JOIN Content USING (content_id) WHERE - date_format(program_date, '%Y%m') = '202006' + DATE_FORMAT(program_date, '%Y%m') = '202006' AND kids_content = 'Y' AND content_type = 'Movies'; ``` diff --git a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/Solution.sql b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/Solution.sql index 85b242354030b..73c50ebb9598b 100644 --- a/solution/1400-1499/1495.Friendly Movies Streamed Last Month/Solution.sql +++ b/solution/1400-1499/1495.Friendly Movies Streamed Last Month/Solution.sql @@ -4,6 +4,6 @@ FROM TVProgram JOIN Content USING (content_id) WHERE - date_format(program_date, '%Y%m') = '202006' + DATE_FORMAT(program_date, '%Y%m') = '202006' AND kids_content = 'Y' AND content_type = 'Movies'; diff --git a/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md b/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md index 677248ac43db3..adc553702b5ca 100644 --- a/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md +++ b/solution/1500-1599/1501.Countries You Can Safely Invest In/README.md @@ -135,30 +135,30 @@ Calls 表: SELECT country FROM ( - SELECT c.name AS country, avg(duration) AS duration + SELECT c.name AS country, AVG(duration) AS duration FROM Person - JOIN Calls ON id IN (caller_id, callee_id) - JOIN Country AS c ON left(phone_number, 3) = country_code + JOIN Calls ON id IN(caller_id, callee_id) + JOIN Country AS c ON LEFT(phone_number, 3) = country_code GROUP BY 1 ) AS t -WHERE duration > (SELECT avg(duration) FROM Calls); +WHERE duration > (SELECT AVG(duration) FROM Calls); ``` ```sql # Write your MySQL query statement below WITH T AS ( - SELECT c.name AS country, avg(duration) AS duration + SELECT c.name AS country, AVG(duration) AS duration FROM Person - JOIN Calls ON id IN (caller_id, callee_id) - JOIN Country AS c ON left(phone_number, 3) = country_code + JOIN Calls ON id IN(caller_id, callee_id) + JOIN Country AS c ON LEFT(phone_number, 3) = country_code GROUP BY 1 ) SELECT country FROM T -WHERE duration > (SELECT avg(duration) FROM Calls); +WHERE duration > (SELECT AVG(duration) FROM Calls); ``` diff --git a/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md b/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md index f176ece300e37..ee4fd8ccfefe6 100644 --- a/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md +++ b/solution/1500-1599/1501.Countries You Can Safely Invest In/README_EN.md @@ -130,30 +130,30 @@ We can use an equi-join to join the `Person` table and the `Calls` table on the SELECT country FROM ( - SELECT c.name AS country, avg(duration) AS duration + SELECT c.name AS country, AVG(duration) AS duration FROM Person - JOIN Calls ON id IN (caller_id, callee_id) - JOIN Country AS c ON left(phone_number, 3) = country_code + JOIN Calls ON id IN(caller_id, callee_id) + JOIN Country AS c ON LEFT(phone_number, 3) = country_code GROUP BY 1 ) AS t -WHERE duration > (SELECT avg(duration) FROM Calls); +WHERE duration > (SELECT AVG(duration) FROM Calls); ``` ```sql # Write your MySQL query statement below WITH T AS ( - SELECT c.name AS country, avg(duration) AS duration + SELECT c.name AS country, AVG(duration) AS duration FROM Person - JOIN Calls ON id IN (caller_id, callee_id) - JOIN Country AS c ON left(phone_number, 3) = country_code + JOIN Calls ON id IN(caller_id, callee_id) + JOIN Country AS c ON LEFT(phone_number, 3) = country_code GROUP BY 1 ) SELECT country FROM T -WHERE duration > (SELECT avg(duration) FROM Calls); +WHERE duration > (SELECT AVG(duration) FROM Calls); ``` diff --git a/solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql b/solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql index 5f7040df8ae20..32d57e1223b29 100644 --- a/solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql +++ b/solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql @@ -1,13 +1,13 @@ # Write your MySQL query statement below WITH T AS ( - SELECT c.name AS country, avg(duration) AS duration + SELECT c.name AS country, AVG(duration) AS duration FROM Person JOIN Calls ON id IN (caller_id, callee_id) - JOIN Country AS c ON left(phone_number, 3) = country_code + JOIN Country AS c ON LEFT(phone_number, 3) = country_code GROUP BY 1 ) SELECT country FROM T -WHERE duration > (SELECT avg(duration) FROM Calls); +WHERE duration > (SELECT AVG(duration) FROM Calls); diff --git a/solution/1500-1599/1511.Customer Order Frequency/README.md b/solution/1500-1599/1511.Customer Order Frequency/README.md index d48a056cc26e7..d7720fb828436 100644 --- a/solution/1500-1599/1511.Customer Order Frequency/README.md +++ b/solution/1500-1599/1511.Customer Order Frequency/README.md @@ -132,11 +132,11 @@ FROM Orders JOIN Product USING (product_id) JOIN Customers USING (customer_id) -WHERE year(order_date) = 2020 +WHERE YEAR(order_date) = 2020 GROUP BY 1 HAVING - sum(if(month(order_date) = 6, quantity * price, 0)) >= 100 - AND sum(if(month(order_date) = 7, quantity * price, 0)) >= 100; + SUM(IF(MONTH(order_date) = 6, quantity * price, 0)) >= 100 + AND SUM(IF(MONTH(order_date) = 7, quantity * price, 0)) >= 100; ``` diff --git a/solution/1500-1599/1511.Customer Order Frequency/README_EN.md b/solution/1500-1599/1511.Customer Order Frequency/README_EN.md index 91e87ee6d3d08..84dee7548762b 100644 --- a/solution/1500-1599/1511.Customer Order Frequency/README_EN.md +++ b/solution/1500-1599/1511.Customer Order Frequency/README_EN.md @@ -127,11 +127,11 @@ FROM Orders JOIN Product USING (product_id) JOIN Customers USING (customer_id) -WHERE year(order_date) = 2020 +WHERE YEAR(order_date) = 2020 GROUP BY 1 HAVING - sum(if(month(order_date) = 6, quantity * price, 0)) >= 100 - AND sum(if(month(order_date) = 7, quantity * price, 0)) >= 100; + SUM(IF(MONTH(order_date) = 6, quantity * price, 0)) >= 100 + AND SUM(IF(MONTH(order_date) = 7, quantity * price, 0)) >= 100; ``` diff --git a/solution/1500-1599/1511.Customer Order Frequency/Solution.sql b/solution/1500-1599/1511.Customer Order Frequency/Solution.sql index da8aaa9d75b7e..10cb34f944dea 100644 --- a/solution/1500-1599/1511.Customer Order Frequency/Solution.sql +++ b/solution/1500-1599/1511.Customer Order Frequency/Solution.sql @@ -4,8 +4,8 @@ FROM Orders JOIN Product USING (product_id) JOIN Customers USING (customer_id) -WHERE year(order_date) = 2020 +WHERE YEAR(order_date) = 2020 GROUP BY 1 HAVING - sum(if(month(order_date) = 6, quantity * price, 0)) >= 100 - AND sum(if(month(order_date) = 7, quantity * price, 0)) >= 100; + SUM(IF(MONTH(order_date) = 6, quantity * price, 0)) >= 100 + AND SUM(IF(MONTH(order_date) = 7, quantity * price, 0)) >= 100; diff --git a/solution/1500-1599/1532.The Most Recent Three Orders/README.md b/solution/1500-1599/1532.The Most Recent Three Orders/README.md index bf39a65008816..b717299e360c2 100644 --- a/solution/1500-1599/1532.The Most Recent Three Orders/README.md +++ b/solution/1500-1599/1532.The Most Recent Three Orders/README.md @@ -125,7 +125,7 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md b/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md index 923928d97b36c..79b53383dc6c0 100644 --- a/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md +++ b/solution/1500-1599/1532.The Most Recent Three Orders/README_EN.md @@ -114,7 +114,7 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1532.The Most Recent Three Orders/Solution.sql b/solution/1500-1599/1532.The Most Recent Three Orders/Solution.sql index 901986fd6d6ab..a01ff9aa0553e 100644 --- a/solution/1500-1599/1532.The Most Recent Three Orders/Solution.sql +++ b/solution/1500-1599/1532.The Most Recent Three Orders/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1543.Fix Product Name Format/README.md b/solution/1500-1599/1543.Fix Product Name Format/README.md index 485a360fc4661..fb1964cf5941e 100644 --- a/solution/1500-1599/1543.Fix Product Name Format/README.md +++ b/solution/1500-1599/1543.Fix Product Name Format/README.md @@ -80,11 +80,11 @@ Sales 表: WITH t AS ( SELECT - lower(trim(product_name)) AS product_name, - date_format(sale_date, '%Y-%m') AS sale_date + LOWER(TRIM(product_name)) AS product_name, + DATE_FORMAT(sale_date, '%Y-%m') AS sale_date FROM Sales ) -SELECT product_name, sale_date, count(1) AS total +SELECT product_name, sale_date, COUNT(1) AS total FROM t GROUP BY 1, 2 ORDER BY 1, 2; diff --git a/solution/1500-1599/1543.Fix Product Name Format/README_EN.md b/solution/1500-1599/1543.Fix Product Name Format/README_EN.md index 5c48ff2ebfb9b..1f086a35dbdf9 100644 --- a/solution/1500-1599/1543.Fix Product Name Format/README_EN.md +++ b/solution/1500-1599/1543.Fix Product Name Format/README_EN.md @@ -76,11 +76,11 @@ In March, one matryoshka was sold. WITH t AS ( SELECT - lower(trim(product_name)) AS product_name, - date_format(sale_date, '%Y-%m') AS sale_date + LOWER(TRIM(product_name)) AS product_name, + DATE_FORMAT(sale_date, '%Y-%m') AS sale_date FROM Sales ) -SELECT product_name, sale_date, count(1) AS total +SELECT product_name, sale_date, COUNT(1) AS total FROM t GROUP BY 1, 2 ORDER BY 1, 2; diff --git a/solution/1500-1599/1543.Fix Product Name Format/Solution.sql b/solution/1500-1599/1543.Fix Product Name Format/Solution.sql index 2ba76ce73520a..67721cc9a83bf 100644 --- a/solution/1500-1599/1543.Fix Product Name Format/Solution.sql +++ b/solution/1500-1599/1543.Fix Product Name Format/Solution.sql @@ -2,11 +2,11 @@ WITH t AS ( SELECT - lower(trim(product_name)) AS product_name, - date_format(sale_date, '%Y-%m') AS sale_date + LOWER(TRIM(product_name)) AS product_name, + DATE_FORMAT(sale_date, '%Y-%m') AS sale_date FROM Sales ) -SELECT product_name, sale_date, count(1) AS total +SELECT product_name, sale_date, COUNT(1) AS total FROM t GROUP BY 1, 2 ORDER BY 1, 2; diff --git a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md index 67a33ddb40ac3..61f70c63c2e42 100644 --- a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md +++ b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README.md @@ -133,7 +133,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md index cfce43577bac9..bf954d7731eff 100644 --- a/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md +++ b/solution/1500-1599/1549.The Most Recent Orders for Each Product/README_EN.md @@ -129,7 +129,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1549.The Most Recent Orders for Each Product/Solution.sql b/solution/1500-1599/1549.The Most Recent Orders for Each Product/Solution.sql index 3430592f23866..d09e85eaf98fc 100644 --- a/solution/1500-1599/1549.The Most Recent Orders for Each Product/Solution.sql +++ b/solution/1500-1599/1549.The Most Recent Orders for Each Product/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY product_id ORDER BY order_date DESC ) AS rk diff --git a/solution/1500-1599/1555.Bank Account Summary/README.md b/solution/1500-1599/1555.Bank Account Summary/README.md index b6e9dc8c06b24..b525c75d3dc9e 100644 --- a/solution/1500-1599/1555.Bank Account Summary/README.md +++ b/solution/1500-1599/1555.Bank Account Summary/README.md @@ -107,8 +107,8 @@ Luis 未收到任何转账信息,额度 = 800 SELECT t.user_id, user_name, - sum(t.credit) AS credit, - if(sum(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached + SUM(t.credit) AS credit, + IF(SUM(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached FROM ( SELECT paid_by AS user_id, -amount AS credit FROM Transactions diff --git a/solution/1500-1599/1555.Bank Account Summary/README_EN.md b/solution/1500-1599/1555.Bank Account Summary/README_EN.md index d0d422cc8bcbd..bf83ab6862b14 100644 --- a/solution/1500-1599/1555.Bank Account Summary/README_EN.md +++ b/solution/1500-1599/1555.Bank Account Summary/README_EN.md @@ -103,8 +103,8 @@ Luis did not received any transfer, credit = 800 SELECT t.user_id, user_name, - sum(t.credit) AS credit, - if(sum(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached + SUM(t.credit) AS credit, + IF(SUM(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached FROM ( SELECT paid_by AS user_id, -amount AS credit FROM Transactions diff --git a/solution/1500-1599/1555.Bank Account Summary/Solution.sql b/solution/1500-1599/1555.Bank Account Summary/Solution.sql index ea31a447c3948..933461414f5dc 100644 --- a/solution/1500-1599/1555.Bank Account Summary/Solution.sql +++ b/solution/1500-1599/1555.Bank Account Summary/Solution.sql @@ -2,8 +2,8 @@ SELECT t.user_id, user_name, - sum(t.credit) AS credit, - if(sum(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached + SUM(t.credit) AS credit, + IF(SUM(t.credit) < 0, 'Yes', 'No') AS credit_limit_breached FROM ( SELECT paid_by AS user_id, -amount AS credit FROM Transactions diff --git a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md index de566d54cf2b9..4ed179e799b42 100644 --- a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md +++ b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README.md @@ -77,9 +77,9 @@ Orders ```sql # Write your MySQL query statement below SELECT - date_format(order_date, '%Y-%m') AS month, - count(order_id) AS order_count, - count(DISTINCT customer_id) AS customer_count + DATE_FORMAT(order_date, '%Y-%m') AS month, + COUNT(order_id) AS order_count, + COUNT(DISTINCT customer_id) AS customer_count FROM Orders WHERE invoice > 20 GROUP BY month; diff --git a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md index 1d2c5514cc5eb..c2eac8e472a04 100644 --- a/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md +++ b/solution/1500-1599/1565.Unique Orders and Customers Per Month/README_EN.md @@ -73,9 +73,9 @@ In January 2021 we have two orders from 2 different customers, but only one of t ```sql # Write your MySQL query statement below SELECT - date_format(order_date, '%Y-%m') AS month, - count(order_id) AS order_count, - count(DISTINCT customer_id) AS customer_count + DATE_FORMAT(order_date, '%Y-%m') AS month, + COUNT(order_id) AS order_count, + COUNT(DISTINCT customer_id) AS customer_count FROM Orders WHERE invoice > 20 GROUP BY month; diff --git a/solution/1500-1599/1565.Unique Orders and Customers Per Month/Solution.sql b/solution/1500-1599/1565.Unique Orders and Customers Per Month/Solution.sql index 0f6439efe5325..a33903f9fe18f 100644 --- a/solution/1500-1599/1565.Unique Orders and Customers Per Month/Solution.sql +++ b/solution/1500-1599/1565.Unique Orders and Customers Per Month/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT - date_format(order_date, '%Y-%m') AS month, - count(order_id) AS order_count, - count(DISTINCT customer_id) AS customer_count + DATE_FORMAT(order_date, '%Y-%m') AS month, + COUNT(order_id) AS order_count, + COUNT(DISTINCT customer_id) AS customer_count FROM Orders WHERE invoice > 20 GROUP BY month; diff --git a/solution/1500-1599/1571.Warehouse Manager/README.md b/solution/1500-1599/1571.Warehouse Manager/README.md index d5650e8f82cb8..a575384b4b57c 100644 --- a/solution/1500-1599/1571.Warehouse Manager/README.md +++ b/solution/1500-1599/1571.Warehouse Manager/README.md @@ -108,7 +108,7 @@ Id为4的商品(LC-T-Shirt)的存货量为 4x10x20 = 800 # Write your MySQL query statement below SELECT name AS warehouse_name, - sum(width * length * height * units) AS volume + SUM(width * length * height * units) AS volume FROM Warehouse JOIN Products USING (product_id) diff --git a/solution/1500-1599/1571.Warehouse Manager/README_EN.md b/solution/1500-1599/1571.Warehouse Manager/README_EN.md index 4ceb5429571f2..79b265bc69d90 100644 --- a/solution/1500-1599/1571.Warehouse Manager/README_EN.md +++ b/solution/1500-1599/1571.Warehouse Manager/README_EN.md @@ -104,7 +104,7 @@ We can use an inner join to join the `Warehouse` table and the `Products` table # Write your MySQL query statement below SELECT name AS warehouse_name, - sum(width * length * height * units) AS volume + SUM(width * length * height * units) AS volume FROM Warehouse JOIN Products USING (product_id) diff --git a/solution/1500-1599/1571.Warehouse Manager/Solution.sql b/solution/1500-1599/1571.Warehouse Manager/Solution.sql index 85c6d2d0d22c1..7c416a2b11c73 100644 --- a/solution/1500-1599/1571.Warehouse Manager/Solution.sql +++ b/solution/1500-1599/1571.Warehouse Manager/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT name AS warehouse_name, - sum(width * length * height * units) AS volume + SUM(width * length * height * units) AS volume FROM Warehouse JOIN Products USING (product_id) diff --git a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md index 1c55d92acb8ff..31af2d4a7d1a2 100644 --- a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md +++ b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README.md @@ -112,7 +112,7 @@ GROUP BY customer_id; ```sql # Write your MySQL query statement below -SELECT customer_id, count(1) AS count_no_trans +SELECT customer_id, COUNT(1) AS count_no_trans FROM Visits AS v LEFT JOIN Transactions AS t ON v.visit_id = t.visit_id diff --git a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md index 5f5afab093cc2..b058a302e99b5 100644 --- a/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md +++ b/solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md @@ -108,7 +108,7 @@ GROUP BY customer_id; ```sql # Write your MySQL query statement below -SELECT customer_id, count(1) AS count_no_trans +SELECT customer_id, COUNT(1) AS count_no_trans FROM Visits AS v LEFT JOIN Transactions AS t ON v.visit_id = t.visit_id diff --git a/solution/1500-1599/1587.Bank Account Summary II/README.md b/solution/1500-1599/1587.Bank Account Summary II/README.md index 40a3b0975c7b9..ac5c036c96baf 100644 --- a/solution/1500-1599/1587.Bank Account Summary II/README.md +++ b/solution/1500-1599/1587.Bank Account Summary II/README.md @@ -104,7 +104,7 @@ Charlie 的余额为(6000 + 6000 - 4000) = 8000. # Write your MySQL query statement below SELECT name, - sum(amount) AS balance + SUM(amount) AS balance FROM Users JOIN Transactions USING (account) diff --git a/solution/1500-1599/1587.Bank Account Summary II/README_EN.md b/solution/1500-1599/1587.Bank Account Summary II/README_EN.md index 9522b819d1c93..e02eb57b2d2d1 100644 --- a/solution/1500-1599/1587.Bank Account Summary II/README_EN.md +++ b/solution/1500-1599/1587.Bank Account Summary II/README_EN.md @@ -96,7 +96,7 @@ We can use an equi-join to join the `Users` table and the `Transactions` table o # Write your MySQL query statement below SELECT name, - sum(amount) AS balance + SUM(amount) AS balance FROM Users JOIN Transactions USING (account) diff --git a/solution/1500-1599/1587.Bank Account Summary II/Solution.sql b/solution/1500-1599/1587.Bank Account Summary II/Solution.sql index 0e26be4b79380..e1f668b00f999 100644 --- a/solution/1500-1599/1587.Bank Account Summary II/Solution.sql +++ b/solution/1500-1599/1587.Bank Account Summary II/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT name, - sum(amount) AS balance + SUM(amount) AS balance FROM Users JOIN Transactions USING (account) diff --git a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md index f08d525dfe6ec..5ab822bc945b1 100644 --- a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md +++ b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md @@ -141,9 +141,9 @@ WITH SELECT customer_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY customer_id - ORDER BY count(1) DESC + ORDER BY COUNT(1) DESC ) AS rk FROM Orders GROUP BY 1, 2 diff --git a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md index 21cef7cfefd29..888b1e1efcb60 100644 --- a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md +++ b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md @@ -135,9 +135,9 @@ WITH SELECT customer_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY customer_id - ORDER BY count(1) DESC + ORDER BY COUNT(1) DESC ) AS rk FROM Orders GROUP BY 1, 2 diff --git a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/Solution.sql b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/Solution.sql index 17485249d3404..bc9beeb9fe74e 100644 --- a/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/Solution.sql +++ b/solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/Solution.sql @@ -4,9 +4,9 @@ WITH SELECT customer_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY customer_id - ORDER BY count(1) DESC + ORDER BY COUNT(1) DESC ) AS rk FROM Orders GROUP BY 1, 2 diff --git a/solution/1600-1699/1607.Sellers With No Sales/README.md b/solution/1600-1699/1607.Sellers With No Sales/README.md index e9c1f7e34454f..a5bf63bca1d14 100644 --- a/solution/1600-1699/1607.Sellers With No Sales/README.md +++ b/solution/1600-1699/1607.Sellers With No Sales/README.md @@ -123,7 +123,7 @@ FROM Seller LEFT JOIN Orders USING (seller_id) GROUP BY seller_id -HAVING ifnull(sum(year(sale_date) = 2020), 0) = 0 +HAVING IFNULL(SUM(YEAR(sale_date) = 2020), 0) = 0 ORDER BY 1; ``` diff --git a/solution/1600-1699/1607.Sellers With No Sales/README_EN.md b/solution/1600-1699/1607.Sellers With No Sales/README_EN.md index d1493c9809465..f8074bd3d3101 100644 --- a/solution/1600-1699/1607.Sellers With No Sales/README_EN.md +++ b/solution/1600-1699/1607.Sellers With No Sales/README_EN.md @@ -119,7 +119,7 @@ FROM Seller LEFT JOIN Orders USING (seller_id) GROUP BY seller_id -HAVING ifnull(sum(year(sale_date) = 2020), 0) = 0 +HAVING IFNULL(SUM(YEAR(sale_date) = 2020), 0) = 0 ORDER BY 1; ``` diff --git a/solution/1600-1699/1607.Sellers With No Sales/Solution.sql b/solution/1600-1699/1607.Sellers With No Sales/Solution.sql index f70bb59a4fa22..2607d1440c103 100644 --- a/solution/1600-1699/1607.Sellers With No Sales/Solution.sql +++ b/solution/1600-1699/1607.Sellers With No Sales/Solution.sql @@ -4,5 +4,5 @@ FROM Seller LEFT JOIN Orders USING (seller_id) GROUP BY seller_id -HAVING ifnull(sum(year(sale_date) = 2020), 0) = 0 +HAVING IFNULL(SUM(YEAR(sale_date) = 2020), 0) = 0 ORDER BY 1; diff --git a/solution/1600-1699/1613.Find the Missing IDs/README.md b/solution/1600-1699/1613.Find the Missing IDs/README.md index 61ff0cbd574df..43a49d81c4fe5 100644 --- a/solution/1600-1699/1613.Find the Missing IDs/README.md +++ b/solution/1600-1699/1613.Find the Missing IDs/README.md @@ -83,7 +83,7 @@ FROM t WHERE n < ( SELECT - max(customer_id) + MAX(customer_id) FROM Customers ) AND n NOT IN ( diff --git a/solution/1600-1699/1613.Find the Missing IDs/README_EN.md b/solution/1600-1699/1613.Find the Missing IDs/README_EN.md index c54c96af807fd..d87ac8170a8b7 100644 --- a/solution/1600-1699/1613.Find the Missing IDs/README_EN.md +++ b/solution/1600-1699/1613.Find the Missing IDs/README_EN.md @@ -75,7 +75,7 @@ FROM t WHERE n < ( SELECT - max(customer_id) + MAX(customer_id) FROM Customers ) AND n NOT IN ( diff --git a/solution/1600-1699/1613.Find the Missing IDs/Solution.sql b/solution/1600-1699/1613.Find the Missing IDs/Solution.sql index e5e2c489576f0..841ae732ceaa9 100644 --- a/solution/1600-1699/1613.Find the Missing IDs/Solution.sql +++ b/solution/1600-1699/1613.Find the Missing IDs/Solution.sql @@ -1,25 +1,25 @@ -# Write your MySQL query statement below -WITH RECURSIVE - t AS ( - SELECT - 1 AS n - UNION ALL - SELECT - n + 1 - FROM t - WHERE n < 100 - ) -SELECT - n AS ids -FROM t -WHERE - n < ( - SELECT - max(customer_id) - FROM Customers - ) - AND n NOT IN ( - SELECT - customer_id - FROM Customers - ); +# Write your MySQL query statement below +WITH RECURSIVE + t AS ( + SELECT + 1 AS n + UNION ALL + SELECT + n + 1 + FROM t + WHERE n < 100 + ) +SELECT + n AS ids +FROM t +WHERE + n < ( + SELECT + MAX(customer_id) + FROM Customers + ) + AND n NOT IN( + SELECT + customer_id + FROM Customers + ); diff --git a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md index 40d48414ac12e..fa48218333dda 100644 --- a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md +++ b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README.md @@ -99,7 +99,7 @@ Bob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33% # Write your MySQL query statement below SELECT contest_id, - round(count(1) * 100 / (SELECT count(1) FROM Users), 2) AS percentage + ROUND(COUNT(1) * 100 / (SELECT COUNT(1) FROM Users), 2) AS percentage FROM Register GROUP BY contest_id ORDER BY percentage DESC, contest_id; diff --git a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md index d56347a3d9f88..cdf49d5cf92ca 100644 --- a/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md +++ b/solution/1600-1699/1633.Percentage of Users Attended a Contest/README_EN.md @@ -96,7 +96,7 @@ Bob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33% # Write your MySQL query statement below SELECT contest_id, - round(count(1) * 100 / (SELECT count(1) FROM Users), 2) AS percentage + ROUND(COUNT(1) * 100 / (SELECT COUNT(1) FROM Users), 2) AS percentage FROM Register GROUP BY contest_id ORDER BY percentage DESC, contest_id; diff --git a/solution/1600-1699/1633.Percentage of Users Attended a Contest/Solution.sql b/solution/1600-1699/1633.Percentage of Users Attended a Contest/Solution.sql index 5484cec59d343..d6b507f9093c6 100644 --- a/solution/1600-1699/1633.Percentage of Users Attended a Contest/Solution.sql +++ b/solution/1600-1699/1633.Percentage of Users Attended a Contest/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT contest_id, - round(count(1) * 100 / (SELECT count(1) FROM Users), 2) AS percentage + ROUND(COUNT(1) * 100 / (SELECT COUNT(1) FROM Users), 2) AS percentage FROM Register GROUP BY contest_id ORDER BY percentage DESC, contest_id; diff --git a/solution/1600-1699/1635.Hopper Company Queries I/README.md b/solution/1600-1699/1635.Hopper Company Queries I/README.md index e5722edef48f5..503ba71fbad94 100644 --- a/solution/1600-1699/1635.Hopper Company Queries I/README.md +++ b/solution/1600-1699/1635.Hopper Company Queries I/README.md @@ -173,22 +173,22 @@ WITH WHERE month < 12 ), Ride AS ( - SELECT month(requested_at) AS month, count(1) AS cnt + SELECT MONTH(requested_at) AS month, COUNT(1) AS cnt FROM Rides AS r JOIN AcceptedRides AS a - ON r.ride_id = a.ride_id AND year(requested_at) = 2020 + ON r.ride_id = a.ride_id AND YEAR(requested_at) = 2020 GROUP BY month ) SELECT m.month, - count(driver_id) AS active_drivers, - ifnull(r.cnt, 0) AS accepted_rides + COUNT(driver_id) AS active_drivers, + IFNULL(r.cnt, 0) AS accepted_rides FROM Months AS m LEFT JOIN Drivers AS d - ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020) - OR year(d.join_date) < 2020 + ON (m.month >= MONTH(d.join_date) AND YEAR(d.join_date) = 2020) + OR YEAR(d.join_date) < 2020 LEFT JOIN Ride AS r ON m.month = r.month GROUP BY month; ``` diff --git a/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md b/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md index 29f5390d17a50..a0e460093ecaa 100644 --- a/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md +++ b/solution/1600-1699/1635.Hopper Company Queries I/README_EN.md @@ -169,22 +169,22 @@ WITH WHERE month < 12 ), Ride AS ( - SELECT month(requested_at) AS month, count(1) AS cnt + SELECT MONTH(requested_at) AS month, COUNT(1) AS cnt FROM Rides AS r JOIN AcceptedRides AS a - ON r.ride_id = a.ride_id AND year(requested_at) = 2020 + ON r.ride_id = a.ride_id AND YEAR(requested_at) = 2020 GROUP BY month ) SELECT m.month, - count(driver_id) AS active_drivers, - ifnull(r.cnt, 0) AS accepted_rides + COUNT(driver_id) AS active_drivers, + IFNULL(r.cnt, 0) AS accepted_rides FROM Months AS m LEFT JOIN Drivers AS d - ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020) - OR year(d.join_date) < 2020 + ON (m.month >= MONTH(d.join_date) AND YEAR(d.join_date) = 2020) + OR YEAR(d.join_date) < 2020 LEFT JOIN Ride AS r ON m.month = r.month GROUP BY month; ``` diff --git a/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql b/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql index a69830c61dcd3..73f7b801b62c6 100644 --- a/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql +++ b/solution/1600-1699/1635.Hopper Company Queries I/Solution.sql @@ -1,30 +1,30 @@ -# Write your MySQL query statement below -WITH - recursive Months AS ( - SELECT - 1 AS month - UNION ALL - SELECT - month + 1 - FROM Months - WHERE month < 12 - ), - Ride AS ( - SELECT month(requested_at) AS month, count(1) AS cnt - FROM - Rides AS r - JOIN AcceptedRides AS a - ON r.ride_id = a.ride_id AND year(requested_at) = 2020 - GROUP BY month - ) -SELECT - m.month, - count(driver_id) AS active_drivers, - ifnull(r.cnt, 0) AS accepted_rides -FROM - Months AS m - LEFT JOIN Drivers AS d - ON (m.month >= month(d.join_date) AND year(d.join_date) = 2020) - OR year(d.join_date) < 2020 - LEFT JOIN Ride AS r ON m.month = r.month -GROUP BY month; +# Write your MySQL query statement below +WITH + recursive Months AS ( + SELECT + 1 AS month + UNION ALL + SELECT + month + 1 + FROM Months + WHERE month < 12 + ), + Ride AS ( + SELECT MONTH(requested_at) AS month, COUNT(1) AS cnt + FROM + Rides AS r + JOIN AcceptedRides AS a + ON r.ride_id = a.ride_id AND YEAR(requested_at) = 2020 + GROUP BY month + ) +SELECT + m.month, + COUNT(driver_id) AS active_drivers, + IFNULL(r.cnt, 0) AS accepted_rides +FROM + Months AS m + LEFT JOIN Drivers AS d + ON (m.month >= MONTH(d.join_date) AND YEAR(d.join_date) = 2020) + OR YEAR(d.join_date) < 2020 + LEFT JOIN Ride AS r ON m.month = r.month +GROUP BY month; diff --git a/solution/1600-1699/1645.Hopper Company Queries II/README.md b/solution/1600-1699/1645.Hopper Company Queries II/README.md index e921f9ab75bf1..7a40e4d58925c 100644 --- a/solution/1600-1699/1645.Hopper Company Queries II/README.md +++ b/solution/1600-1699/1645.Hopper Company Queries II/README.md @@ -188,20 +188,20 @@ WITH RECURSIVE FROM Month AS m LEFT JOIN Drivers AS d - ON year(d.join_date) < 2020 - OR (year(d.join_date) = 2020 AND month(d.join_date) <= month) + ON YEAR(d.join_date) < 2020 + OR (YEAR(d.join_date) = 2020 AND MONTH(d.join_date) <= month) ), T AS ( SELECT driver_id, requested_at FROM Rides JOIN AcceptedRides USING (ride_id) - WHERE year(requested_at) = 2020 + WHERE YEAR(requested_at) = 2020 ) SELECT month, - ifnull( - round(count(DISTINCT t.driver_id) * 100 / count(DISTINCT s.driver_id), 2), + IFNULL( + ROUND(COUNT(DISTINCT t.driver_id) * 100 / COUNT(DISTINCT s.driver_id), 2), 0 ) AS working_percentage FROM @@ -209,7 +209,7 @@ FROM LEFT JOIN T AS t ON s.driver_id = t.driver_id AND s.join_date <= t.requested_at - AND s.month = month(t.requested_at) + AND s.month = MONTH(t.requested_at) GROUP BY 1; ``` diff --git a/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md b/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md index 37540f8fcc673..bf968645804ee 100644 --- a/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md +++ b/solution/1600-1699/1645.Hopper Company Queries II/README_EN.md @@ -168,20 +168,20 @@ WITH RECURSIVE FROM Month AS m LEFT JOIN Drivers AS d - ON year(d.join_date) < 2020 - OR (year(d.join_date) = 2020 AND month(d.join_date) <= month) + ON YEAR(d.join_date) < 2020 + OR (YEAR(d.join_date) = 2020 AND MONTH(d.join_date) <= month) ), T AS ( SELECT driver_id, requested_at FROM Rides JOIN AcceptedRides USING (ride_id) - WHERE year(requested_at) = 2020 + WHERE YEAR(requested_at) = 2020 ) SELECT month, - ifnull( - round(count(DISTINCT t.driver_id) * 100 / count(DISTINCT s.driver_id), 2), + IFNULL( + ROUND(COUNT(DISTINCT t.driver_id) * 100 / COUNT(DISTINCT s.driver_id), 2), 0 ) AS working_percentage FROM @@ -189,7 +189,7 @@ FROM LEFT JOIN T AS t ON s.driver_id = t.driver_id AND s.join_date <= t.requested_at - AND s.month = month(t.requested_at) + AND s.month = MONTH(t.requested_at) GROUP BY 1; ``` diff --git a/solution/1600-1699/1645.Hopper Company Queries II/Solution.sql b/solution/1600-1699/1645.Hopper Company Queries II/Solution.sql index 72043a18c6b69..98aa2b1a7f52b 100644 --- a/solution/1600-1699/1645.Hopper Company Queries II/Solution.sql +++ b/solution/1600-1699/1645.Hopper Company Queries II/Solution.sql @@ -12,20 +12,20 @@ WITH RECURSIVE FROM Month AS m LEFT JOIN Drivers AS d - ON year(d.join_date) < 2020 - OR (year(d.join_date) = 2020 AND month(d.join_date) <= month) + ON YEAR(d.join_date) < 2020 + OR (YEAR(d.join_date) = 2020 AND MONTH(d.join_date) <= month) ), T AS ( SELECT driver_id, requested_at FROM Rides JOIN AcceptedRides USING (ride_id) - WHERE year(requested_at) = 2020 + WHERE YEAR(requested_at) = 2020 ) SELECT month, - ifnull( - round(count(DISTINCT t.driver_id) * 100 / count(DISTINCT s.driver_id), 2), + IFNULL( + ROUND(COUNT(DISTINCT t.driver_id) * 100 / COUNT(DISTINCT s.driver_id), 2), 0 ) AS working_percentage FROM @@ -33,5 +33,5 @@ FROM LEFT JOIN T AS t ON s.driver_id = t.driver_id AND s.join_date <= t.requested_at - AND s.month = month(t.requested_at) + AND s.month = MONTH(t.requested_at) GROUP BY 1; diff --git a/solution/1600-1699/1651.Hopper Company Queries III/README.md b/solution/1600-1699/1651.Hopper Company Queries III/README.md index 308eb6fe5cb47..c45f393eb34de 100644 --- a/solution/1600-1699/1651.Hopper Company Queries III/README.md +++ b/solution/1600-1699/1651.Hopper Company Queries III/README.md @@ -164,22 +164,22 @@ WITH RECURSIVE Ride AS ( SELECT month, - sum(ifnull(ride_distance, 0)) AS ride_distance, - sum(ifnull(ride_duration, 0)) AS ride_duration + SUM(IFNULL(ride_distance, 0)) AS ride_distance, + SUM(IFNULL(ride_duration, 0)) AS ride_duration FROM Months AS m - LEFT JOIN Rides AS r ON month = month(requested_at) AND year(requested_at) = 2020 + LEFT JOIN Rides AS r ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020 LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id GROUP BY month ) SELECT month, - round( - avg(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + ROUND( + AVG(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), 2 ) AS average_ride_distance, - round( - avg(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + ROUND( + AVG(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), 2 ) AS average_ride_duration FROM Ride diff --git a/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md b/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md index 69c18df062b2c..2c8e341f657d3 100644 --- a/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md +++ b/solution/1600-1699/1651.Hopper Company Queries III/README_EN.md @@ -162,22 +162,22 @@ WITH RECURSIVE Ride AS ( SELECT month, - sum(ifnull(ride_distance, 0)) AS ride_distance, - sum(ifnull(ride_duration, 0)) AS ride_duration + SUM(IFNULL(ride_distance, 0)) AS ride_distance, + SUM(IFNULL(ride_duration, 0)) AS ride_duration FROM Months AS m - LEFT JOIN Rides AS r ON month = month(requested_at) AND year(requested_at) = 2020 + LEFT JOIN Rides AS r ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020 LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id GROUP BY month ) SELECT month, - round( - avg(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + ROUND( + AVG(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), 2 ) AS average_ride_distance, - round( - avg(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + ROUND( + AVG(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), 2 ) AS average_ride_duration FROM Ride diff --git a/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql b/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql index 0d1f793b9efff..33c43e3793b08 100644 --- a/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql +++ b/solution/1600-1699/1651.Hopper Company Queries III/Solution.sql @@ -1,34 +1,34 @@ -# Write your MySQL query statement below -WITH RECURSIVE - Months AS ( - SELECT 1 AS month - UNION ALL - SELECT month + 1 - FROM Months - WHERE month < 12 - ), - Ride AS ( - SELECT - month, - sum(ifnull(ride_distance, 0)) AS ride_distance, - sum(ifnull(ride_duration, 0)) AS ride_duration - FROM - Months AS m - LEFT JOIN Rides AS r - ON month = month(requested_at) AND year(requested_at) = 2020 - LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id - GROUP BY month - ) -SELECT - month, - round( - avg(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), - 2 - ) AS average_ride_distance, - round( - avg(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), - 2 - ) AS average_ride_duration -FROM Ride -ORDER BY month -LIMIT 10; +# Write your MySQL query statement below +WITH RECURSIVE + Months AS ( + SELECT 1 AS month + UNION ALL + SELECT month + 1 + FROM Months + WHERE month < 12 + ), + Ride AS ( + SELECT + month, + SUM(IFNULL(ride_distance, 0)) AS ride_distance, + SUM(IFNULL(ride_duration, 0)) AS ride_duration + FROM + Months AS m + LEFT JOIN Rides AS r + ON month = MONTH(requested_at) AND YEAR(requested_at) = 2020 + LEFT JOIN AcceptedRides AS a ON r.ride_id = a.ride_id + GROUP BY month + ) +SELECT + month, + ROUND( + AVG(ride_distance) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + 2 + ) AS average_ride_distance, + ROUND( + AVG(ride_duration) OVER (ROWS BETWEEN CURRENT ROW AND 2 FOLLOWING), + 2 + ) AS average_ride_duration +FROM Ride +ORDER BY month +LIMIT 10; diff --git a/solution/1600-1699/1661.Average Time of Process per Machine/README.md b/solution/1600-1699/1661.Average Time of Process per Machine/README.md index 41c7245a6ff15..6a051da4b48f6 100644 --- a/solution/1600-1699/1661.Average Time of Process per Machine/README.md +++ b/solution/1600-1699/1661.Average Time of Process per Machine/README.md @@ -87,8 +87,8 @@ Activity table: # Write your MySQL query statement below SELECT machine_id, - round( - avg( + ROUND( + AVG( CASE WHEN activity_type = 'start' THEN -timestamp ELSE timestamp diff --git a/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md b/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md index 2084f6d10ee63..e4632f5132211 100644 --- a/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md +++ b/solution/1600-1699/1661.Average Time of Process per Machine/README_EN.md @@ -83,8 +83,8 @@ Machine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456 # Write your MySQL query statement below SELECT machine_id, - round( - avg( + ROUND( + AVG( CASE WHEN activity_type = 'start' THEN -timestamp ELSE timestamp diff --git a/solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql b/solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql index 6b727afb35801..0a513f9594e71 100644 --- a/solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql +++ b/solution/1600-1699/1661.Average Time of Process per Machine/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT machine_id, - round( - avg( + ROUND( + AVG( CASE WHEN activity_type = 'start' THEN -timestamp ELSE timestamp diff --git a/solution/1600-1699/1677.Product's Worth Over Invoices/README.md b/solution/1600-1699/1677.Product's Worth Over Invoices/README.md index f3ebedf30b5db..b9e12c55ba299 100644 --- a/solution/1600-1699/1677.Product's Worth Over Invoices/README.md +++ b/solution/1600-1699/1677.Product's Worth Over Invoices/README.md @@ -96,10 +96,10 @@ Result 表: # Write your MySQL query statement below SELECT name, - ifnull(sum(rest), 0) AS rest, - ifnull(sum(paid), 0) AS paid, - ifnull(sum(canceled), 0) AS canceled, - ifnull(sum(refunded), 0) AS refunded + IFNULL(SUM(rest), 0) AS rest, + IFNULL(SUM(paid), 0) AS paid, + IFNULL(SUM(canceled), 0) AS canceled, + IFNULL(SUM(refunded), 0) AS refunded FROM Product LEFT JOIN Invoice USING (product_id) diff --git a/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md b/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md index 0069f5d8821c0..093203afa43bb 100644 --- a/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md +++ b/solution/1600-1699/1677.Product's Worth Over Invoices/README_EN.md @@ -99,10 +99,10 @@ Invoice table: # Write your MySQL query statement below SELECT name, - ifnull(sum(rest), 0) AS rest, - ifnull(sum(paid), 0) AS paid, - ifnull(sum(canceled), 0) AS canceled, - ifnull(sum(refunded), 0) AS refunded + IFNULL(SUM(rest), 0) AS rest, + IFNULL(SUM(paid), 0) AS paid, + IFNULL(SUM(canceled), 0) AS canceled, + IFNULL(SUM(refunded), 0) AS refunded FROM Product LEFT JOIN Invoice USING (product_id) diff --git a/solution/1600-1699/1677.Product's Worth Over Invoices/Solution.sql b/solution/1600-1699/1677.Product's Worth Over Invoices/Solution.sql index 0be3afb1fea22..6db109d8b5326 100644 --- a/solution/1600-1699/1677.Product's Worth Over Invoices/Solution.sql +++ b/solution/1600-1699/1677.Product's Worth Over Invoices/Solution.sql @@ -1,10 +1,10 @@ # Write your MySQL query statement below SELECT name, - ifnull(sum(rest), 0) AS rest, - ifnull(sum(paid), 0) AS paid, - ifnull(sum(canceled), 0) AS canceled, - ifnull(sum(refunded), 0) AS refunded + IFNULL(SUM(rest), 0) AS rest, + IFNULL(SUM(paid), 0) AS paid, + IFNULL(SUM(canceled), 0) AS canceled, + IFNULL(SUM(refunded), 0) AS refunded FROM Product LEFT JOIN Invoice USING (product_id) diff --git a/solution/1600-1699/1693.Daily Leads and Partners/README.md b/solution/1600-1699/1693.Daily Leads and Partners/README.md index 1f59eb7bc7d3f..6c6f8fa0bc8d6 100644 --- a/solution/1600-1699/1693.Daily Leads and Partners/README.md +++ b/solution/1600-1699/1693.Daily Leads and Partners/README.md @@ -80,8 +80,8 @@ DailySales 表: SELECT date_id, make_name, - count(DISTINCT lead_id) AS unique_leads, - count(DISTINCT partner_id) AS unique_partners + COUNT(DISTINCT lead_id) AS unique_leads, + COUNT(DISTINCT partner_id) AS unique_partners FROM DailySales GROUP BY 1, 2; ``` diff --git a/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md b/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md index 9e6831c5b464e..3c12283ae9a53 100644 --- a/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md +++ b/solution/1600-1699/1693.Daily Leads and Partners/README_EN.md @@ -77,8 +77,8 @@ We can use the `GROUP BY` statement to group the data by the `date_id` and `make SELECT date_id, make_name, - count(DISTINCT lead_id) AS unique_leads, - count(DISTINCT partner_id) AS unique_partners + COUNT(DISTINCT lead_id) AS unique_leads, + COUNT(DISTINCT partner_id) AS unique_partners FROM DailySales GROUP BY 1, 2; ``` diff --git a/solution/1600-1699/1693.Daily Leads and Partners/Solution.sql b/solution/1600-1699/1693.Daily Leads and Partners/Solution.sql index 33bb3386293ed..f76ca030c1013 100644 --- a/solution/1600-1699/1693.Daily Leads and Partners/Solution.sql +++ b/solution/1600-1699/1693.Daily Leads and Partners/Solution.sql @@ -2,7 +2,7 @@ SELECT date_id, make_name, - count(DISTINCT lead_id) AS unique_leads, - count(DISTINCT partner_id) AS unique_partners + COUNT(DISTINCT lead_id) AS unique_leads, + COUNT(DISTINCT partner_id) AS unique_partners FROM DailySales GROUP BY 1, 2; diff --git a/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md b/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md index 54cd130adff7b..eee1f6c3e29bd 100644 --- a/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md +++ b/solution/1600-1699/1699.Number of Calls Between Two Persons/README.md @@ -75,10 +75,10 @@ Calls 表: ```sql # Write your MySQL query statement below SELECT - if(from_id < to_id, from_id, to_id) AS person1, - if(from_id < to_id, to_id, from_id) AS person2, - count(1) AS call_count, - sum(duration) AS total_duration + IF(from_id < to_id, from_id, to_id) AS person1, + IF(from_id < to_id, to_id, from_id) AS person2, + COUNT(1) AS call_count, + SUM(duration) AS total_duration FROM Calls GROUP BY 1, 2; ``` @@ -86,10 +86,10 @@ GROUP BY 1, 2; ```sql # Write your MySQL query statement below SELECT - least(from_id, to_id) AS person1, - greatest(from_id, to_id) AS person2, - count(1) AS call_count, - sum(duration) AS total_duration + LEAST(from_id, to_id) AS person1, + GREATEST(from_id, to_id) AS person2, + COUNT(1) AS call_count, + SUM(duration) AS total_duration FROM Calls GROUP BY 1, 2; ``` diff --git a/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md b/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md index c0283f3806a0d..83437f0a5ecd1 100644 --- a/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md +++ b/solution/1600-1699/1699.Number of Calls Between Two Persons/README_EN.md @@ -71,10 +71,10 @@ We can use the `if` function or the `least` and `greatest` functions to convert ```sql # Write your MySQL query statement below SELECT - if(from_id < to_id, from_id, to_id) AS person1, - if(from_id < to_id, to_id, from_id) AS person2, - count(1) AS call_count, - sum(duration) AS total_duration + IF(from_id < to_id, from_id, to_id) AS person1, + IF(from_id < to_id, to_id, from_id) AS person2, + COUNT(1) AS call_count, + SUM(duration) AS total_duration FROM Calls GROUP BY 1, 2; ``` @@ -82,10 +82,10 @@ GROUP BY 1, 2; ```sql # Write your MySQL query statement below SELECT - least(from_id, to_id) AS person1, - greatest(from_id, to_id) AS person2, - count(1) AS call_count, - sum(duration) AS total_duration + LEAST(from_id, to_id) AS person1, + GREATEST(from_id, to_id) AS person2, + COUNT(1) AS call_count, + SUM(duration) AS total_duration FROM Calls GROUP BY 1, 2; ``` diff --git a/solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql b/solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql index 955c80a3acaa7..e70c4702e8660 100644 --- a/solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql +++ b/solution/1600-1699/1699.Number of Calls Between Two Persons/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT - least(from_id, to_id) AS person1, - greatest(from_id, to_id) AS person2, - count(1) AS call_count, - sum(duration) AS total_duration + LEAST(from_id, to_id) AS person1, + GREATEST(from_id, to_id) AS person2, + COUNT(1) AS call_count, + SUM(duration) AS total_duration FROM Calls GROUP BY 1, 2; diff --git a/solution/1700-1799/1709.Biggest Window Between Visits/README.md b/solution/1700-1799/1709.Biggest Window Between Visits/README.md index 9b022751fedf0..c3e0215e84653 100644 --- a/solution/1700-1799/1709.Biggest Window Between Visits/README.md +++ b/solution/1700-1799/1709.Biggest Window Between Visits/README.md @@ -83,8 +83,8 @@ WITH T AS ( SELECT user_id, - datediff( - lead(visit_date, 1, '2021-1-1') OVER ( + DATEDIFF( + LEAD(visit_date, 1, '2021-1-1') OVER ( PARTITION BY user_id ORDER BY visit_date ), @@ -92,7 +92,7 @@ WITH ) AS diff FROM UserVisits ) -SELECT user_id, max(diff) AS biggest_window +SELECT user_id, MAX(diff) AS biggest_window FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md b/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md index 3947ddfc6e0a1..a07213b53c35d 100644 --- a/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md +++ b/solution/1700-1799/1709.Biggest Window Between Visits/README_EN.md @@ -80,8 +80,8 @@ WITH T AS ( SELECT user_id, - datediff( - lead(visit_date, 1, '2021-1-1') OVER ( + DATEDIFF( + LEAD(visit_date, 1, '2021-1-1') OVER ( PARTITION BY user_id ORDER BY visit_date ), @@ -89,7 +89,7 @@ WITH ) AS diff FROM UserVisits ) -SELECT user_id, max(diff) AS biggest_window +SELECT user_id, MAX(diff) AS biggest_window FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/1700-1799/1709.Biggest Window Between Visits/Solution.sql b/solution/1700-1799/1709.Biggest Window Between Visits/Solution.sql index 37d2f68b62be2..b713c803097c7 100644 --- a/solution/1700-1799/1709.Biggest Window Between Visits/Solution.sql +++ b/solution/1700-1799/1709.Biggest Window Between Visits/Solution.sql @@ -3,8 +3,8 @@ WITH T AS ( SELECT user_id, - datediff( - lead(visit_date, 1, '2021-1-1') OVER ( + DATEDIFF( + LEAD(visit_date, 1, '2021-1-1') OVER ( PARTITION BY user_id ORDER BY visit_date ), @@ -12,7 +12,7 @@ WITH ) AS diff FROM UserVisits ) -SELECT user_id, max(diff) AS biggest_window +SELECT user_id, MAX(diff) AS biggest_window FROM T GROUP BY 1 ORDER BY 1; diff --git a/solution/1700-1799/1729.Find Followers Count/README.md b/solution/1700-1799/1729.Find Followers Count/README.md index f6c04e30f0eb2..ab4c7b7c8e86e 100644 --- a/solution/1700-1799/1729.Find Followers Count/README.md +++ b/solution/1700-1799/1729.Find Followers Count/README.md @@ -67,7 +67,7 @@ Followers 表: ```sql SELECT user_id, - count(1) AS followers_count + COUNT(1) AS followers_count FROM Followers GROUP BY user_id ORDER BY user_id; diff --git a/solution/1700-1799/1729.Find Followers Count/README_EN.md b/solution/1700-1799/1729.Find Followers Count/README_EN.md index c2829127386a8..231b35087a97e 100644 --- a/solution/1700-1799/1729.Find Followers Count/README_EN.md +++ b/solution/1700-1799/1729.Find Followers Count/README_EN.md @@ -61,7 +61,7 @@ The followers of 2 are {0,1} ```sql SELECT user_id, - count(1) AS followers_count + COUNT(1) AS followers_count FROM Followers GROUP BY user_id ORDER BY user_id; diff --git a/solution/1700-1799/1729.Find Followers Count/Solution.sql b/solution/1700-1799/1729.Find Followers Count/Solution.sql index 03e64ca0bae43..3c856dfd0d4b9 100644 --- a/solution/1700-1799/1729.Find Followers Count/Solution.sql +++ b/solution/1700-1799/1729.Find Followers Count/Solution.sql @@ -1,6 +1,6 @@ SELECT user_id, - count(1) AS followers_count + COUNT(1) AS followers_count FROM Followers GROUP BY user_id ORDER BY user_id; diff --git a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md index 705760f7635d2..b16f873a22993 100644 --- a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md +++ b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README.md @@ -64,8 +64,8 @@ Hercy 有两个需要向他汇报的员工, 他们是 Alice and Bob. 他们的 SELECT e2.employee_id, e2.name, - count(1) AS reports_count, - round(avg(e1.age)) AS average_age + COUNT(1) AS reports_count, + ROUND(AVG(e1.age)) AS average_age FROM Employees AS e1 JOIN Employees AS e2 ON e1.reports_to = e2.employee_id diff --git a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md index a74bda6090f22..49d5c6cfac2ee 100644 --- a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md +++ b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/README_EN.md @@ -63,8 +63,8 @@ Employees table: SELECT e2.employee_id, e2.name, - count(1) AS reports_count, - round(avg(e1.age)) AS average_age + COUNT(1) AS reports_count, + ROUND(AVG(e1.age)) AS average_age FROM Employees AS e1 JOIN Employees AS e2 ON e1.reports_to = e2.employee_id diff --git a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/Solution.sql b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/Solution.sql index 8af42816a8a5a..e16b417b8c2ee 100644 --- a/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/Solution.sql +++ b/solution/1700-1799/1731.The Number of Employees Which Report to Each Employee/Solution.sql @@ -2,8 +2,8 @@ SELECT e2.employee_id, e2.name, - count(1) AS reports_count, - round(avg(e1.age)) AS average_age + COUNT(1) AS reports_count, + ROUND(AVG(e1.age)) AS average_age FROM Employees AS e1 JOIN Employees AS e2 ON e1.reports_to = e2.employee_id diff --git a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md index 4e3cd04fb8aa5..8534cc5a1cb47 100644 --- a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md +++ b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README.md @@ -75,7 +75,7 @@ Employees table: ```sql # Write your MySQL query statement below -SELECT event_day AS day, emp_id, sum(out_time - in_time) AS total_time +SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time FROM Employees GROUP BY 1, 2; ``` diff --git a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md index 848fa18a71396..19060e3ad57b4 100644 --- a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md +++ b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/README_EN.md @@ -71,7 +71,7 @@ We can first group by `emp_id` and `event_day`, and then calculate the total tim ```sql # Write your MySQL query statement below -SELECT event_day AS day, emp_id, sum(out_time - in_time) AS total_time +SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time FROM Employees GROUP BY 1, 2; ``` diff --git a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/Solution.sql b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/Solution.sql index 81a2b3361c5cc..9043238a86e6b 100644 --- a/solution/1700-1799/1741.Find Total Time Spent by Each Employee/Solution.sql +++ b/solution/1700-1799/1741.Find Total Time Spent by Each Employee/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below -SELECT event_day AS day, emp_id, sum(out_time - in_time) AS total_time +SELECT event_day AS day, emp_id, SUM(out_time - in_time) AS total_time FROM Employees GROUP BY 1, 2; diff --git a/solution/1700-1799/1777.Product's Price for Each Store/README.md b/solution/1700-1799/1777.Product's Price for Each Store/README.md index a8659620bc037..8c7760293afd9 100644 --- a/solution/1700-1799/1777.Product's Price for Each Store/README.md +++ b/solution/1700-1799/1777.Product's Price for Each Store/README.md @@ -68,9 +68,9 @@ Products 表: # Write your MySQL query statement below SELECT product_id, - sum(if(store = 'store1', price, NULL)) AS store1, - sum(if(store = 'store2', price, NULL)) AS store2, - sum(if(store = 'store3', price, NULL)) AS store3 + SUM(IF(store = 'store1', price, NULL)) AS store1, + SUM(IF(store = 'store2', price, NULL)) AS store2, + SUM(IF(store = 'store3', price, NULL)) AS store3 FROM Products GROUP BY 1; ``` diff --git a/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md b/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md index 96bee97513b35..4c38925df5131 100644 --- a/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md +++ b/solution/1700-1799/1777.Product's Price for Each Store/README_EN.md @@ -64,9 +64,9 @@ Product 1 price's are 70 for store1, 80 for store3 and, it's not sold in # Write your MySQL query statement below SELECT product_id, - sum(if(store = 'store1', price, NULL)) AS store1, - sum(if(store = 'store2', price, NULL)) AS store2, - sum(if(store = 'store3', price, NULL)) AS store3 + SUM(IF(store = 'store1', price, NULL)) AS store1, + SUM(IF(store = 'store2', price, NULL)) AS store2, + SUM(IF(store = 'store3', price, NULL)) AS store3 FROM Products GROUP BY 1; ``` diff --git a/solution/1700-1799/1777.Product's Price for Each Store/Solution.sql b/solution/1700-1799/1777.Product's Price for Each Store/Solution.sql index 853d6c6dd4ccc..5b37c4994bae3 100644 --- a/solution/1700-1799/1777.Product's Price for Each Store/Solution.sql +++ b/solution/1700-1799/1777.Product's Price for Each Store/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT product_id, - sum(if(store = 'store1', price, NULL)) AS store1, - sum(if(store = 'store2', price, NULL)) AS store2, - sum(if(store = 'store3', price, NULL)) AS store3 + SUM(IF(store = 'store1', price, NULL)) AS store1, + SUM(IF(store = 'store2', price, NULL)) AS store2, + SUM(IF(store = 'store3', price, NULL)) AS store3 FROM Products GROUP BY 1; diff --git a/solution/1700-1799/1783.Grand Slam Titles/README.md b/solution/1700-1799/1783.Grand Slam Titles/README.md index 245a3493e642f..575d048178bc6 100644 --- a/solution/1700-1799/1783.Grand Slam Titles/README.md +++ b/solution/1700-1799/1783.Grand Slam Titles/README.md @@ -107,7 +107,7 @@ WITH SELECT Au_open AS player_id FROM Championships ) -SELECT player_id, player_name, count(1) AS grand_slams_count +SELECT player_id, player_name, COUNT(1) AS grand_slams_count FROM T JOIN Players USING (player_id) @@ -119,7 +119,7 @@ GROUP BY 1; SELECT player_id, player_name, - sum( + SUM( ( CASE WHEN Wimbledon = player_id THEN 1 diff --git a/solution/1700-1799/1783.Grand Slam Titles/README_EN.md b/solution/1700-1799/1783.Grand Slam Titles/README_EN.md index d9003389a512a..51df23db8cef9 100644 --- a/solution/1700-1799/1783.Grand Slam Titles/README_EN.md +++ b/solution/1700-1799/1783.Grand Slam Titles/README_EN.md @@ -103,7 +103,7 @@ WITH SELECT Au_open AS player_id FROM Championships ) -SELECT player_id, player_name, count(1) AS grand_slams_count +SELECT player_id, player_name, COUNT(1) AS grand_slams_count FROM T JOIN Players USING (player_id) @@ -115,7 +115,7 @@ GROUP BY 1; SELECT player_id, player_name, - sum( + SUM( ( CASE WHEN Wimbledon = player_id THEN 1 diff --git a/solution/1700-1799/1783.Grand Slam Titles/Solution.sql b/solution/1700-1799/1783.Grand Slam Titles/Solution.sql index d8fd5397005ca..2c9c8957a02c6 100644 --- a/solution/1700-1799/1783.Grand Slam Titles/Solution.sql +++ b/solution/1700-1799/1783.Grand Slam Titles/Solution.sql @@ -13,7 +13,7 @@ WITH SELECT Au_open AS player_id FROM Championships ) -SELECT player_id, player_name, count(1) AS grand_slams_count +SELECT player_id, player_name, COUNT(1) AS grand_slams_count FROM T JOIN Players USING (player_id) diff --git a/solution/1700-1799/1789.Primary Department for Each Employee/README.md b/solution/1700-1799/1789.Primary Department for Each Employee/README.md index 3b9cddefd0cce..ecb127f906382 100644 --- a/solution/1700-1799/1789.Primary Department for Each Employee/README.md +++ b/solution/1700-1799/1789.Primary Department for Each Employee/README.md @@ -86,7 +86,7 @@ UNION SELECT employee_id, department_id FROM Employee GROUP BY employee_id -HAVING count(1) = 1; +HAVING COUNT(1) = 1; ``` diff --git a/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md b/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md index 29551e6ef4132..e91a3dbeeff86 100644 --- a/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md +++ b/solution/1700-1799/1789.Primary Department for Each Employee/README_EN.md @@ -78,7 +78,7 @@ UNION SELECT employee_id, department_id FROM Employee GROUP BY employee_id -HAVING count(1) = 1; +HAVING COUNT(1) = 1; ``` diff --git a/solution/1700-1799/1789.Primary Department for Each Employee/Solution.sql b/solution/1700-1799/1789.Primary Department for Each Employee/Solution.sql index 53c81d8c746fb..ca2bcbb1eda48 100644 --- a/solution/1700-1799/1789.Primary Department for Each Employee/Solution.sql +++ b/solution/1700-1799/1789.Primary Department for Each Employee/Solution.sql @@ -6,4 +6,4 @@ UNION SELECT employee_id, department_id FROM Employee GROUP BY employee_id -HAVING count(1) = 1; +HAVING COUNT(1) = 1; diff --git a/solution/1800-1899/1811.Find Interview Candidates/README.md b/solution/1800-1899/1811.Find Interview Candidates/README.md index d62940d887a23..7b0b0e663b50d 100644 --- a/solution/1800-1899/1811.Find Interview Candidates/README.md +++ b/solution/1800-1899/1811.Find Interview Candidates/README.md @@ -130,7 +130,7 @@ WITH SELECT user_id, ( - contest_id - row_number() OVER ( + contest_id - ROW_NUMBER() OVER ( PARTITION BY user_id ORDER BY contest_id ) @@ -142,12 +142,12 @@ WITH FROM S WHERE type = 1 GROUP BY user_id - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 UNION SELECT DISTINCT user_id FROM T GROUP BY user_id, diff - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT name, mail FROM diff --git a/solution/1800-1899/1811.Find Interview Candidates/README_EN.md b/solution/1800-1899/1811.Find Interview Candidates/README_EN.md index 1a8a27dd9f627..801dac38d8f8d 100644 --- a/solution/1800-1899/1811.Find Interview Candidates/README_EN.md +++ b/solution/1800-1899/1811.Find Interview Candidates/README_EN.md @@ -123,7 +123,7 @@ WITH SELECT user_id, ( - contest_id - row_number() OVER ( + contest_id - ROW_NUMBER() OVER ( PARTITION BY user_id ORDER BY contest_id ) @@ -135,12 +135,12 @@ WITH FROM S WHERE type = 1 GROUP BY user_id - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 UNION SELECT DISTINCT user_id FROM T GROUP BY user_id, diff - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT name, mail FROM diff --git a/solution/1800-1899/1811.Find Interview Candidates/Solution.sql b/solution/1800-1899/1811.Find Interview Candidates/Solution.sql index 3b11732c38601..4a4d9b0ea593c 100644 --- a/solution/1800-1899/1811.Find Interview Candidates/Solution.sql +++ b/solution/1800-1899/1811.Find Interview Candidates/Solution.sql @@ -14,7 +14,7 @@ WITH SELECT user_id, ( - contest_id - row_number() OVER ( + contest_id - ROW_NUMBER() OVER ( PARTITION BY user_id ORDER BY contest_id ) @@ -26,12 +26,12 @@ WITH FROM S WHERE type = 1 GROUP BY user_id - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 UNION SELECT DISTINCT user_id FROM T GROUP BY user_id, diff - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT name, mail FROM diff --git a/solution/1800-1899/1831.Maximum Transaction Each Day/README.md b/solution/1800-1899/1831.Maximum Transaction Each Day/README.md index 6833e47a668fc..881c154ba556b 100644 --- a/solution/1800-1899/1831.Maximum Transaction Each Day/README.md +++ b/solution/1800-1899/1831.Maximum Transaction Each Day/README.md @@ -83,8 +83,8 @@ WITH T AS ( SELECT transaction_id, - rank() OVER ( - PARTITION BY day(day) + RANK() OVER ( + PARTITION BY DAY(day) ORDER BY amount DESC ) AS rk FROM Transactions diff --git a/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md b/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md index 7fd018e8e2643..a58e8d3f4468f 100644 --- a/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md +++ b/solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md @@ -76,8 +76,8 @@ WITH T AS ( SELECT transaction_id, - rank() OVER ( - PARTITION BY day(day) + RANK() OVER ( + PARTITION BY DAY(day) ORDER BY amount DESC ) AS rk FROM Transactions diff --git a/solution/1800-1899/1831.Maximum Transaction Each Day/Solution.sql b/solution/1800-1899/1831.Maximum Transaction Each Day/Solution.sql index 974b30778a3d3..22b31c093d602 100644 --- a/solution/1800-1899/1831.Maximum Transaction Each Day/Solution.sql +++ b/solution/1800-1899/1831.Maximum Transaction Each Day/Solution.sql @@ -3,8 +3,8 @@ WITH T AS ( SELECT transaction_id, - rank() OVER ( - PARTITION BY day(day) + RANK() OVER ( + PARTITION BY DAY(day) ORDER BY amount DESC ) AS rk FROM Transactions diff --git a/solution/1800-1899/1841.League Statistics/README.md b/solution/1800-1899/1841.League Statistics/README.md index 415c1f16576f2..d5028d59875e6 100644 --- a/solution/1800-1899/1841.League Statistics/README.md +++ b/solution/1800-1899/1841.League Statistics/README.md @@ -133,11 +133,11 @@ WITH ) SELECT team_name, - count(1) AS matches_played, - sum(score) AS points, - sum(goals) AS goal_for, - sum(away_goals) AS goal_against, - (sum(goals) - sum(away_goals)) AS goal_diff + COUNT(1) AS matches_played, + SUM(score) AS points, + SUM(goals) AS goal_for, + SUM(away_goals) AS goal_against, + (SUM(goals) - SUM(away_goals)) AS goal_diff FROM Scores AS s JOIN Teams AS t ON s.team_id = t.team_id diff --git a/solution/1800-1899/1841.League Statistics/README_EN.md b/solution/1800-1899/1841.League Statistics/README_EN.md index 8b62febbd7c63..1a8d201f8ddea 100644 --- a/solution/1800-1899/1841.League Statistics/README_EN.md +++ b/solution/1800-1899/1841.League Statistics/README_EN.md @@ -127,11 +127,11 @@ WITH ) SELECT team_name, - count(1) AS matches_played, - sum(score) AS points, - sum(goals) AS goal_for, - sum(away_goals) AS goal_against, - (sum(goals) - sum(away_goals)) AS goal_diff + COUNT(1) AS matches_played, + SUM(score) AS points, + SUM(goals) AS goal_for, + SUM(away_goals) AS goal_against, + (SUM(goals) - SUM(away_goals)) AS goal_diff FROM Scores AS s JOIN Teams AS t ON s.team_id = t.team_id diff --git a/solution/1800-1899/1841.League Statistics/Solution.sql b/solution/1800-1899/1841.League Statistics/Solution.sql index 54870eb43d859..3b3073599f284 100644 --- a/solution/1800-1899/1841.League Statistics/Solution.sql +++ b/solution/1800-1899/1841.League Statistics/Solution.sql @@ -25,11 +25,11 @@ WITH ) SELECT team_name, - count(1) AS matches_played, - sum(score) AS points, - sum(goals) AS goal_for, - sum(away_goals) AS goal_against, - (sum(goals) - sum(away_goals)) AS goal_diff + COUNT(1) AS matches_played, + SUM(score) AS points, + SUM(goals) AS goal_for, + SUM(away_goals) AS goal_against, + (SUM(goals) - SUM(away_goals)) AS goal_diff FROM Scores AS s JOIN Teams AS t ON s.team_id = t.team_id diff --git a/solution/1800-1899/1843.Suspicious Bank Accounts/README.md b/solution/1800-1899/1843.Suspicious Bank Accounts/README.md index 304f98e408082..286f59ec88142 100644 --- a/solution/1800-1899/1843.Suspicious Bank Accounts/README.md +++ b/solution/1800-1899/1843.Suspicious Bank Accounts/README.md @@ -111,10 +111,10 @@ WITH S AS ( SELECT DISTINCT t.account_id, - date_format(day, '%Y-%m-01') AS day, + DATE_FORMAT(day, '%Y-%m-01') AS day, transaction_id AS tx, - sum(amount) OVER ( - PARTITION BY account_id, date_format(day, '%Y-%m-01') + SUM(amount) OVER ( + PARTITION BY account_id, DATE_FORMAT(day, '%Y-%m-01') ) > max_income AS marked FROM Transactions AS t @@ -124,7 +124,7 @@ WITH SELECT DISTINCT s1.account_id FROM S AS s1 - LEFT JOIN S AS s2 ON s1.account_id = s2.account_id AND timestampdiff(Month, s1.day, s2.day) = 1 + LEFT JOIN S AS s2 ON s1.account_id = s2.account_id AND TIMESTAMPDIFF(Month, s1.day, s2.day) = 1 WHERE s1.marked = 1 AND s2.marked = 1 ORDER BY s1.tx; ``` @@ -135,18 +135,18 @@ WITH S AS ( SELECT account_id, - date_format(day, '%Y%m') AS yearmonth, + DATE_FORMAT(day, '%Y%m') AS yearmonth, transaction_id AS tx FROM Transactions JOIN Accounts USING (account_id) WHERE type = 'Creditor' GROUP BY account_id, yearmonth - HAVING sum(amount) > avg(max_income) + HAVING SUM(amount) > AVG(max_income) ) SELECT DISTINCT account_id FROM S -WHERE (account_id, period_add(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) +WHERE (account_id, PERIOD_ADD(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) ORDER BY tx; ``` diff --git a/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md b/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md index 84635937bf052..7eed07ed210ac 100644 --- a/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md +++ b/solution/1800-1899/1843.Suspicious Bank Accounts/README_EN.md @@ -105,10 +105,10 @@ WITH S AS ( SELECT DISTINCT t.account_id, - date_format(day, '%Y-%m-01') AS day, + DATE_FORMAT(day, '%Y-%m-01') AS day, transaction_id AS tx, - sum(amount) OVER ( - PARTITION BY account_id, date_format(day, '%Y-%m-01') + SUM(amount) OVER ( + PARTITION BY account_id, DATE_FORMAT(day, '%Y-%m-01') ) > max_income AS marked FROM Transactions AS t @@ -118,7 +118,7 @@ WITH SELECT DISTINCT s1.account_id FROM S AS s1 - LEFT JOIN S AS s2 ON s1.account_id = s2.account_id AND timestampdiff(Month, s1.day, s2.day) = 1 + LEFT JOIN S AS s2 ON s1.account_id = s2.account_id AND TIMESTAMPDIFF(Month, s1.day, s2.day) = 1 WHERE s1.marked = 1 AND s2.marked = 1 ORDER BY s1.tx; ``` @@ -129,18 +129,18 @@ WITH S AS ( SELECT account_id, - date_format(day, '%Y%m') AS yearmonth, + DATE_FORMAT(day, '%Y%m') AS yearmonth, transaction_id AS tx FROM Transactions JOIN Accounts USING (account_id) WHERE type = 'Creditor' GROUP BY account_id, yearmonth - HAVING sum(amount) > avg(max_income) + HAVING SUM(amount) > AVG(max_income) ) SELECT DISTINCT account_id FROM S -WHERE (account_id, period_add(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) +WHERE (account_id, PERIOD_ADD(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) ORDER BY tx; ``` diff --git a/solution/1800-1899/1843.Suspicious Bank Accounts/Solution.sql b/solution/1800-1899/1843.Suspicious Bank Accounts/Solution.sql index dc4a8987503c2..263f1256b7fee 100644 --- a/solution/1800-1899/1843.Suspicious Bank Accounts/Solution.sql +++ b/solution/1800-1899/1843.Suspicious Bank Accounts/Solution.sql @@ -3,16 +3,16 @@ WITH S AS ( SELECT account_id, - date_format(day, '%Y%m') AS yearmonth, + DATE_FORMAT(day, '%Y%m') AS yearmonth, transaction_id AS tx FROM Transactions JOIN Accounts USING (account_id) WHERE type = 'Creditor' GROUP BY account_id, yearmonth - HAVING sum(amount) > avg(max_income) + HAVING SUM(amount) > AVG(max_income) ) SELECT DISTINCT account_id FROM S -WHERE (account_id, period_add(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) +WHERE (account_id, PERIOD_ADD(yearmonth, 1)) IN (SELECT account_id, yearmonth FROM S) ORDER BY tx; diff --git a/solution/1800-1899/1853.Convert Date Format/README.md b/solution/1800-1899/1853.Convert Date Format/README.md index a20f9d7ba661b..8cf26902f571b 100644 --- a/solution/1800-1899/1853.Convert Date Format/README.md +++ b/solution/1800-1899/1853.Convert Date Format/README.md @@ -61,7 +61,7 @@ Days table: ```sql # Write your MySQL query statement below -SELECT date_format(day, '%W, %M %e, %Y') AS day FROM Days; +SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day FROM Days; ``` diff --git a/solution/1800-1899/1853.Convert Date Format/README_EN.md b/solution/1800-1899/1853.Convert Date Format/README_EN.md index 5aa240e168332..837a78d384dfd 100644 --- a/solution/1800-1899/1853.Convert Date Format/README_EN.md +++ b/solution/1800-1899/1853.Convert Date Format/README_EN.md @@ -55,7 +55,7 @@ Days table: ```sql # Write your MySQL query statement below -SELECT date_format(day, '%W, %M %e, %Y') AS day FROM Days; +SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day FROM Days; ``` diff --git a/solution/1800-1899/1853.Convert Date Format/Solution.sql b/solution/1800-1899/1853.Convert Date Format/Solution.sql index 43279e7269033..5ff8efd978cba 100644 --- a/solution/1800-1899/1853.Convert Date Format/Solution.sql +++ b/solution/1800-1899/1853.Convert Date Format/Solution.sql @@ -1,2 +1,2 @@ # Write your MySQL query statement below -SELECT date_format(day, '%W, %M %e, %Y') AS day FROM Days; +SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day FROM Days; diff --git a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md index 4deb15604c956..93f5d1f6f8db0 100644 --- a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md +++ b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README.md @@ -99,14 +99,14 @@ WITH t AS ( SELECT order_id, - max(quantity) AS max_quantity, - sum(quantity) / count(1) AS avg_quantity + MAX(quantity) AS max_quantity, + SUM(quantity) / COUNT(1) AS avg_quantity FROM OrdersDetails GROUP BY order_id ) SELECT order_id FROM t -WHERE max_quantity > (SELECT max(avg_quantity) FROM t); +WHERE max_quantity > (SELECT MAX(avg_quantity) FROM t); ``` diff --git a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md index ccf5f00b3c503..9f70ec7d41d4a 100644 --- a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md +++ b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/README_EN.md @@ -92,14 +92,14 @@ WITH t AS ( SELECT order_id, - max(quantity) AS max_quantity, - sum(quantity) / count(1) AS avg_quantity + MAX(quantity) AS max_quantity, + SUM(quantity) / COUNT(1) AS avg_quantity FROM OrdersDetails GROUP BY order_id ) SELECT order_id FROM t -WHERE max_quantity > (SELECT max(avg_quantity) FROM t); +WHERE max_quantity > (SELECT MAX(avg_quantity) FROM t); ``` diff --git a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/Solution.sql b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/Solution.sql index 994bbbb6b4f42..ef92d8721a735 100644 --- a/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/Solution.sql +++ b/solution/1800-1899/1867.Orders With Maximum Quantity Above Average/Solution.sql @@ -3,11 +3,11 @@ WITH t AS ( SELECT order_id, - max(quantity) AS max_quantity, - sum(quantity) / count(1) AS avg_quantity + MAX(quantity) AS max_quantity, + SUM(quantity) / COUNT(1) AS avg_quantity FROM OrdersDetails GROUP BY order_id ) SELECT order_id FROM t -WHERE max_quantity > (SELECT max(avg_quantity) FROM t); +WHERE max_quantity > (SELECT MAX(avg_quantity) FROM t); diff --git a/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql b/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql index beb80a26a2ef5..202a1e0c428f1 100644 --- a/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql +++ b/solution/1800-1899/1873.Calculate Special Bonus/Solution.sql @@ -1,12 +1,12 @@ -# Write your MySQL query statement below -SELECT - employee_id, - IF( - employee_id % 2 = 0 - OR LEFT(name, 1) = 'M', - 0, - salary - ) AS bonus -FROM - employees -ORDER BY 1; +# Write your MySQL query statement below +SELECT + employee_id, + IF( + employee_id % 2 = 0 + OR LEFT(name, 1) = 'M', + 0, + salary + ) AS bonus +FROM + employees +ORDER BY 1; diff --git a/solution/1800-1899/1875.Group Employees of the Same Salary/README.md b/solution/1800-1899/1875.Group Employees of the Same Salary/README.md index cc2acf7f3984c..607b9014b1daf 100644 --- a/solution/1800-1899/1875.Group Employees of the Same Salary/README.md +++ b/solution/1800-1899/1875.Group Employees of the Same Salary/README.md @@ -89,10 +89,10 @@ WITH SELECT salary FROM Employees GROUP BY salary - HAVING count(1) > 1 + HAVING COUNT(1) > 1 ), T AS ( - SELECT salary, row_number() OVER (ORDER BY salary) AS team_id + SELECT salary, ROW_NUMBER() OVER (ORDER BY salary) AS team_id FROM S ) SELECT e.*, t.team_id diff --git a/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md b/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md index e3db533447343..4ed290f23d2eb 100644 --- a/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md +++ b/solution/1800-1899/1875.Group Employees of the Same Salary/README_EN.md @@ -83,10 +83,10 @@ WITH SELECT salary FROM Employees GROUP BY salary - HAVING count(1) > 1 + HAVING COUNT(1) > 1 ), T AS ( - SELECT salary, row_number() OVER (ORDER BY salary) AS team_id + SELECT salary, ROW_NUMBER() OVER (ORDER BY salary) AS team_id FROM S ) SELECT e.*, t.team_id diff --git a/solution/1800-1899/1875.Group Employees of the Same Salary/Solution.sql b/solution/1800-1899/1875.Group Employees of the Same Salary/Solution.sql index bd203d465d2a0..d666d1aa7cd15 100644 --- a/solution/1800-1899/1875.Group Employees of the Same Salary/Solution.sql +++ b/solution/1800-1899/1875.Group Employees of the Same Salary/Solution.sql @@ -4,10 +4,10 @@ WITH SELECT salary FROM Employees GROUP BY salary - HAVING count(1) > 1 + HAVING COUNT(1) > 1 ), T AS ( - SELECT salary, row_number() OVER (ORDER BY salary) AS team_id + SELECT salary, ROW_NUMBER() OVER (ORDER BY salary) AS team_id FROM S ) SELECT e.*, t.team_id diff --git a/solution/1800-1899/1890.The Latest Login in 2020/README.md b/solution/1800-1899/1890.The Latest Login in 2020/README.md index b1013a731dff1..dcf457fa31b8e 100644 --- a/solution/1800-1899/1890.The Latest Login in 2020/README.md +++ b/solution/1800-1899/1890.The Latest Login in 2020/README.md @@ -77,9 +77,9 @@ Logins 表: ```sql # Write your MySQL query statement below -SELECT user_id, max(time_stamp) AS last_stamp +SELECT user_id, MAX(time_stamp) AS last_stamp FROM Logins -WHERE year(time_stamp) = 2020 +WHERE YEAR(time_stamp) = 2020 GROUP BY 1; ``` diff --git a/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md b/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md index c1bdf282b6aa9..8cefd0dc07e71 100644 --- a/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md +++ b/solution/1800-1899/1890.The Latest Login in 2020/README_EN.md @@ -71,9 +71,9 @@ We can first filter out the login records in 2020, and then group by `user_id`, ```sql # Write your MySQL query statement below -SELECT user_id, max(time_stamp) AS last_stamp +SELECT user_id, MAX(time_stamp) AS last_stamp FROM Logins -WHERE year(time_stamp) = 2020 +WHERE YEAR(time_stamp) = 2020 GROUP BY 1; ``` diff --git a/solution/1800-1899/1890.The Latest Login in 2020/Solution.sql b/solution/1800-1899/1890.The Latest Login in 2020/Solution.sql index fb82458255255..9a4d0cc32f2d6 100644 --- a/solution/1800-1899/1890.The Latest Login in 2020/Solution.sql +++ b/solution/1800-1899/1890.The Latest Login in 2020/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT user_id, max(time_stamp) AS last_stamp +SELECT user_id, MAX(time_stamp) AS last_stamp FROM Logins -WHERE year(time_stamp) = 2020 +WHERE YEAR(time_stamp) = 2020 GROUP BY 1; diff --git a/solution/1800-1899/1892.Page Recommendations II/README.md b/solution/1800-1899/1892.Page Recommendations II/README.md index b75e22fb42b62..1fde96530f1a4 100644 --- a/solution/1800-1899/1892.Page Recommendations II/README.md +++ b/solution/1800-1899/1892.Page Recommendations II/README.md @@ -133,7 +133,7 @@ WITH UNION SELECT user2_id, user1_id FROM Friendship ) -SELECT user1_id AS user_id, page_id, count(1) AS friends_likes +SELECT user1_id AS user_id, page_id, COUNT(1) AS friends_likes FROM S AS s LEFT JOIN Likes AS l ON s.user2_id = l.user_id diff --git a/solution/1800-1899/1892.Page Recommendations II/README_EN.md b/solution/1800-1899/1892.Page Recommendations II/README_EN.md index 187d09b1368bd..588dcaf819792 100644 --- a/solution/1800-1899/1892.Page Recommendations II/README_EN.md +++ b/solution/1800-1899/1892.Page Recommendations II/README_EN.md @@ -127,7 +127,7 @@ WITH UNION SELECT user2_id, user1_id FROM Friendship ) -SELECT user1_id AS user_id, page_id, count(1) AS friends_likes +SELECT user1_id AS user_id, page_id, COUNT(1) AS friends_likes FROM S AS s LEFT JOIN Likes AS l ON s.user2_id = l.user_id diff --git a/solution/1800-1899/1892.Page Recommendations II/Solution.sql b/solution/1800-1899/1892.Page Recommendations II/Solution.sql index ad03d5e3732e8..19f71217c0d38 100644 --- a/solution/1800-1899/1892.Page Recommendations II/Solution.sql +++ b/solution/1800-1899/1892.Page Recommendations II/Solution.sql @@ -5,7 +5,7 @@ WITH UNION SELECT user2_id, user1_id FROM Friendship ) -SELECT user1_id AS user_id, page_id, count(1) AS friends_likes +SELECT user1_id AS user_id, page_id, COUNT(1) AS friends_likes FROM S AS s LEFT JOIN Likes AS l ON s.user2_id = l.user_id diff --git a/solution/1900-1999/1907.Count Salary Categories/README.md b/solution/1900-1999/1907.Count Salary Categories/README.md index e37c0b8c1b8b1..4b2fa10c5a423 100644 --- a/solution/1900-1999/1907.Count Salary Categories/README.md +++ b/solution/1900-1999/1907.Count Salary Categories/README.md @@ -92,11 +92,11 @@ WITH WHEN income > 50000 THEN 'High Salary' ELSE 'Average Salary' END AS category, - count(1) AS accounts_count + COUNT(1) AS accounts_count FROM Accounts GROUP BY category ) -SELECT s.category, ifnull(accounts_count, 0) AS accounts_count +SELECT s.category, IFNULL(accounts_count, 0) AS accounts_count FROM S AS s LEFT JOIN T AS t ON s.category = t.category; diff --git a/solution/1900-1999/1907.Count Salary Categories/README_EN.md b/solution/1900-1999/1907.Count Salary Categories/README_EN.md index 580ade269b1fe..9d193d73efb72 100644 --- a/solution/1900-1999/1907.Count Salary Categories/README_EN.md +++ b/solution/1900-1999/1907.Count Salary Categories/README_EN.md @@ -84,11 +84,11 @@ WITH WHEN income > 50000 THEN 'High Salary' ELSE 'Average Salary' END AS category, - count(1) AS accounts_count + COUNT(1) AS accounts_count FROM Accounts GROUP BY category ) -SELECT s.category, ifnull(accounts_count, 0) AS accounts_count +SELECT s.category, IFNULL(accounts_count, 0) AS accounts_count FROM S AS s LEFT JOIN T AS t ON s.category = t.category; diff --git a/solution/1900-1999/1907.Count Salary Categories/Solution.sql b/solution/1900-1999/1907.Count Salary Categories/Solution.sql index 8c922b9af641c..f6a6acfa56042 100644 --- a/solution/1900-1999/1907.Count Salary Categories/Solution.sql +++ b/solution/1900-1999/1907.Count Salary Categories/Solution.sql @@ -14,11 +14,11 @@ WITH WHEN income > 50000 THEN 'High Salary' ELSE 'Average Salary' END AS category, - count(1) AS accounts_count + COUNT(1) AS accounts_count FROM Accounts GROUP BY category ) -SELECT s.category, ifnull(accounts_count, 0) AS accounts_count +SELECT s.category, IFNULL(accounts_count, 0) AS accounts_count FROM S AS s LEFT JOIN T AS t ON s.category = t.category; diff --git a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md index aba97634513f6..0527606ed07a6 100644 --- a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md +++ b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README.md @@ -133,7 +133,7 @@ WHERE WHERE l1.user_id = t.user1_id AND l2.user_id = t.user2_id ) GROUP BY l1.day, l1.user_id, l2.user_id -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md index 8ddce2c15b2be..d081afc71cce1 100644 --- a/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md +++ b/solution/1900-1999/1917.Leetcodify Friends Recommendations/README_EN.md @@ -126,7 +126,7 @@ WHERE WHERE l1.user_id = t.user1_id AND l2.user_id = t.user2_id ) GROUP BY l1.day, l1.user_id, l2.user_id -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1917.Leetcodify Friends Recommendations/Solution.sql b/solution/1900-1999/1917.Leetcodify Friends Recommendations/Solution.sql index bceff9fccecd2..2589582ae5e81 100644 --- a/solution/1900-1999/1917.Leetcodify Friends Recommendations/Solution.sql +++ b/solution/1900-1999/1917.Leetcodify Friends Recommendations/Solution.sql @@ -19,4 +19,4 @@ WHERE WHERE l1.user_id = t.user1_id AND l2.user_id = t.user2_id ) GROUP BY l1.day, l1.user_id, l2.user_id -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md index 151ccbf15989f..31e08744d7cac 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README.md @@ -114,7 +114,7 @@ FROM LEFT JOIN Listens AS l2 ON user2_id = l2.user_id WHERE l1.song_id = l2.song_id AND l1.day = l2.day GROUP BY 1, 2, l1.day -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md index 93d64b69bd067..ba443c828cd97 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/README_EN.md @@ -108,7 +108,7 @@ FROM LEFT JOIN Listens AS l2 ON user2_id = l2.user_id WHERE l1.song_id = l2.song_id AND l1.day = l2.day GROUP BY 1, 2, l1.day -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; ``` diff --git a/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql b/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql index 76ab3963271e6..8599fa30763f0 100644 --- a/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql +++ b/solution/1900-1999/1919.Leetcodify Similar Friends/Solution.sql @@ -6,4 +6,4 @@ FROM LEFT JOIN Listens AS l2 ON user2_id = l2.user_id WHERE l1.song_id = l2.song_id AND l1.day = l2.day GROUP BY 1, 2, l1.day -HAVING count(DISTINCT l1.song_id) >= 3; +HAVING COUNT(DISTINCT l1.song_id) >= 3; diff --git a/solution/1900-1999/1934.Confirmation Rate/README.md b/solution/1900-1999/1934.Confirmation Rate/README.md index f76a76b4c4cd4..4a71ce6c6039f 100644 --- a/solution/1900-1999/1934.Confirmation Rate/README.md +++ b/solution/1900-1999/1934.Confirmation Rate/README.md @@ -101,8 +101,8 @@ Confirmations 表: # Write your MySQL query statement below SELECT user_id, - round( - sum(if(action = 'confirmed', 1, 0)) / count(1), + ROUND( + SUM(IF(action = 'confirmed', 1, 0)) / COUNT(1), 2 ) AS confirmation_rate FROM diff --git a/solution/1900-1999/1934.Confirmation Rate/README_EN.md b/solution/1900-1999/1934.Confirmation Rate/README_EN.md index fa1b1d553e2c8..95a8b1f36d79d 100644 --- a/solution/1900-1999/1934.Confirmation Rate/README_EN.md +++ b/solution/1900-1999/1934.Confirmation Rate/README_EN.md @@ -97,8 +97,8 @@ User 2 made 2 requests where one was confirmed and the other timed out. The conf # Write your MySQL query statement below SELECT user_id, - round( - sum(if(action = 'confirmed', 1, 0)) / count(1), + ROUND( + SUM(IF(action = 'confirmed', 1, 0)) / COUNT(1), 2 ) AS confirmation_rate FROM diff --git a/solution/1900-1999/1934.Confirmation Rate/Solution.sql b/solution/1900-1999/1934.Confirmation Rate/Solution.sql index 4c9f4b99663a4..9411edbe6cc63 100644 --- a/solution/1900-1999/1934.Confirmation Rate/Solution.sql +++ b/solution/1900-1999/1934.Confirmation Rate/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT user_id, - round(sum(if(action = 'confirmed', 1, 0)) / count(1), 2) AS confirmation_rate + ROUND(SUM(IF(action = 'confirmed', 1, 0)) / COUNT(1), 2) AS confirmation_rate FROM Signups LEFT JOIN Confirmations USING (user_id) diff --git a/solution/1900-1999/1949.Strong Friendship/README.md b/solution/1900-1999/1949.Strong Friendship/README.md index 99d8d4fbdbdf7..43aeeaf7aa9db 100644 --- a/solution/1900-1999/1949.Strong Friendship/README.md +++ b/solution/1900-1999/1949.Strong Friendship/README.md @@ -94,14 +94,14 @@ WITH SELECT t1.user1_id, t1.user2_id, - count(1) AS common_friend + COUNT(1) AS common_friend FROM t AS t1 JOIN t AS t2 ON t1.user2_id = t2.user1_id JOIN t AS t3 ON t1.user1_id = t3.user1_id WHERE t3.user2_id = t2.user2_id AND t1.user1_id < t1.user2_id GROUP BY t1.user1_id, t1.user2_id -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/1900-1999/1949.Strong Friendship/README_EN.md b/solution/1900-1999/1949.Strong Friendship/README_EN.md index 896ed435c010f..a7f23e85aa5bb 100644 --- a/solution/1900-1999/1949.Strong Friendship/README_EN.md +++ b/solution/1900-1999/1949.Strong Friendship/README_EN.md @@ -87,14 +87,14 @@ WITH SELECT t1.user1_id, t1.user2_id, - count(1) AS common_friend + COUNT(1) AS common_friend FROM t AS t1 JOIN t AS t2 ON t1.user2_id = t2.user1_id JOIN t AS t3 ON t1.user1_id = t3.user1_id WHERE t3.user2_id = t2.user2_id AND t1.user1_id < t1.user2_id GROUP BY t1.user1_id, t1.user2_id -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; ``` diff --git a/solution/1900-1999/1949.Strong Friendship/Solution.sql b/solution/1900-1999/1949.Strong Friendship/Solution.sql index b4e324dff12e6..f251834189d11 100644 --- a/solution/1900-1999/1949.Strong Friendship/Solution.sql +++ b/solution/1900-1999/1949.Strong Friendship/Solution.sql @@ -13,11 +13,11 @@ WITH SELECT t1.user1_id, t1.user2_id, - count(1) AS common_friend + COUNT(1) AS common_friend FROM t AS t1 JOIN t AS t2 ON t1.user2_id = t2.user1_id JOIN t AS t3 ON t1.user1_id = t3.user1_id WHERE t3.user2_id = t2.user2_id AND t1.user1_id < t1.user2_id GROUP BY t1.user1_id, t1.user2_id -HAVING count(1) >= 3; +HAVING COUNT(1) >= 3; diff --git a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md index 33beb590c2b3f..9360ea6a2fb26 100644 --- a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md +++ b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md @@ -79,7 +79,7 @@ WITH SELECT r1.user_id AS user1_id, r2.user_id AS user2_id, - rank() OVER (ORDER BY count(1) DESC) AS rk + RANK() OVER (ORDER BY COUNT(1) DESC) AS rk FROM Relations AS r1 JOIN Relations AS r2 ON r1.follower_id = r2.follower_id AND r1.user_id < r2.user_id diff --git a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md index dd339b2dc7519..ab8376e704dd7 100644 --- a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md +++ b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md @@ -73,7 +73,7 @@ WITH SELECT r1.user_id AS user1_id, r2.user_id AS user2_id, - rank() OVER (ORDER BY count(1) DESC) AS rk + RANK() OVER (ORDER BY COUNT(1) DESC) AS rk FROM Relations AS r1 JOIN Relations AS r2 ON r1.follower_id = r2.follower_id AND r1.user_id < r2.user_id diff --git a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/Solution.sql b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/Solution.sql index cff622c82c138..3d82c55cef024 100644 --- a/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/Solution.sql +++ b/solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/Solution.sql @@ -4,7 +4,7 @@ WITH SELECT r1.user_id AS user1_id, r2.user_id AS user2_id, - rank() OVER (ORDER BY count(1) DESC) AS rk + RANK() OVER (ORDER BY COUNT(1) DESC) AS rk FROM Relations AS r1 JOIN Relations AS r2 ON r1.follower_id = r2.follower_id AND r1.user_id < r2.user_id diff --git a/solution/1900-1999/1972.First and Last Call On the Same Day/README.md b/solution/1900-1999/1972.First and Last Call On the Same Day/README.md index ef7dd2effbda5..c1f98a1868509 100644 --- a/solution/1900-1999/1972.First and Last Call On the Same Day/README.md +++ b/solution/1900-1999/1972.First and Last Call On the Same Day/README.md @@ -85,14 +85,14 @@ with s as ( t as ( select caller_id user_id, - first_value(recipient_id) over( - partition by date_format(call_time, '%Y-%m-%d'), + FIRST_VALUE(recipient_id) over( + partition by DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id order by call_time asc ) first, - first_value(recipient_id) over( - partition by date_format(call_time, '%Y-%m-%d'), + FIRST_VALUE(recipient_id) over( + partition by DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id order by call_time desc diff --git a/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md b/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md index d654e79da33ca..996345f2e5673 100644 --- a/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md +++ b/solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md @@ -82,14 +82,14 @@ with s as ( t as ( select caller_id user_id, - first_value(recipient_id) over( - partition by date_format(call_time, '%Y-%m-%d'), + FIRST_VALUE(recipient_id) over( + partition by DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id order by call_time asc ) first, - first_value(recipient_id) over( - partition by date_format(call_time, '%Y-%m-%d'), + FIRST_VALUE(recipient_id) over( + partition by DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id order by call_time desc diff --git a/solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql b/solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql index a782b0ecc5340..4ed4c1b0c6b64 100644 --- a/solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql +++ b/solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql @@ -14,12 +14,12 @@ WITH t AS ( SELECT caller_id AS user_id, - first_value(recipient_id) OVER ( - PARTITION BY date_format(call_time, '%Y-%m-%d'), caller_id + FIRST_VALUE(recipient_id) OVER ( + PARTITION BY DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id ORDER BY call_time ASC ) AS first, - first_value(recipient_id) OVER ( - PARTITION BY date_format(call_time, '%Y-%m-%d'), caller_id + FIRST_VALUE(recipient_id) OVER ( + PARTITION BY DATE_FORMAT(call_time, '%Y-%m-%d'), caller_id ORDER BY call_time DESC ) AS last FROM s diff --git a/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md b/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md index 14e19f4e080cc..8d1ecddd6c044 100644 --- a/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md +++ b/solution/1900-1999/1988.Find Cutoff Score for Each School/README.md @@ -102,7 +102,7 @@ Exam 表: ```sql # Write your MySQL query statement below -SELECT school_id, min(ifnull(score, -1)) AS score +SELECT school_id, MIN(IFNULL(score, -1)) AS score FROM Schools AS s LEFT JOIN Exam AS e ON s.capacity >= e.student_count diff --git a/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md b/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md index f80bb9d32d342..d435630aebcfb 100644 --- a/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md +++ b/solution/1900-1999/1988.Find Cutoff Score for Each School/README_EN.md @@ -97,7 +97,7 @@ Exam table: ```sql # Write your MySQL query statement below -SELECT school_id, min(ifnull(score, -1)) AS score +SELECT school_id, MIN(IFNULL(score, -1)) AS score FROM Schools AS s LEFT JOIN Exam AS e ON s.capacity >= e.student_count diff --git a/solution/1900-1999/1988.Find Cutoff Score for Each School/Solution.sql b/solution/1900-1999/1988.Find Cutoff Score for Each School/Solution.sql index cc94e8e055a12..fd73a028fd5ca 100644 --- a/solution/1900-1999/1988.Find Cutoff Score for Each School/Solution.sql +++ b/solution/1900-1999/1988.Find Cutoff Score for Each School/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT school_id, min(ifnull(score, -1)) AS score +SELECT school_id, MIN(IFNULL(score, -1)) AS score FROM Schools AS s LEFT JOIN Exam AS e ON s.capacity >= e.student_count diff --git a/solution/1900-1999/1990.Count the Number of Experiments/README.md b/solution/1900-1999/1990.Count the Number of Experiments/README.md index 40af4c03f07b3..5efaaab927289 100644 --- a/solution/1900-1999/1990.Count the Number of Experiments/README.md +++ b/solution/1900-1999/1990.Count the Number of Experiments/README.md @@ -101,7 +101,7 @@ WITH P, Exp ) -SELECT platform, experiment_name, count(experiment_id) AS num_experiments +SELECT platform, experiment_name, COUNT(experiment_id) AS num_experiments FROM T AS t LEFT JOIN Experiments USING (platform, experiment_name) diff --git a/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md b/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md index ae90f2698b217..6567e453d9059 100644 --- a/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md +++ b/solution/1900-1999/1990.Count the Number of Experiments/README_EN.md @@ -93,7 +93,7 @@ WITH P, Exp ) -SELECT platform, experiment_name, count(experiment_id) AS num_experiments +SELECT platform, experiment_name, COUNT(experiment_id) AS num_experiments FROM T AS t LEFT JOIN Experiments USING (platform, experiment_name) diff --git a/solution/1900-1999/1990.Count the Number of Experiments/Solution.sql b/solution/1900-1999/1990.Count the Number of Experiments/Solution.sql index 3f0d7af794644..db70d19d16b93 100644 --- a/solution/1900-1999/1990.Count the Number of Experiments/Solution.sql +++ b/solution/1900-1999/1990.Count the Number of Experiments/Solution.sql @@ -20,7 +20,7 @@ WITH P, Exp ) -SELECT platform, experiment_name, count(experiment_id) AS num_experiments +SELECT platform, experiment_name, COUNT(experiment_id) AS num_experiments FROM T AS t LEFT JOIN Experiments USING (platform, experiment_name) diff --git a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md index 73efb264f3eda..b3dcc52dcb8c5 100644 --- a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md +++ b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README.md @@ -110,32 +110,32 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) SELECT 'Senior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM s WHERE cur <= 70000 UNION ALL SELECT 'Junior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM j WHERE cur <= 70000; ``` diff --git a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md index 878850ca86cda..5e2ec440383c6 100644 --- a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md +++ b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/README_EN.md @@ -101,32 +101,32 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) SELECT 'Senior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM s WHERE cur <= 70000 UNION ALL SELECT 'Junior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM j WHERE cur <= 70000; ``` diff --git a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/Solution.sql b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/Solution.sql index 2c41ae2b5bda2..8349a929af99a 100644 --- a/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/Solution.sql +++ b/solution/2000-2099/2004.The Number of Seniors and Juniors to Join the Company/Solution.sql @@ -3,31 +3,31 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) SELECT 'Senior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM s WHERE cur <= 70000 UNION ALL SELECT 'Junior' AS experience, - count(employee_id) AS accepted_candidates + COUNT(employee_id) AS accepted_candidates FROM j WHERE cur <= 70000; diff --git a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md index af304ea6aea4c..fdb5a83e31a63 100644 --- a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md +++ b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README.md @@ -115,20 +115,20 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) diff --git a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md index a3a1bd0b57162..1ac6b0da7cc83 100644 --- a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md +++ b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/README_EN.md @@ -105,20 +105,20 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) diff --git a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/Solution.sql b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/Solution.sql index 6ecfa971b052b..1dce7a8cabcf5 100644 --- a/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/Solution.sql +++ b/solution/2000-2099/2010.The Number of Seniors and Juniors to Join the Company II/Solution.sql @@ -3,20 +3,20 @@ WITH s AS ( SELECT employee_id, - sum(salary) OVER (ORDER BY salary) AS cur + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Senior' ), j AS ( SELECT employee_id, - ifnull( + IFNULL( SELECT - max(cur) + MAX(cur) FROM s WHERE cur <= 70000, 0 - ) + sum(salary) OVER (ORDER BY salary) AS cur + ) + SUM(salary) OVER (ORDER BY salary) AS cur FROM Candidates WHERE experience = 'Junior' ) diff --git a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md index 1995bd3533f25..3e7d9f320def3 100644 --- a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md +++ b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README.md @@ -90,14 +90,14 @@ Streams table: ```sql # Write your MySQL query statement below -SELECT count(DISTINCT sub.account_id) AS accounts_count +SELECT COUNT(DISTINCT sub.account_id) AS accounts_count FROM Subscriptions AS sub LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id WHERE - year(start_date) <= 2021 - AND year(end_date) >= 2021 - AND (year(stream_date) != 2021 OR stream_date > end_date); + YEAR(start_date) <= 2021 + AND YEAR(end_date) >= 2021 + AND (YEAR(stream_date) != 2021 OR stream_date > end_date); ``` diff --git a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md index f7ddfccd7535d..65264c2c28c2d 100644 --- a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md +++ b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/README_EN.md @@ -87,14 +87,14 @@ User 11 did not subscribe in 2021. ```sql # Write your MySQL query statement below -SELECT count(DISTINCT sub.account_id) AS accounts_count +SELECT COUNT(DISTINCT sub.account_id) AS accounts_count FROM Subscriptions AS sub LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id WHERE - year(start_date) <= 2021 - AND year(end_date) >= 2021 - AND (year(stream_date) != 2021 OR stream_date > end_date); + YEAR(start_date) <= 2021 + AND YEAR(end_date) >= 2021 + AND (YEAR(stream_date) != 2021 OR stream_date > end_date); ``` diff --git a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/Solution.sql b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/Solution.sql index 417e03701d268..fae1d28d0721b 100644 --- a/solution/2000-2099/2020.Number of Accounts That Did Not Stream/Solution.sql +++ b/solution/2000-2099/2020.Number of Accounts That Did Not Stream/Solution.sql @@ -1,9 +1,9 @@ # Write your MySQL query statement below -SELECT count(DISTINCT sub.account_id) AS accounts_count +SELECT COUNT(DISTINCT sub.account_id) AS accounts_count FROM Subscriptions AS sub LEFT JOIN Streams AS ss ON sub.account_id = ss.account_id WHERE - year(start_date) <= 2021 - AND year(end_date) >= 2021 - AND (year(stream_date) != 2021 OR stream_date > end_date); + YEAR(start_date) <= 2021 + AND YEAR(end_date) >= 2021 + AND (YEAR(stream_date) != 2021 OR stream_date > end_date); diff --git a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md index 856cf6d9073a6..7a7ab86cd4b2d 100644 --- a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md +++ b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README.md @@ -108,7 +108,7 @@ FROM LEFT JOIN Rounds AS r ON c.interview_id = r.interview_id WHERE years_of_exp >= 2 GROUP BY c.interview_id -HAVING sum(score) > 15; +HAVING SUM(score) > 15; ``` diff --git a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md index 57f6291baf42e..8874a8a3f66c5 100644 --- a/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md +++ b/solution/2000-2099/2041.Accepted Candidates From the Interviews/README_EN.md @@ -101,7 +101,7 @@ FROM LEFT JOIN Rounds AS r ON c.interview_id = r.interview_id WHERE years_of_exp >= 2 GROUP BY c.interview_id -HAVING sum(score) > 15; +HAVING SUM(score) > 15; ``` diff --git a/solution/2000-2099/2041.Accepted Candidates From the Interviews/Solution.sql b/solution/2000-2099/2041.Accepted Candidates From the Interviews/Solution.sql index 48f4af5db54fa..cb695bcbfc203 100644 --- a/solution/2000-2099/2041.Accepted Candidates From the Interviews/Solution.sql +++ b/solution/2000-2099/2041.Accepted Candidates From the Interviews/Solution.sql @@ -5,4 +5,4 @@ FROM LEFT JOIN Rounds AS r ON c.interview_id = r.interview_id WHERE years_of_exp >= 2 GROUP BY c.interview_id -HAVING sum(score) > 15; +HAVING SUM(score) > 15; diff --git a/solution/2000-2099/2051.The Category of Each Member in the Store/README.md b/solution/2000-2099/2051.The Category of Each Member in the Store/README.md index d09247761dc62..6462963b72a1c 100644 --- a/solution/2000-2099/2051.The Category of Each Member in the Store/README.md +++ b/solution/2000-2099/2051.The Category of Each Member in the Store/README.md @@ -140,9 +140,9 @@ SELECT m.member_id, name, CASE - WHEN count(v.visit_id) = 0 THEN 'Bronze' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 80 THEN 'Diamond' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 50 THEN 'Gold' + WHEN COUNT(v.visit_id) = 0 THEN 'Bronze' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 80 THEN 'Diamond' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 50 THEN 'Gold' ELSE 'Silver' END AS category FROM diff --git a/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md b/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md index 4fac58f7ea880..a05b197afe90c 100644 --- a/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md +++ b/solution/2000-2099/2051.The Category of Each Member in the Store/README_EN.md @@ -134,9 +134,9 @@ SELECT m.member_id, name, CASE - WHEN count(v.visit_id) = 0 THEN 'Bronze' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 80 THEN 'Diamond' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 50 THEN 'Gold' + WHEN COUNT(v.visit_id) = 0 THEN 'Bronze' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 80 THEN 'Diamond' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 50 THEN 'Gold' ELSE 'Silver' END AS category FROM diff --git a/solution/2000-2099/2051.The Category of Each Member in the Store/Solution.sql b/solution/2000-2099/2051.The Category of Each Member in the Store/Solution.sql index 366d6ecf2e17c..3c7758addccf2 100644 --- a/solution/2000-2099/2051.The Category of Each Member in the Store/Solution.sql +++ b/solution/2000-2099/2051.The Category of Each Member in the Store/Solution.sql @@ -3,9 +3,9 @@ SELECT m.member_id, name, CASE - WHEN count(v.visit_id) = 0 THEN 'Bronze' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 80 THEN 'Diamond' - WHEN 100 * count(charged_amount) / count(v.visit_id) >= 50 THEN 'Gold' + WHEN COUNT(v.visit_id) = 0 THEN 'Bronze' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 80 THEN 'Diamond' + WHEN 100 * COUNT(charged_amount) / COUNT(v.visit_id) >= 50 THEN 'Gold' ELSE 'Silver' END AS category FROM diff --git a/solution/2000-2099/2066.Account Balance/README.md b/solution/2000-2099/2066.Account Balance/README.md index 41722b4735ca7..851e162f22b60 100644 --- a/solution/2000-2099/2066.Account Balance/README.md +++ b/solution/2000-2099/2066.Account Balance/README.md @@ -84,7 +84,7 @@ Transactions 表: SELECT account_id, day, - sum(if(type = 'Deposit', amount, -amount)) OVER ( + SUM(IF(type = 'Deposit', amount, -amount)) OVER ( PARTITION BY account_id ORDER BY day ) AS balance diff --git a/solution/2000-2099/2066.Account Balance/README_EN.md b/solution/2000-2099/2066.Account Balance/README_EN.md index a9f4b9eba5ab7..51d80bd838e72 100644 --- a/solution/2000-2099/2066.Account Balance/README_EN.md +++ b/solution/2000-2099/2066.Account Balance/README_EN.md @@ -76,7 +76,7 @@ Account 2: SELECT account_id, day, - sum(if(type = 'Deposit', amount, -amount)) OVER ( + SUM(IF(type = 'Deposit', amount, -amount)) OVER ( PARTITION BY account_id ORDER BY day ) AS balance diff --git a/solution/2000-2099/2066.Account Balance/Solution.sql b/solution/2000-2099/2066.Account Balance/Solution.sql index a9a3d833eecb8..6eb47344678f9 100644 --- a/solution/2000-2099/2066.Account Balance/Solution.sql +++ b/solution/2000-2099/2066.Account Balance/Solution.sql @@ -2,7 +2,7 @@ SELECT account_id, day, - sum(if(type = 'Deposit', amount, -amount)) OVER ( + SUM(IF(type = 'Deposit', amount, -amount)) OVER ( PARTITION BY account_id ORDER BY day ) AS balance diff --git a/solution/2000-2099/2072.The Winner University/README.md b/solution/2000-2099/2072.The Winner University/README.md index 9170d1b32b502..a9c5f0da8c801 100644 --- a/solution/2000-2099/2072.The Winner University/README.md +++ b/solution/2000-2099/2072.The Winner University/README.md @@ -155,7 +155,7 @@ SELECT ELSE 'No Winner' END AS winner FROM - (SELECT count(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, + (SELECT COUNT(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, (SELECT COUNT(1) AS cnt FROM California WHERE score >= 90) AS n2; ``` diff --git a/solution/2000-2099/2072.The Winner University/README_EN.md b/solution/2000-2099/2072.The Winner University/README_EN.md index 4ce598a992fe1..6ed98376784cf 100644 --- a/solution/2000-2099/2072.The Winner University/README_EN.md +++ b/solution/2000-2099/2072.The Winner University/README_EN.md @@ -148,7 +148,7 @@ SELECT ELSE 'No Winner' END AS winner FROM - (SELECT count(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, + (SELECT COUNT(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, (SELECT COUNT(1) AS cnt FROM California WHERE score >= 90) AS n2; ``` diff --git a/solution/2000-2099/2072.The Winner University/Solution.sql b/solution/2000-2099/2072.The Winner University/Solution.sql index 9ac7e725e11fa..e2389c588f56b 100644 --- a/solution/2000-2099/2072.The Winner University/Solution.sql +++ b/solution/2000-2099/2072.The Winner University/Solution.sql @@ -6,5 +6,5 @@ SELECT ELSE 'No Winner' END AS winner FROM - (SELECT count(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, + (SELECT COUNT(1) AS cnt FROM NewYork WHERE score >= 90) AS n1, (SELECT COUNT(1) AS cnt FROM California WHERE score >= 90) AS n2; diff --git a/solution/2100-2199/2112.The Airport With the Most Traffic/README.md b/solution/2100-2199/2112.The Airport With the Most Traffic/README.md index e5a0314723923..e2b2985c12baf 100644 --- a/solution/2100-2199/2112.The Airport With the Most Traffic/README.md +++ b/solution/2100-2199/2112.The Airport With the Most Traffic/README.md @@ -106,13 +106,13 @@ WITH SELECT arrival_airport, departure_airport, flights_count FROM Flights ), P AS ( - SELECT departure_airport, sum(flights_count) AS cnt + SELECT departure_airport, SUM(flights_count) AS cnt FROM T GROUP BY 1 ) SELECT departure_airport AS airport_id FROM P -WHERE cnt = (SELECT max(cnt) FROM P); +WHERE cnt = (SELECT MAX(cnt) FROM P); ``` diff --git a/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md b/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md index 094771cbf8f37..7a0260f1697d6 100644 --- a/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md +++ b/solution/2100-2199/2112.The Airport With the Most Traffic/README_EN.md @@ -100,13 +100,13 @@ WITH SELECT arrival_airport, departure_airport, flights_count FROM Flights ), P AS ( - SELECT departure_airport, sum(flights_count) AS cnt + SELECT departure_airport, SUM(flights_count) AS cnt FROM T GROUP BY 1 ) SELECT departure_airport AS airport_id FROM P -WHERE cnt = (SELECT max(cnt) FROM P); +WHERE cnt = (SELECT MAX(cnt) FROM P); ``` diff --git a/solution/2100-2199/2112.The Airport With the Most Traffic/Solution.sql b/solution/2100-2199/2112.The Airport With the Most Traffic/Solution.sql index 8eca6249113aa..beb2d3d508562 100644 --- a/solution/2100-2199/2112.The Airport With the Most Traffic/Solution.sql +++ b/solution/2100-2199/2112.The Airport With the Most Traffic/Solution.sql @@ -6,10 +6,10 @@ WITH SELECT arrival_airport, departure_airport, flights_count FROM Flights ), P AS ( - SELECT departure_airport, sum(flights_count) AS cnt + SELECT departure_airport, SUM(flights_count) AS cnt FROM T GROUP BY 1 ) SELECT departure_airport AS airport_id FROM P -WHERE cnt = (SELECT max(cnt) FROM P); +WHERE cnt = (SELECT MAX(cnt) FROM P); diff --git a/solution/2100-2199/2118.Build the Equation/README.md b/solution/2100-2199/2118.Build the Equation/README.md index 9e39b106198fd..b739ea39fb6b8 100644 --- a/solution/2100-2199/2118.Build the Equation/README.md +++ b/solution/2100-2199/2118.Build the Equation/README.md @@ -115,13 +115,13 @@ WITH SELECT power, CASE power - WHEN 0 THEN IF(factor > 0, concat('+', factor), factor) - WHEN 1 THEN concat( - IF(factor > 0, concat('+', factor), factor), + WHEN 0 THEN IF(factor > 0, CONCAT('+', factor), factor) + WHEN 1 THEN CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), 'X' ) - ELSE concat( - IF(factor > 0, concat('+', factor), factor), + ELSE CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), 'X^', power ) @@ -129,7 +129,7 @@ WITH FROM Terms ) SELECT - concat(group_concat(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation + CONCAT(GROUP_CONCAT(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation FROM T; ``` diff --git a/solution/2100-2199/2118.Build the Equation/README_EN.md b/solution/2100-2199/2118.Build the Equation/README_EN.md index bb4c4b0ff2454..fce91e2b9dea9 100644 --- a/solution/2100-2199/2118.Build the Equation/README_EN.md +++ b/solution/2100-2199/2118.Build the Equation/README_EN.md @@ -107,13 +107,13 @@ WITH SELECT power, CASE power - WHEN 0 THEN IF(factor > 0, concat('+', factor), factor) - WHEN 1 THEN concat( - IF(factor > 0, concat('+', factor), factor), + WHEN 0 THEN IF(factor > 0, CONCAT('+', factor), factor) + WHEN 1 THEN CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), 'X' ) - ELSE concat( - IF(factor > 0, concat('+', factor), factor), + ELSE CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), 'X^', power ) @@ -121,7 +121,7 @@ WITH FROM Terms ) SELECT - concat(group_concat(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation + CONCAT(GROUP_CONCAT(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation FROM T; ``` diff --git a/solution/2100-2199/2118.Build the Equation/Solution.sql b/solution/2100-2199/2118.Build the Equation/Solution.sql index 28acff0502152..5b8f07424ece8 100644 --- a/solution/2100-2199/2118.Build the Equation/Solution.sql +++ b/solution/2100-2199/2118.Build the Equation/Solution.sql @@ -1,22 +1,22 @@ -# Write your MySQL query statement below -WITH - T AS ( - SELECT - power, - CASE power - WHEN 0 THEN IF(factor > 0, concat('+', factor), factor) - WHEN 1 THEN concat( - IF(factor > 0, concat('+', factor), factor), - 'X' - ) - ELSE concat( - IF(factor > 0, concat('+', factor), factor), - 'X^', - power - ) - END AS it - FROM Terms - ) -SELECT - concat(group_concat(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation +# Write your MySQL query statement below +WITH + T AS ( + SELECT + power, + CASE power + WHEN 0 THEN IF(factor > 0, CONCAT('+', factor), factor) + WHEN 1 THEN CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), + 'X' + ) + ELSE CONCAT( + IF(factor > 0, CONCAT('+', factor), factor), + 'X^', + power + ) + END AS it + FROM Terms + ) +SELECT + CONCAT(GROUP_CONCAT(it ORDER BY power DESC SEPARATOR ""), '=0') AS equation FROM T; \ No newline at end of file diff --git a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md index ecd2752228360..537f2c94ad04e 100644 --- a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md +++ b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README.md @@ -98,7 +98,7 @@ Passengers 表: # Write your MySQL query statement below SELECT bus_id, - count(passenger_id) - lag(count(passenger_id), 1, 0) OVER ( + COUNT(passenger_id) - LAG(COUNT(passenger_id), 1, 0) OVER ( ORDER BY b.arrival_time ) AS passengers_cnt FROM diff --git a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md index 16ca845263fb8..bffd0506e96f2 100644 --- a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md +++ b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/README_EN.md @@ -95,7 +95,7 @@ Passengers table: # Write your MySQL query statement below SELECT bus_id, - count(passenger_id) - lag(count(passenger_id), 1, 0) OVER ( + COUNT(passenger_id) - LAG(COUNT(passenger_id), 1, 0) OVER ( ORDER BY b.arrival_time ) AS passengers_cnt FROM diff --git a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/Solution.sql b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/Solution.sql index 5bb887e7038f8..fc488aba43a39 100644 --- a/solution/2100-2199/2142.The Number of Passengers in Each Bus I/Solution.sql +++ b/solution/2100-2199/2142.The Number of Passengers in Each Bus I/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT bus_id, - count(passenger_id) - lag(count(passenger_id), 1, 0) OVER ( + COUNT(passenger_id) - LAG(COUNT(passenger_id), 1, 0) OVER ( ORDER BY b.arrival_time ) AS passengers_cnt FROM diff --git a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md index 02c133a827c9d..4bbca10502613 100644 --- a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md +++ b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README.md @@ -106,8 +106,8 @@ WITH T AS ( SELECT *, - sum(cnt) OVER (ORDER BY dt, bus_id) AS cur, - if(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum + SUM(cnt) OVER (ORDER BY dt, bus_id) AS cur, + IF(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum FROM ( SELECT bus_id, arrival_time AS dt, capacity AS cnt FROM Buses @@ -117,7 +117,7 @@ WITH ) SELECT bus_id, - if(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt + IF(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt FROM T WHERE bus_id > 0 ORDER BY bus_id; diff --git a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md index f1e7752cb70ed..08ed5c9873bbd 100644 --- a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md +++ b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/README_EN.md @@ -100,8 +100,8 @@ WITH T AS ( SELECT *, - sum(cnt) OVER (ORDER BY dt, bus_id) AS cur, - if(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum + SUM(cnt) OVER (ORDER BY dt, bus_id) AS cur, + IF(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum FROM ( SELECT bus_id, arrival_time AS dt, capacity AS cnt FROM Buses @@ -111,7 +111,7 @@ WITH ) SELECT bus_id, - if(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt + IF(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt FROM T WHERE bus_id > 0 ORDER BY bus_id; diff --git a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql index d6c4b6c584345..14ed97801b804 100644 --- a/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql +++ b/solution/2100-2199/2153.The Number of Passengers in Each Bus II/Solution.sql @@ -3,8 +3,8 @@ WITH T AS ( SELECT *, - sum(cnt) OVER (ORDER BY dt, bus_id) AS cur, - if(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum + SUM(cnt) OVER (ORDER BY dt, bus_id) AS cur, + IF(@t > 0, @t := cnt, @t := @t + cnt) AS cur_sum FROM ( SELECT bus_id, arrival_time AS dt, capacity AS cnt FROM Buses @@ -14,7 +14,7 @@ WITH ) SELECT bus_id, - if(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt + IF(cur_sum > 0, cnt - cur_sum, cnt) AS passengers_cnt FROM T WHERE bus_id > 0 ORDER BY bus_id; diff --git a/solution/2100-2199/2159.Order Two Columns Independently/README.md b/solution/2100-2199/2159.Order Two Columns Independently/README.md index e3374a898843c..99f35177d7fb8 100644 --- a/solution/2100-2199/2159.Order Two Columns Independently/README.md +++ b/solution/2100-2199/2159.Order Two Columns Independently/README.md @@ -71,13 +71,13 @@ WITH S AS ( SELECT first_col, - row_number() OVER (ORDER BY first_col) AS rk + ROW_NUMBER() OVER (ORDER BY first_col) AS rk FROM Data ), T AS ( SELECT second_col, - row_number() OVER (ORDER BY second_col DESC) AS rk + ROW_NUMBER() OVER (ORDER BY second_col DESC) AS rk FROM Data ) SELECT first_col, second_col diff --git a/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md b/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md index 9efbef31416e2..ab2c307282e91 100644 --- a/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md +++ b/solution/2100-2199/2159.Order Two Columns Independently/README_EN.md @@ -64,13 +64,13 @@ WITH S AS ( SELECT first_col, - row_number() OVER (ORDER BY first_col) AS rk + ROW_NUMBER() OVER (ORDER BY first_col) AS rk FROM Data ), T AS ( SELECT second_col, - row_number() OVER (ORDER BY second_col DESC) AS rk + ROW_NUMBER() OVER (ORDER BY second_col DESC) AS rk FROM Data ) SELECT first_col, second_col diff --git a/solution/2100-2199/2159.Order Two Columns Independently/Solution.sql b/solution/2100-2199/2159.Order Two Columns Independently/Solution.sql index bf13f56a29c5f..e3a1bfaa34a81 100644 --- a/solution/2100-2199/2159.Order Two Columns Independently/Solution.sql +++ b/solution/2100-2199/2159.Order Two Columns Independently/Solution.sql @@ -3,13 +3,13 @@ WITH S AS ( SELECT first_col, - row_number() OVER (ORDER BY first_col) AS rk + ROW_NUMBER() OVER (ORDER BY first_col) AS rk FROM Data ), T AS ( SELECT second_col, - row_number() OVER (ORDER BY second_col DESC) AS rk + ROW_NUMBER() OVER (ORDER BY second_col DESC) AS rk FROM Data ) SELECT first_col, second_col diff --git a/solution/2100-2199/2173.Longest Winning Streak/README.md b/solution/2100-2199/2173.Longest Winning Streak/README.md index cbfefc691d3fa..e0ca73a9e9ae4 100644 --- a/solution/2100-2199/2173.Longest Winning Streak/README.md +++ b/solution/2100-2199/2173.Longest Winning Streak/README.md @@ -93,21 +93,21 @@ WITH S AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY player_id ORDER BY match_day - ) - row_number() OVER ( + ) - ROW_NUMBER() OVER ( PARTITION BY player_id, result ORDER BY match_day ) AS rk FROM Matches ), T AS ( - SELECT player_id, sum(result = 'Win') AS s + SELECT player_id, SUM(result = 'Win') AS s FROM S GROUP BY player_id, rk ) -SELECT player_id, max(s) AS longest_streak +SELECT player_id, MAX(s) AS longest_streak FROM T GROUP BY player_id; ``` diff --git a/solution/2100-2199/2173.Longest Winning Streak/README_EN.md b/solution/2100-2199/2173.Longest Winning Streak/README_EN.md index 1a13f64105c98..1ed81a235b958 100644 --- a/solution/2100-2199/2173.Longest Winning Streak/README_EN.md +++ b/solution/2100-2199/2173.Longest Winning Streak/README_EN.md @@ -86,21 +86,21 @@ WITH S AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY player_id ORDER BY match_day - ) - row_number() OVER ( + ) - ROW_NUMBER() OVER ( PARTITION BY player_id, result ORDER BY match_day ) AS rk FROM Matches ), T AS ( - SELECT player_id, sum(result = 'Win') AS s + SELECT player_id, SUM(result = 'Win') AS s FROM S GROUP BY player_id, rk ) -SELECT player_id, max(s) AS longest_streak +SELECT player_id, MAX(s) AS longest_streak FROM T GROUP BY player_id; ``` diff --git a/solution/2100-2199/2173.Longest Winning Streak/Solution.sql b/solution/2100-2199/2173.Longest Winning Streak/Solution.sql index cee635da1182b..31e0b8930982e 100644 --- a/solution/2100-2199/2173.Longest Winning Streak/Solution.sql +++ b/solution/2100-2199/2173.Longest Winning Streak/Solution.sql @@ -3,20 +3,20 @@ WITH S AS ( SELECT *, - row_number() OVER ( + ROW_NUMBER() OVER ( PARTITION BY player_id ORDER BY match_day - ) - row_number() OVER ( + ) - ROW_NUMBER() OVER ( PARTITION BY player_id, result ORDER BY match_day ) AS rk FROM Matches ), T AS ( - SELECT player_id, sum(result = 'Win') AS s + SELECT player_id, SUM(result = 'Win') AS s FROM S GROUP BY player_id, rk ) -SELECT player_id, max(s) AS longest_streak +SELECT player_id, MAX(s) AS longest_streak FROM T GROUP BY player_id; diff --git a/solution/2100-2199/2175.The Change in Global Rankings/README.md b/solution/2100-2199/2175.The Change in Global Rankings/README.md index 5b25757a0fd44..bcff74ce5cdbd 100644 --- a/solution/2100-2199/2175.The Change in Global Rankings/README.md +++ b/solution/2100-2199/2175.The Change in Global Rankings/README.md @@ -129,15 +129,15 @@ New Zealand 没有获得或丢失分数,他们的排名也没有发生变化 # Write your MySQL query statement below WITH P AS ( - SELECT team_id, sum(points_change) AS delta + SELECT team_id, SUM(points_change) AS delta FROM PointsChange GROUP BY team_id ) SELECT team_id, name, - CAST(rank() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( - rank() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED + CAST(RANK() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( + RANK() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED ) AS 'rank_diff' FROM TeamPoints diff --git a/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md b/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md index 7677d247e7930..d1a3b4d45260c 100644 --- a/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md +++ b/solution/2100-2199/2175.The Change in Global Rankings/README_EN.md @@ -118,15 +118,15 @@ New Zealand did not gain or lose points and their rank did not change. # Write your MySQL query statement below WITH P AS ( - SELECT team_id, sum(points_change) AS delta + SELECT team_id, SUM(points_change) AS delta FROM PointsChange GROUP BY team_id ) SELECT team_id, name, - CAST(rank() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( - rank() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED + CAST(RANK() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( + RANK() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED ) AS 'rank_diff' FROM TeamPoints diff --git a/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql b/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql index f6afb256ea885..da8b3ea362c91 100644 --- a/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql +++ b/solution/2100-2199/2175.The Change in Global Rankings/Solution.sql @@ -1,15 +1,15 @@ # Write your MySQL query statement below WITH P AS ( - SELECT team_id, sum(points_change) AS delta + SELECT team_id, SUM(points_change) AS delta FROM PointsChange GROUP BY team_id ) SELECT team_id, name, - CAST(rank() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( - rank() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED + CAST(RANK() OVER (ORDER BY points DESC, name) AS SIGNED) - CAST( + RANK() OVER (ORDER BY (points + delta) DESC, name) AS SIGNED ) AS 'rank_diff' FROM TeamPoints diff --git a/solution/2100-2199/2199.Finding the Topic of Each Post/README.md b/solution/2100-2199/2199.Finding the Topic of Each Post/README.md index 0323914db30a5..de75ca3385be4 100644 --- a/solution/2100-2199/2199.Finding the Topic of Each Post/README.md +++ b/solution/2100-2199/2199.Finding the Topic of Each Post/README.md @@ -115,10 +115,10 @@ Posts 表: # Write your MySQL query statement below SELECT post_id, - ifnull(group_concat(DISTINCT topic_id), 'Ambiguous!') AS topic + IFNULL(GROUP_CONCAT(DISTINCT topic_id), 'Ambiguous!') AS topic FROM Posts - LEFT JOIN Keywords ON instr(concat(' ', content, ' '), concat(' ', word, ' ')) > 0 + LEFT JOIN Keywords ON INSTR(CONCAT(' ', content, ' '), CONCAT(' ', word, ' ')) > 0 GROUP BY post_id; ``` diff --git a/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md b/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md index c10665dfdef48..86fb4ea585f2b 100644 --- a/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md +++ b/solution/2100-2199/2199.Finding the Topic of Each Post/README_EN.md @@ -110,10 +110,10 @@ Note that it is okay to have one word that expresses more than one topic. # Write your MySQL query statement below SELECT post_id, - ifnull(group_concat(DISTINCT topic_id), 'Ambiguous!') AS topic + IFNULL(GROUP_CONCAT(DISTINCT topic_id), 'Ambiguous!') AS topic FROM Posts - LEFT JOIN Keywords ON instr(concat(' ', content, ' '), concat(' ', word, ' ')) > 0 + LEFT JOIN Keywords ON INSTR(CONCAT(' ', content, ' '), CONCAT(' ', word, ' ')) > 0 GROUP BY post_id; ``` diff --git a/solution/2100-2199/2199.Finding the Topic of Each Post/Solution.sql b/solution/2100-2199/2199.Finding the Topic of Each Post/Solution.sql index a2d826e67b46a..e694cde2d9b77 100644 --- a/solution/2100-2199/2199.Finding the Topic of Each Post/Solution.sql +++ b/solution/2100-2199/2199.Finding the Topic of Each Post/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT post_id, - ifnull(group_concat(DISTINCT topic_id), 'Ambiguous!') AS topic + IFNULL(GROUP_CONCAT(DISTINCT topic_id), 'Ambiguous!') AS topic FROM Posts - LEFT JOIN Keywords ON instr(concat(' ', content, ' '), concat(' ', word, ' ')) > 0 + LEFT JOIN Keywords ON INSTR(CONCAT(' ', content, ' '), CONCAT(' ', word, ' ')) > 0 GROUP BY post_id; diff --git a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md index 1e62fc0b647e1..3d3c42149e92f 100644 --- a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md +++ b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README.md @@ -76,7 +76,7 @@ BEGIN RETURN ( # Write your MySQL query statement below. # Write your MySQL query statement below. - SELECT count(DISTINCT user_id) AS user_cnt + SELECT COUNT(DISTINCT user_id) AS user_cnt FROM Purchases WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount; ); diff --git a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md index 78253c734830d..2943dacbd93d2 100644 --- a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md +++ b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/README_EN.md @@ -66,7 +66,7 @@ BEGIN RETURN ( # Write your MySQL query statement below. # Write your MySQL query statement below. - SELECT count(DISTINCT user_id) AS user_cnt + SELECT COUNT(DISTINCT user_id) AS user_cnt FROM Purchases WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount; ); diff --git a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql index 402c6dee40c43..4483969a58e8a 100644 --- a/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql +++ b/solution/2200-2299/2205.The Number of Users That Are Eligible for Discount/Solution.sql @@ -1,10 +1,10 @@ -CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT -BEGIN - RETURN ( - # Write your MySQL query statement below. - # Write your MySQL query statement below. - SELECT count(DISTINCT user_id) AS user_cnt - FROM Purchases - WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount; - ); +CREATE FUNCTION getUserIDs(startDate DATE, endDate DATE, minAmount INT) RETURNS INT +BEGIN + RETURN ( + # Write your MySQL query statement below. + # Write your MySQL query statement below. + SELECT COUNT(DISTINCT user_id) AS user_cnt + FROM Purchases + WHERE time_stamp BETWEEN startDate AND endDate AND amount >= minAmount; + ); END \ No newline at end of file diff --git a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md index 0c9de281f88fd..024f5f14dc879 100644 --- a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md +++ b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README.md @@ -73,9 +73,9 @@ WITH t AS ( SELECT user_id, - datediff( + DATEDIFF( purchase_date, - lag(purchase_date, 1) OVER ( + LAG(purchase_date, 1) OVER ( PARTITION BY user_id ORDER BY purchase_date ) diff --git a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md index a1c69fa22b79f..77ab55ad531c0 100644 --- a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md +++ b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/README_EN.md @@ -67,9 +67,9 @@ WITH t AS ( SELECT user_id, - datediff( + DATEDIFF( purchase_date, - lag(purchase_date, 1) OVER ( + LAG(purchase_date, 1) OVER ( PARTITION BY user_id ORDER BY purchase_date ) diff --git a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/Solution.sql b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/Solution.sql index 25ae200f68266..8be15dedee393 100644 --- a/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/Solution.sql +++ b/solution/2200-2299/2228.Users With Two Purchases Within Seven Days/Solution.sql @@ -3,9 +3,9 @@ WITH t AS ( SELECT user_id, - datediff( + DATEDIFF( purchase_date, - lag(purchase_date, 1) OVER ( + LAG(purchase_date, 1) OVER ( PARTITION BY user_id ORDER BY purchase_date ) diff --git a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md index b9aa34341edaa..882a129454ecd 100644 --- a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md +++ b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README.md @@ -70,7 +70,7 @@ ID = 11 的司机从来不是乘客。 ```sql # Write your MySQL query statement below WITH T AS (SELECT DISTINCT driver_id FROM Rides) -SELECT t.driver_id, count(passenger_id) AS cnt +SELECT t.driver_id, COUNT(passenger_id) AS cnt FROM T AS t LEFT JOIN Rides AS r ON t.driver_id = r.passenger_id diff --git a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md index 5c33014b19030..1920c89362a1f 100644 --- a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md +++ b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/README_EN.md @@ -65,7 +65,7 @@ The driver with ID = 11 was never a passenger. ```sql # Write your MySQL query statement below WITH T AS (SELECT DISTINCT driver_id FROM Rides) -SELECT t.driver_id, count(passenger_id) AS cnt +SELECT t.driver_id, COUNT(passenger_id) AS cnt FROM T AS t LEFT JOIN Rides AS r ON t.driver_id = r.passenger_id diff --git a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/Solution.sql b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/Solution.sql index 7cdba3146cb28..81c6652bda641 100644 --- a/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/Solution.sql +++ b/solution/2200-2299/2238.Number of Times a Driver Was a Passenger/Solution.sql @@ -1,6 +1,6 @@ # Write your MySQL query statement below WITH T AS (SELECT DISTINCT driver_id FROM Rides) -SELECT t.driver_id, count(passenger_id) AS cnt +SELECT t.driver_id, COUNT(passenger_id) AS cnt FROM T AS t LEFT JOIN Rides AS r ON t.driver_id = r.passenger_id diff --git a/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql b/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql index f79841c8b9283..679b71cf5a66e 100644 --- a/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql +++ b/solution/2200-2299/2252.Dynamic Pivoting of a Table/Solution.sql @@ -1,17 +1,17 @@ -CREATE PROCEDURE PivotProducts() -BEGIN - # Write your MySQL query statement below. - SET group_concat_max_len = 5000; - SELECT GROUP_CONCAT(DISTINCT 'MAX(CASE WHEN store = \'', - store, - '\' THEN price ELSE NULL END) AS ', - store - ORDER BY store) INTO @sql - FROM Products; - SET @sql = CONCAT('SELECT product_id, ', - @sql, - ' FROM Products GROUP BY product_id'); - PREPARE stmt FROM @sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; +CREATE PROCEDURE PivotProducts() +BEGIN + # Write your MySQL query statement below. + SET group_concat_max_len = 5000; + SELECT GROUP_CONCAT(DISTINCT 'MAX(CASE WHEN store = \'', + store, + '\' THEN price ELSE NULL END) AS ', + store + ORDER BY store) INTO @sql + FROM Products; + SET @sql = CONCAT('SELECT product_id, ', + @sql, + ' FROM Products GROUP BY product_id'); + PREPARE stmt FROM @sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; END \ No newline at end of file diff --git a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql index 80a919a2c2e84..d006794f0efc6 100644 --- a/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql +++ b/solution/2200-2299/2253.Dynamic Unpivoting of a Table/Solution.sql @@ -1,27 +1,27 @@ -CREATE PROCEDURE UnpivotProducts() -BEGIN - # Write your MySQL query statement below. - SET group_concat_max_len = 5000; - WITH - t AS ( - SELECT column_name - FROM information_schema.columns - WHERE - table_schema = DATABASE() - AND table_name = 'Products' - AND column_name != 'product_id' - ) - SELECT - GROUP_CONCAT( - 'SELECT product_id, \'', - column_name, - '\' store, ', - column_name, - ' price FROM Products WHERE ', - column_name, - ' IS NOT NULL' SEPARATOR ' UNION ' - ) INTO @sql from t; - PREPARE stmt FROM @sql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; -END; +CREATE PROCEDURE UnpivotProducts() +BEGIN + # Write your MySQL query statement below. + SET group_concat_max_len = 5000; + WITH + t AS ( + SELECT column_name + FROM information_schema.columns + WHERE + table_schema = DATABASE() + AND table_name = 'Products' + AND column_name != 'product_id' + ) + SELECT + GROUP_CONCAT( + 'SELECT product_id, \'', + column_name, + '\' store, ', + column_name, + ' price FROM Products WHERE ', + column_name, + ' IS NOT NULL' SEPARATOR ' UNION ' + ) INTO @sql from t; + PREPARE stmt FROM @sql; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; +END; diff --git a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md index df82cef95a2c0..96d24a84eb90c 100644 --- a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md +++ b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README.md @@ -72,7 +72,7 @@ Orders 表: # Write your MySQL query statement below WITH P AS ( - SELECT product_id, year(purchase_date) AS y, count(1) >= 3 AS mark + SELECT product_id, YEAR(purchase_date) AS y, COUNT(1) >= 3 AS mark FROM Orders GROUP BY 1, 2 ) @@ -87,10 +87,10 @@ WHERE p1.mark AND p2.mark; # Write your MySQL query statement below WITH P AS ( - SELECT product_id, year(purchase_date) AS y + SELECT product_id, YEAR(purchase_date) AS y FROM Orders GROUP BY 1, 2 - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT DISTINCT p1.product_id FROM diff --git a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md index 0562e41ceab85..b4f27035d14d2 100644 --- a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md +++ b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/README_EN.md @@ -65,7 +65,7 @@ Product 2 was ordered one time in 2022. We do not include it in the answer. # Write your MySQL query statement below WITH P AS ( - SELECT product_id, year(purchase_date) AS y, count(1) >= 3 AS mark + SELECT product_id, YEAR(purchase_date) AS y, COUNT(1) >= 3 AS mark FROM Orders GROUP BY 1, 2 ) @@ -80,10 +80,10 @@ WHERE p1.mark AND p2.mark; # Write your MySQL query statement below WITH P AS ( - SELECT product_id, year(purchase_date) AS y + SELECT product_id, YEAR(purchase_date) AS y FROM Orders GROUP BY 1, 2 - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT DISTINCT p1.product_id FROM diff --git a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/Solution.sql b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/Solution.sql index 3832e47c27ad9..683c145de576f 100644 --- a/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/Solution.sql +++ b/solution/2200-2299/2292.Products With Three or More Orders in Two Consecutive Years/Solution.sql @@ -1,10 +1,10 @@ # Write your MySQL query statement below WITH P AS ( - SELECT product_id, year(purchase_date) AS y + SELECT product_id, YEAR(purchase_date) AS y FROM Orders GROUP BY 1, 2 - HAVING count(1) >= 3 + HAVING COUNT(1) >= 3 ) SELECT DISTINCT p1.product_id FROM diff --git a/solution/2200-2299/2298.Tasks Count in the Weekend/README.md b/solution/2200-2299/2298.Tasks Count in the Weekend/README.md index 805b6d1c5e4de..4c706884beb2c 100644 --- a/solution/2200-2299/2298.Tasks Count in the Weekend/README.md +++ b/solution/2200-2299/2298.Tasks Count in the Weekend/README.md @@ -83,8 +83,8 @@ Task 6 是在周日提交的。 ```sql # Write your MySQL query statement below SELECT - sum(weekday(submit_date) IN (5, 6)) AS weekend_cnt, - sum(weekday(submit_date) NOT IN (5, 6)) AS working_cnt + SUM(WEEKDAY(submit_date) IN (5, 6)) AS weekend_cnt, + SUM(WEEKDAY(submit_date) NOT IN (5, 6)) AS working_cnt FROM Tasks; ``` diff --git a/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md b/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md index 87876dcdd52f0..877973fd7e560 100644 --- a/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md +++ b/solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md @@ -73,8 +73,8 @@ Task 6 was submitted on Sunday. ```sql # Write your MySQL query statement below SELECT - sum(weekday(submit_date) IN (5, 6)) AS weekend_cnt, - sum(weekday(submit_date) NOT IN (5, 6)) AS working_cnt + SUM(WEEKDAY(submit_date) IN (5, 6)) AS weekend_cnt, + SUM(WEEKDAY(submit_date) NOT IN (5, 6)) AS working_cnt FROM Tasks; ``` diff --git a/solution/2200-2299/2298.Tasks Count in the Weekend/Solution.sql b/solution/2200-2299/2298.Tasks Count in the Weekend/Solution.sql index 51675c2d6b3fc..31562a2884f1a 100644 --- a/solution/2200-2299/2298.Tasks Count in the Weekend/Solution.sql +++ b/solution/2200-2299/2298.Tasks Count in the Weekend/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below SELECT - sum(weekday(submit_date) IN (5, 6)) AS weekend_cnt, - sum(weekday(submit_date) NOT IN (5, 6)) AS working_cnt + SUM(WEEKDAY(submit_date) IN (5, 6)) AS weekend_cnt, + SUM(WEEKDAY(submit_date) NOT IN (5, 6)) AS working_cnt FROM Tasks; diff --git a/solution/2300-2399/2308.Arrange Table by Gender/README.md b/solution/2300-2399/2308.Arrange Table by Gender/README.md index ef1736ab80096..32d2a450d3b43 100644 --- a/solution/2300-2399/2308.Arrange Table by Gender/README.md +++ b/solution/2300-2399/2308.Arrange Table by Gender/README.md @@ -85,7 +85,7 @@ WITH t AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY gender ORDER BY user_id ) AS rk1, diff --git a/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md b/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md index 9efec401ee5e5..0ac503f0ead85 100644 --- a/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md +++ b/solution/2300-2399/2308.Arrange Table by Gender/README_EN.md @@ -80,7 +80,7 @@ WITH t AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY gender ORDER BY user_id ) AS rk1, diff --git a/solution/2300-2399/2308.Arrange Table by Gender/Solution.sql b/solution/2300-2399/2308.Arrange Table by Gender/Solution.sql index e8760fbb44b27..238689bfb9172 100644 --- a/solution/2300-2399/2308.Arrange Table by Gender/Solution.sql +++ b/solution/2300-2399/2308.Arrange Table by Gender/Solution.sql @@ -3,7 +3,7 @@ WITH t AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY gender ORDER BY user_id ) AS rk1, diff --git a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md index b4523aafad46a..341c7889a0b51 100644 --- a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md +++ b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README.md @@ -77,7 +77,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY city_id ORDER BY degree DESC, day ) AS rk diff --git a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md index 70ef18d0d189e..63a280217a11f 100644 --- a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md +++ b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/README_EN.md @@ -70,7 +70,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY city_id ORDER BY degree DESC, day ) AS rk diff --git a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/Solution.sql b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/Solution.sql index 8375da603cb73..43524120e3ab0 100644 --- a/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/Solution.sql +++ b/solution/2300-2399/2314.The First Day of the Maximum Recorded Degree in Each City/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT *, - rank() OVER ( + RANK() OVER ( PARTITION BY city_id ORDER BY degree DESC, day ) AS rk diff --git a/solution/2300-2399/2324.Product Sales Analysis IV/README.md b/solution/2300-2399/2324.Product Sales Analysis IV/README.md index d560060d37247..5e2d62456cb3f 100644 --- a/solution/2300-2399/2324.Product Sales Analysis IV/README.md +++ b/solution/2300-2399/2324.Product Sales Analysis IV/README.md @@ -108,9 +108,9 @@ WITH SELECT user_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY user_id - ORDER BY sum(quantity * price) DESC + ORDER BY SUM(quantity * price) DESC ) AS rk FROM Sales diff --git a/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md b/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md index b966e5a9a6d7e..7b270083fcbf6 100644 --- a/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md +++ b/solution/2300-2399/2324.Product Sales Analysis IV/README_EN.md @@ -101,9 +101,9 @@ WITH SELECT user_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY user_id - ORDER BY sum(quantity * price) DESC + ORDER BY SUM(quantity * price) DESC ) AS rk FROM Sales diff --git a/solution/2300-2399/2324.Product Sales Analysis IV/Solution.sql b/solution/2300-2399/2324.Product Sales Analysis IV/Solution.sql index da7f9c80bedaf..3c241bc9e674d 100644 --- a/solution/2300-2399/2324.Product Sales Analysis IV/Solution.sql +++ b/solution/2300-2399/2324.Product Sales Analysis IV/Solution.sql @@ -4,9 +4,9 @@ WITH SELECT user_id, product_id, - rank() OVER ( + RANK() OVER ( PARTITION BY user_id - ORDER BY sum(quantity * price) DESC + ORDER BY SUM(quantity * price) DESC ) AS rk FROM Sales diff --git a/solution/2300-2399/2329.Product Sales Analysis V/README.md b/solution/2300-2399/2329.Product Sales Analysis V/README.md index 7f41294c7da18..c29ddcd99c73c 100644 --- a/solution/2300-2399/2329.Product Sales Analysis V/README.md +++ b/solution/2300-2399/2329.Product Sales Analysis V/README.md @@ -94,7 +94,7 @@ Product 表: ```sql # Write your MySQL query statement below -SELECT user_id, sum(quantity * price) AS spending +SELECT user_id, SUM(quantity * price) AS spending FROM Sales JOIN Product USING (product_id) diff --git a/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md b/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md index e5f35a4b1a136..68ce7f7754262 100644 --- a/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md +++ b/solution/2300-2399/2329.Product Sales Analysis V/README_EN.md @@ -89,7 +89,7 @@ Users 102 and 103 spent the same amount and we break the tie by their ID while u ```sql # Write your MySQL query statement below -SELECT user_id, sum(quantity * price) AS spending +SELECT user_id, SUM(quantity * price) AS spending FROM Sales JOIN Product USING (product_id) diff --git a/solution/2300-2399/2329.Product Sales Analysis V/Solution.sql b/solution/2300-2399/2329.Product Sales Analysis V/Solution.sql index e600bbd37eb44..8710d53212aad 100644 --- a/solution/2300-2399/2329.Product Sales Analysis V/Solution.sql +++ b/solution/2300-2399/2329.Product Sales Analysis V/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT user_id, sum(quantity * price) AS spending +SELECT user_id, SUM(quantity * price) AS spending FROM Sales JOIN Product USING (product_id) diff --git a/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md b/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md index c1d006e0e2b99..ab8f66e25b616 100644 --- a/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md +++ b/solution/2300-2399/2346.Compute the Rank as a Percentage/README.md @@ -87,14 +87,14 @@ Students 表: SELECT student_id, department_id, - ifnull( - round( + IFNULL( + ROUND( ( - rank() OVER ( + RANK() OVER ( PARTITION BY department_id ORDER BY mark DESC ) - 1 - ) * 100 / (count(1) OVER (PARTITION BY department_id) - 1), + ) * 100 / (COUNT(1) OVER (PARTITION BY department_id) - 1), 2 ), 0 diff --git a/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md b/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md index 09f815b8269c9..19a74206cda29 100644 --- a/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md +++ b/solution/2300-2399/2346.Compute the Rank as a Percentage/README_EN.md @@ -72,14 +72,14 @@ For Department 2: SELECT student_id, department_id, - ifnull( - round( + IFNULL( + ROUND( ( - rank() OVER ( + RANK() OVER ( PARTITION BY department_id ORDER BY mark DESC ) - 1 - ) * 100 / (count(1) OVER (PARTITION BY department_id) - 1), + ) * 100 / (COUNT(1) OVER (PARTITION BY department_id) - 1), 2 ), 0 diff --git a/solution/2300-2399/2346.Compute the Rank as a Percentage/Solution.sql b/solution/2300-2399/2346.Compute the Rank as a Percentage/Solution.sql index a1d5b9d19a3a3..ed6cd8b667051 100644 --- a/solution/2300-2399/2346.Compute the Rank as a Percentage/Solution.sql +++ b/solution/2300-2399/2346.Compute the Rank as a Percentage/Solution.sql @@ -2,14 +2,14 @@ SELECT student_id, department_id, - ifnull( - round( + IFNULL( + ROUND( ( - rank() OVER ( + RANK() OVER ( PARTITION BY department_id ORDER BY mark DESC ) - 1 - ) * 100 / (count(1) OVER (PARTITION BY department_id) - 1), + ) * 100 / (COUNT(1) OVER (PARTITION BY department_id) - 1), 2 ), 0 diff --git a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md index 821d816d8674e..9cf835ccb892f 100644 --- a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md +++ b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README.md @@ -75,7 +75,7 @@ Teacher 表: ```sql # Write your MySQL query statement below -SELECT teacher_id, count(DISTINCT subject_id) AS cnt +SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt FROM Teacher GROUP BY 1; ``` diff --git a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md index 8b78abfaf70da..c0efec24bf3cc 100644 --- a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md +++ b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/README_EN.md @@ -69,7 +69,7 @@ Teacher 2: ```sql # Write your MySQL query statement below -SELECT teacher_id, count(DISTINCT subject_id) AS cnt +SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt FROM Teacher GROUP BY 1; ``` diff --git a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/Solution.sql b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/Solution.sql index cda6876878ae7..56dd63346694d 100644 --- a/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/Solution.sql +++ b/solution/2300-2399/2356.Number of Unique Subjects Taught by Each Teacher/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below -SELECT teacher_id, count(DISTINCT subject_id) AS cnt +SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt FROM Teacher GROUP BY 1; diff --git a/solution/2300-2399/2362.Generate the Invoice/README.md b/solution/2300-2399/2362.Generate the Invoice/README.md index f95bc2085a9d0..f7a748d47560e 100644 --- a/solution/2300-2399/2362.Generate the Invoice/README.md +++ b/solution/2300-2399/2362.Generate the Invoice/README.md @@ -101,7 +101,7 @@ WITH JOIN Products USING (product_id) ), T AS ( - SELECT invoice_id, sum(price * quantity) AS amount + SELECT invoice_id, SUM(price * quantity) AS amount FROM P GROUP BY invoice_id ORDER BY 2 DESC, 1 diff --git a/solution/2300-2399/2362.Generate the Invoice/README_EN.md b/solution/2300-2399/2362.Generate the Invoice/README_EN.md index bf6fcf8455351..d4e7ed38caf35 100644 --- a/solution/2300-2399/2362.Generate the Invoice/README_EN.md +++ b/solution/2300-2399/2362.Generate the Invoice/README_EN.md @@ -95,7 +95,7 @@ WITH JOIN Products USING (product_id) ), T AS ( - SELECT invoice_id, sum(price * quantity) AS amount + SELECT invoice_id, SUM(price * quantity) AS amount FROM P GROUP BY invoice_id ORDER BY 2 DESC, 1 diff --git a/solution/2300-2399/2362.Generate the Invoice/Solution.sql b/solution/2300-2399/2362.Generate the Invoice/Solution.sql index 1fad140a63d1c..b86a2031425c6 100644 --- a/solution/2300-2399/2362.Generate the Invoice/Solution.sql +++ b/solution/2300-2399/2362.Generate the Invoice/Solution.sql @@ -7,7 +7,7 @@ WITH JOIN Products USING (product_id) ), T AS ( - SELECT invoice_id, sum(price * quantity) AS amount + SELECT invoice_id, SUM(price * quantity) AS amount FROM P GROUP BY invoice_id ORDER BY 2 DESC, 1 diff --git a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md index 854cf6c2836aa..63c545a87118d 100644 --- a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md +++ b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README.md @@ -122,7 +122,7 @@ Jerry 的总数是 0。 ```sql # Write your MySQL query statement below -SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total +SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total FROM Salesperson AS sp LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id diff --git a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md index 2cb2be20c63e2..a07880f7a2da5 100644 --- a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md +++ b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/README_EN.md @@ -118,7 +118,7 @@ The total for Jerry is 0. ```sql # Write your MySQL query statement below -SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total +SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total FROM Salesperson AS sp LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id diff --git a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/Solution.sql b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/Solution.sql index d197a19ca8320..c18da503eac5d 100644 --- a/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/Solution.sql +++ b/solution/2300-2399/2372.Calculate the Influence of Each Salesperson/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT sp.salesperson_id, name, ifnull(sum(price), 0) AS total +SELECT sp.salesperson_id, name, IFNULL(SUM(price), 0) AS total FROM Salesperson AS sp LEFT JOIN Customer AS c ON sp.salesperson_id = c.salesperson_id diff --git a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md index 4f81a96597d76..613263e86583b 100644 --- a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md +++ b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README.md @@ -95,13 +95,13 @@ FROM CoffeeShop; # Write your MySQL query statement below WITH S AS ( - SELECT *, row_number() OVER () AS rk + SELECT *, ROW_NUMBER() OVER () AS rk FROM CoffeeShop ), T AS ( SELECT *, - sum( + SUM( CASE WHEN drink IS NULL THEN 0 ELSE 1 @@ -111,7 +111,7 @@ WITH ) SELECT id, - max(drink) OVER ( + MAX(drink) OVER ( PARTITION BY gid ORDER BY rk ) AS drink diff --git a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md index 1905ba430ac74..e988245052da7 100644 --- a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md +++ b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/README_EN.md @@ -80,13 +80,13 @@ FROM CoffeeShop; # Write your MySQL query statement below WITH S AS ( - SELECT *, row_number() OVER () AS rk + SELECT *, ROW_NUMBER() OVER () AS rk FROM CoffeeShop ), T AS ( SELECT *, - sum( + SUM( CASE WHEN drink IS NULL THEN 0 ELSE 1 @@ -96,7 +96,7 @@ WITH ) SELECT id, - max(drink) OVER ( + MAX(drink) OVER ( PARTITION BY gid ORDER BY rk ) AS drink diff --git a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/Solution.sql b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/Solution.sql index 1aa8ec5a218bc..778703af00efe 100644 --- a/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/Solution.sql +++ b/solution/2300-2399/2388.Change Null Values in a Table to the Previous Value/Solution.sql @@ -1,13 +1,13 @@ # Write your MySQL query statement below WITH S AS ( - SELECT *, row_number() OVER () AS rk + SELECT *, ROW_NUMBER() OVER () AS rk FROM CoffeeShop ), T AS ( SELECT *, - sum( + SUM( CASE WHEN drink IS NULL THEN 0 ELSE 1 @@ -17,7 +17,7 @@ WITH ) SELECT id, - max(drink) OVER ( + MAX(drink) OVER ( PARTITION BY gid ORDER BY rk ) AS drink diff --git a/solution/2300-2399/2394.Employees With Deductions/README.md b/solution/2300-2399/2394.Employees With Deductions/README.md index 17b957866ab0e..9a7f0446ac9ec 100644 --- a/solution/2300-2399/2394.Employees With Deductions/README.md +++ b/solution/2300-2399/2394.Employees With Deductions/README.md @@ -112,7 +112,7 @@ WITH T AS ( SELECT employee_id, - sum(ceiling(timestampdiff(second, in_time, out_time) / 60)) / 60 AS tot + SUM(ceiling(TIMESTAMPDIFF(second, in_time, out_time) / 60)) / 60 AS tot FROM Logs GROUP BY employee_id ) @@ -120,7 +120,7 @@ SELECT employee_id FROM Employees LEFT JOIN T USING (employee_id) -WHERE ifnull(tot, 0) < needed_hours; +WHERE IFNULL(tot, 0) < needed_hours; ``` diff --git a/solution/2300-2399/2394.Employees With Deductions/README_EN.md b/solution/2300-2399/2394.Employees With Deductions/README_EN.md index e44a3bb2126e2..4cb8b5c877c59 100644 --- a/solution/2300-2399/2394.Employees With Deductions/README_EN.md +++ b/solution/2300-2399/2394.Employees With Deductions/README_EN.md @@ -105,7 +105,7 @@ WITH T AS ( SELECT employee_id, - sum(ceiling(timestampdiff(second, in_time, out_time) / 60)) / 60 AS tot + SUM(ceiling(TIMESTAMPDIFF(second, in_time, out_time) / 60)) / 60 AS tot FROM Logs GROUP BY employee_id ) @@ -113,7 +113,7 @@ SELECT employee_id FROM Employees LEFT JOIN T USING (employee_id) -WHERE ifnull(tot, 0) < needed_hours; +WHERE IFNULL(tot, 0) < needed_hours; ``` diff --git a/solution/2300-2399/2394.Employees With Deductions/Solution.sql b/solution/2300-2399/2394.Employees With Deductions/Solution.sql index ff89d77bae569..c99762eb1896d 100644 --- a/solution/2300-2399/2394.Employees With Deductions/Solution.sql +++ b/solution/2300-2399/2394.Employees With Deductions/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT employee_id, - sum(ceiling(timestampdiff(second, in_time, out_time) / 60)) / 60 AS tot + SUM(ceiling(TIMESTAMPDIFF(second, in_time, out_time) / 60)) / 60 AS tot FROM Logs GROUP BY employee_id ) @@ -11,4 +11,4 @@ SELECT employee_id FROM Employees LEFT JOIN T USING (employee_id) -WHERE ifnull(tot, 0) < needed_hours; +WHERE IFNULL(tot, 0) < needed_hours; diff --git a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md index 6ea2f72cc94ec..62903cef9c3e3 100644 --- a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md +++ b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README.md @@ -97,17 +97,17 @@ FROM ( SELECT customer_id, - year(order_date), - sum(price) AS total, - year(order_date) - rank() OVER ( + YEAR(order_date), + SUM(price) AS total, + YEAR(order_date) - RANK() OVER ( PARTITION BY customer_id - ORDER BY sum(price) + ORDER BY SUM(price) ) AS rk FROM Orders - GROUP BY customer_id, year(order_date) + GROUP BY customer_id, YEAR(order_date) ) AS t GROUP BY customer_id -HAVING count(DISTINCT rk) = 1; +HAVING COUNT(DISTINCT rk) = 1; ``` diff --git a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md index 866ebce3b6603..0d65faf7d2612 100644 --- a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md +++ b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/README_EN.md @@ -92,17 +92,17 @@ FROM ( SELECT customer_id, - year(order_date), - sum(price) AS total, - year(order_date) - rank() OVER ( + YEAR(order_date), + SUM(price) AS total, + YEAR(order_date) - RANK() OVER ( PARTITION BY customer_id - ORDER BY sum(price) + ORDER BY SUM(price) ) AS rk FROM Orders - GROUP BY customer_id, year(order_date) + GROUP BY customer_id, YEAR(order_date) ) AS t GROUP BY customer_id -HAVING count(DISTINCT rk) = 1; +HAVING COUNT(DISTINCT rk) = 1; ``` diff --git a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/Solution.sql b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/Solution.sql index c42ecb713438b..d93894bbc58eb 100644 --- a/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/Solution.sql +++ b/solution/2400-2499/2474.Customers With Strictly Increasing Purchases/Solution.sql @@ -5,14 +5,14 @@ FROM ( SELECT customer_id, - year(order_date), - sum(price) AS total, - year(order_date) - rank() OVER ( + YEAR(order_date), + SUM(price) AS total, + YEAR(order_date) - RANK() OVER ( PARTITION BY customer_id - ORDER BY sum(price) + ORDER BY SUM(price) ) AS rk FROM Orders - GROUP BY customer_id, year(order_date) + GROUP BY customer_id, YEAR(order_date) ) AS t GROUP BY customer_id -HAVING count(DISTINCT rk) = 1; +HAVING COUNT(DISTINCT rk) = 1; diff --git a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md index d127148f6045d..ea4c54715ff54 100644 --- a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md +++ b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README.md @@ -80,7 +80,7 @@ WITH hall_id, start_day, end_day, - max(end_day) OVER ( + MAX(end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS cur_max_end_day @@ -89,8 +89,8 @@ WITH T AS ( SELECT *, - if( - start_day <= lag(cur_max_end_day) OVER ( + IF( + start_day <= LAG(cur_max_end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ), @@ -102,13 +102,13 @@ WITH P AS ( SELECT *, - sum(start) OVER ( + SUM(start) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS gid FROM T ) -SELECT hall_id, min(start_day) AS start_day, max(end_day) AS end_day +SELECT hall_id, MIN(start_day) AS start_day, MAX(end_day) AS end_day FROM P GROUP BY hall_id, gid; ``` diff --git a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md index 007700aac05e7..d714237e4e7d9 100644 --- a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md +++ b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/README_EN.md @@ -75,7 +75,7 @@ WITH hall_id, start_day, end_day, - max(end_day) OVER ( + MAX(end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS cur_max_end_day @@ -84,8 +84,8 @@ WITH T AS ( SELECT *, - if( - start_day <= lag(cur_max_end_day) OVER ( + IF( + start_day <= LAG(cur_max_end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ), @@ -97,13 +97,13 @@ WITH P AS ( SELECT *, - sum(start) OVER ( + SUM(start) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS gid FROM T ) -SELECT hall_id, min(start_day) AS start_day, max(end_day) AS end_day +SELECT hall_id, MIN(start_day) AS start_day, MAX(end_day) AS end_day FROM P GROUP BY hall_id, gid; ``` diff --git a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql index 80a88a12afc45..07b0b12257e32 100644 --- a/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql +++ b/solution/2400-2499/2494.Merge Overlapping Events in the Same Hall/Solution.sql @@ -5,7 +5,7 @@ WITH hall_id, start_day, end_day, - max(end_day) OVER ( + MAX(end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS cur_max_end_day @@ -14,8 +14,8 @@ WITH T AS ( SELECT *, - if( - start_day <= lag(cur_max_end_day) OVER ( + IF( + start_day <= LAG(cur_max_end_day) OVER ( PARTITION BY hall_id ORDER BY start_day ), @@ -27,12 +27,12 @@ WITH P AS ( SELECT *, - sum(start) OVER ( + SUM(start) OVER ( PARTITION BY hall_id ORDER BY start_day ) AS gid FROM T ) -SELECT hall_id, min(start_day) AS start_day, max(end_day) AS end_day +SELECT hall_id, MIN(start_day) AS start_day, MAX(end_day) AS end_day FROM P GROUP BY hall_id, gid; diff --git a/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md b/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md index 42bbc7bcadaed..ca3736d4d4dfe 100644 --- a/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md +++ b/solution/2500-2599/2504.Concatenate the Name and the Profession/README.md @@ -71,7 +71,7 @@ Person 表: ```sql # Write your MySQL query statement below -SELECT person_id, CONCAT(name, "(", substring(profession, 1, 1), ")") AS name +SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name FROM Person ORDER BY person_id DESC; ``` diff --git a/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md b/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md index b522abd4d3aa6..a15ee2f0e7fbf 100644 --- a/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md +++ b/solution/2500-2599/2504.Concatenate the Name and the Profession/README_EN.md @@ -65,7 +65,7 @@ Person table: ```sql # Write your MySQL query statement below -SELECT person_id, CONCAT(name, "(", substring(profession, 1, 1), ")") AS name +SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name FROM Person ORDER BY person_id DESC; ``` diff --git a/solution/2500-2599/2504.Concatenate the Name and the Profession/Solution.sql b/solution/2500-2599/2504.Concatenate the Name and the Profession/Solution.sql index b488d8db1d348..c793694654e43 100644 --- a/solution/2500-2599/2504.Concatenate the Name and the Profession/Solution.sql +++ b/solution/2500-2599/2504.Concatenate the Name and the Profession/Solution.sql @@ -1,4 +1,4 @@ # Write your MySQL query statement below -SELECT person_id, CONCAT(name, "(", substring(profession, 1, 1), ")") AS name +SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name FROM Person ORDER BY person_id DESC; diff --git a/solution/2600-2699/2668.Find Latest Salaries/README.md b/solution/2600-2699/2668.Find Latest Salaries/README.md index 461a6fd975d21..4f23dda117c38 100644 --- a/solution/2600-2699/2668.Find Latest Salaries/README.md +++ b/solution/2600-2699/2668.Find Latest Salaries/README.md @@ -85,7 +85,7 @@ SELECT emp_id, firstname, lastname, - max(salary) AS salary, + MAX(salary) AS salary, department_id FROM Salary GROUP BY emp_id diff --git a/solution/2600-2699/2668.Find Latest Salaries/README_EN.md b/solution/2600-2699/2668.Find Latest Salaries/README_EN.md index cbb99118c541d..12899562fdb29 100644 --- a/solution/2600-2699/2668.Find Latest Salaries/README_EN.md +++ b/solution/2600-2699/2668.Find Latest Salaries/README_EN.md @@ -79,7 +79,7 @@ SELECT emp_id, firstname, lastname, - max(salary) AS salary, + MAX(salary) AS salary, department_id FROM Salary GROUP BY emp_id diff --git a/solution/2600-2699/2668.Find Latest Salaries/Solution.sql b/solution/2600-2699/2668.Find Latest Salaries/Solution.sql index 646aaa7135f14..38d6513ac3ad0 100644 --- a/solution/2600-2699/2668.Find Latest Salaries/Solution.sql +++ b/solution/2600-2699/2668.Find Latest Salaries/Solution.sql @@ -3,7 +3,7 @@ SELECT emp_id, firstname, lastname, - max(salary) AS salary, + MAX(salary) AS salary, department_id FROM Salary GROUP BY emp_id diff --git a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md index 9defddba7a95f..dab3142e524d6 100644 --- a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md +++ b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README.md @@ -68,7 +68,7 @@ id 是该表的主键(具有唯一值的列)。 # Write your MySQL query statement below SELECT artist, - count(1) AS occurrences + COUNT(1) AS occurrences FROM Spotify GROUP BY artist ORDER BY occurrences DESC, artist; diff --git a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md index 6d75c632ce4b0..bb45673d76eb7 100644 --- a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md +++ b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/README_EN.md @@ -61,7 +61,7 @@ Each row contains an id, track_name, and artist. # Write your MySQL query statement below SELECT artist, - count(1) AS occurrences + COUNT(1) AS occurrences FROM Spotify GROUP BY artist ORDER BY occurrences DESC, artist; diff --git a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/Solution.sql b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/Solution.sql index d76a22fb8653c..27224347d8667 100644 --- a/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/Solution.sql +++ b/solution/2600-2699/2669.Count Artist Occurrences On Spotify Ranking List/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT artist, - count(1) AS occurrences + COUNT(1) AS occurrences FROM Spotify GROUP BY artist ORDER BY occurrences DESC, artist; diff --git a/solution/2600-2699/2686.Immediate Food Delivery III/README.md b/solution/2600-2699/2686.Immediate Food Delivery III/README.md index 8ee1fe0388ab7..e8e20a3417b84 100644 --- a/solution/2600-2699/2686.Immediate Food Delivery III/README.md +++ b/solution/2600-2699/2686.Immediate Food Delivery III/README.md @@ -81,7 +81,7 @@ order_dste 按升序排序。 ```sql # Write your MySQL query statement below SELECT order_date - ,round(100*SUM(IF(customer_pref_delivery_date = order_date,1,0))/COUNT(*),2) AS immediate_percentage + ,ROUND(100*SUM(IF(customer_pref_delivery_date = order_date,1,0))/COUNT(*),2) AS immediate_percentage FROM Delivery GROUP BY order_date ORDER BY order_date diff --git a/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md b/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md index 6827cace5702d..efcad4c20db53 100644 --- a/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md +++ b/solution/2600-2699/2686.Immediate Food Delivery III/README_EN.md @@ -73,7 +73,7 @@ order_date is sorted in ascending order. ```sql # Write your MySQL query statement below SELECT order_date - ,round(100*SUM(IF(customer_pref_delivery_date = order_date,1,0))/COUNT(*),2) AS immediate_percentage + ,ROUND(100*SUM(IF(customer_pref_delivery_date = order_date,1,0))/COUNT(*),2) AS immediate_percentage FROM Delivery GROUP BY order_date ORDER BY order_date diff --git a/solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql b/solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql index 5a8f4ce0f31f6..8b3f6f6522886 100644 --- a/solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql +++ b/solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql @@ -1,7 +1,7 @@ # Write your MySQL query statement below SELECT order_date, - round( + ROUND( 100 * SUM(IF(customer_pref_delivery_date = order_date, 1, 0)) / COUNT(*), 2 ) AS immediate_percentage diff --git a/solution/2600-2699/2688.Find Active Users/README.md b/solution/2600-2699/2688.Find Active Users/README.md index 2cdc3123ea6d3..07d931af63848 100644 --- a/solution/2600-2699/2688.Find Active Users/README.md +++ b/solution/2600-2699/2688.Find Active Users/README.md @@ -81,7 +81,7 @@ WHERE SELECT user_id, created_at, - lag(created_at, 1) OVER ( + LAG(created_at, 1) OVER ( PARTITION BY user_id ORDER BY created_at ) AS prev_created_at diff --git a/solution/2600-2699/2688.Find Active Users/README_EN.md b/solution/2600-2699/2688.Find Active Users/README_EN.md index 8dc232d18abe1..a4f61c5340f6d 100644 --- a/solution/2600-2699/2688.Find Active Users/README_EN.md +++ b/solution/2600-2699/2688.Find Active Users/README_EN.md @@ -76,7 +76,7 @@ WHERE SELECT user_id, created_at, - lag(created_at, 1) OVER ( + LAG(created_at, 1) OVER ( PARTITION BY user_id ORDER BY created_at ) AS prev_created_at diff --git a/solution/2600-2699/2688.Find Active Users/Solution.sql b/solution/2600-2699/2688.Find Active Users/Solution.sql index cf1fadba2336e..9d9d728856ebe 100644 --- a/solution/2600-2699/2688.Find Active Users/Solution.sql +++ b/solution/2600-2699/2688.Find Active Users/Solution.sql @@ -11,7 +11,7 @@ WHERE SELECT user_id, created_at, - lag(created_at, 1) OVER ( + LAG(created_at, 1) OVER ( PARTITION BY user_id ORDER BY created_at ) AS prev_created_at diff --git a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md index 9cba4bf9906c0..fd108e1305527 100644 --- a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md +++ b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README.md @@ -81,7 +81,7 @@ WITH T AS ( SELECT t1.*, - sum( + SUM( CASE WHEN t2.customer_id IS NULL THEN 1 ELSE 0 @@ -92,15 +92,15 @@ WITH LEFT JOIN Transactions AS t2 ON t1.customer_id = t2.customer_id AND t1.amount > t2.amount - AND datediff(t1.transaction_date, t2.transaction_date) = 1 + AND DATEDIFF(t1.transaction_date, t2.transaction_date) = 1 ) SELECT customer_id, - min(transaction_date) AS consecutive_start, - max(transaction_date) AS consecutive_end + MIN(transaction_date) AS consecutive_start, + MAX(transaction_date) AS consecutive_end FROM T GROUP BY customer_id, s -HAVING count(1) >= 3 +HAVING COUNT(1) >= 3 ORDER BY customer_id; ``` diff --git a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md index a02030facf2bd..d934e00e60ecb 100644 --- a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md +++ b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/README_EN.md @@ -77,7 +77,7 @@ WITH T AS ( SELECT t1.*, - sum( + SUM( CASE WHEN t2.customer_id IS NULL THEN 1 ELSE 0 @@ -88,15 +88,15 @@ WITH LEFT JOIN Transactions AS t2 ON t1.customer_id = t2.customer_id AND t1.amount > t2.amount - AND datediff(t1.transaction_date, t2.transaction_date) = 1 + AND DATEDIFF(t1.transaction_date, t2.transaction_date) = 1 ) SELECT customer_id, - min(transaction_date) AS consecutive_start, - max(transaction_date) AS consecutive_end + MIN(transaction_date) AS consecutive_start, + MAX(transaction_date) AS consecutive_end FROM T GROUP BY customer_id, s -HAVING count(1) >= 3 +HAVING COUNT(1) >= 3 ORDER BY customer_id; ``` diff --git a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/Solution.sql b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/Solution.sql index 7ae1c0406bbf1..c146d4ec8ec87 100644 --- a/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/Solution.sql +++ b/solution/2700-2799/2701.Consecutive Transactions with Increasing Amounts/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT t1.*, - sum( + SUM( CASE WHEN t2.customer_id IS NULL THEN 1 ELSE 0 @@ -14,13 +14,13 @@ WITH LEFT JOIN Transactions AS t2 ON t1.customer_id = t2.customer_id AND t1.amount > t2.amount - AND datediff(t1.transaction_date, t2.transaction_date) = 1 + AND DATEDIFF(t1.transaction_date, t2.transaction_date) = 1 ) SELECT customer_id, - min(transaction_date) AS consecutive_start, - max(transaction_date) AS consecutive_end + MIN(transaction_date) AS consecutive_start, + MAX(transaction_date) AS consecutive_end FROM T GROUP BY customer_id, s -HAVING count(1) >= 3 +HAVING COUNT(1) >= 3 ORDER BY customer_id; diff --git a/solution/2700-2799/2720.Popularity Percentage/README.md b/solution/2700-2799/2720.Popularity Percentage/README.md index a7c6a2f1baed0..c1d04961f4d8e 100644 --- a/solution/2700-2799/2720.Popularity Percentage/README.md +++ b/solution/2700-2799/2720.Popularity Percentage/README.md @@ -90,11 +90,11 @@ WITH UNION SELECT user2, user1 FROM Friends ), - T AS (SELECT count(DISTINCT user1) AS cnt FROM F) + T AS (SELECT COUNT(DISTINCT user1) AS cnt FROM F) SELECT DISTINCT user1, - round( - (count(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), + ROUND( + (COUNT(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), 2 ) AS percentage_popularity FROM F diff --git a/solution/2700-2799/2720.Popularity Percentage/README_EN.md b/solution/2700-2799/2720.Popularity Percentage/README_EN.md index 61688937ef06f..6899d5d412d79 100644 --- a/solution/2700-2799/2720.Popularity Percentage/README_EN.md +++ b/solution/2700-2799/2720.Popularity Percentage/README_EN.md @@ -84,11 +84,11 @@ WITH UNION SELECT user2, user1 FROM Friends ), - T AS (SELECT count(DISTINCT user1) AS cnt FROM F) + T AS (SELECT COUNT(DISTINCT user1) AS cnt FROM F) SELECT DISTINCT user1, - round( - (count(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), + ROUND( + (COUNT(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), 2 ) AS percentage_popularity FROM F diff --git a/solution/2700-2799/2720.Popularity Percentage/Solution.sql b/solution/2700-2799/2720.Popularity Percentage/Solution.sql index c783da4aefba4..aab115e32eab2 100644 --- a/solution/2700-2799/2720.Popularity Percentage/Solution.sql +++ b/solution/2700-2799/2720.Popularity Percentage/Solution.sql @@ -5,11 +5,11 @@ WITH UNION SELECT user2, user1 FROM Friends ), - T AS (SELECT count(DISTINCT user1) AS cnt FROM F) + T AS (SELECT COUNT(DISTINCT user1) AS cnt FROM F) SELECT DISTINCT user1, - round( - (count(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), + ROUND( + (COUNT(1) OVER (PARTITION BY user1)) * 100 / (SELECT cnt FROM T), 2 ) AS percentage_popularity FROM F diff --git a/solution/2700-2799/2738.Count Occurrences in Text/README.md b/solution/2700-2799/2738.Count Occurrences in Text/README.md index b89f28f80e2e6..fc0b2c77d7008 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/README.md +++ b/solution/2700-2799/2738.Count Occurrences in Text/README.md @@ -69,11 +69,11 @@ Files 表: ```sql # Write your MySQL query statement below -SELECT 'bull' AS word, count(*) AS count +SELECT 'bull' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bull %' UNION -SELECT 'bear' AS word, count(*) AS count +SELECT 'bear' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bear %'; ``` diff --git a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md index 8ffc51341502f..5ad4aa1fdeb11 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md +++ b/solution/2700-2799/2738.Count Occurrences in Text/README_EN.md @@ -62,11 +62,11 @@ Files table: ```sql # Write your MySQL query statement below -SELECT 'bull' AS word, count(*) AS count +SELECT 'bull' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bull %' UNION -SELECT 'bear' AS word, count(*) AS count +SELECT 'bear' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bear %'; ``` diff --git a/solution/2700-2799/2738.Count Occurrences in Text/Solution.sql b/solution/2700-2799/2738.Count Occurrences in Text/Solution.sql index fa6b24c6c7059..43ac3452e78d9 100644 --- a/solution/2700-2799/2738.Count Occurrences in Text/Solution.sql +++ b/solution/2700-2799/2738.Count Occurrences in Text/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below -SELECT 'bull' AS word, count(*) AS count +SELECT 'bull' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bull %' UNION -SELECT 'bear' AS word, count(*) AS count +SELECT 'bear' AS word, COUNT(*) AS count FROM Files WHERE content LIKE '% bear %'; diff --git a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md index bf8a54cc6f108..a5ed8aef3fdf8 100644 --- a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md +++ b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README.md @@ -76,9 +76,9 @@ WITH s AS ( SELECT customer_id, - date_sub( + DATE_SUB( transaction_date, - INTERVAL row_number() OVER ( + INTERVAL ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY transaction_date ) DAY @@ -86,13 +86,13 @@ WITH FROM Transactions ), t AS ( - SELECT customer_id, transaction_date, count(1) AS cnt + SELECT customer_id, transaction_date, COUNT(1) AS cnt FROM s GROUP BY 1, 2 ) SELECT customer_id FROM t -WHERE cnt = (SELECT max(cnt) FROM t) +WHERE cnt = (SELECT MAX(cnt) FROM t) ORDER BY customer_id; ``` diff --git a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md index d2ab16d2ccc2c..8ad3bedbc8658 100644 --- a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md +++ b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/README_EN.md @@ -70,9 +70,9 @@ WITH s AS ( SELECT customer_id, - date_sub( + DATE_SUB( transaction_date, - INTERVAL row_number() OVER ( + INTERVAL ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY transaction_date ) DAY @@ -80,13 +80,13 @@ WITH FROM Transactions ), t AS ( - SELECT customer_id, transaction_date, count(1) AS cnt + SELECT customer_id, transaction_date, COUNT(1) AS cnt FROM s GROUP BY 1, 2 ) SELECT customer_id FROM t -WHERE cnt = (SELECT max(cnt) FROM t) +WHERE cnt = (SELECT MAX(cnt) FROM t) ORDER BY customer_id; ``` diff --git a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql index f213a7dfb1845..8f5dcd3d7018f 100644 --- a/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql +++ b/solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql @@ -3,9 +3,9 @@ WITH s AS ( SELECT customer_id, - date_sub( + DATE_SUB( transaction_date, - INTERVAL row_number() OVER ( + INTERVAL ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY transaction_date ) DAY @@ -13,11 +13,11 @@ WITH FROM Transactions ), t AS ( - SELECT customer_id, transaction_date, count(1) AS cnt + SELECT customer_id, transaction_date, COUNT(1) AS cnt FROM s GROUP BY 1, 2 ) SELECT customer_id FROM t -WHERE cnt = (SELECT max(cnt) FROM t) +WHERE cnt = (SELECT MAX(cnt) FROM t) ORDER BY customer_id; diff --git a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md index 29be9268cc412..a49ad53704cf9 100644 --- a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md +++ b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README.md @@ -99,8 +99,8 @@ Passengers table: # Write your MySQL query statement below SELECT flight_id, - least(count(passenger_id), capacity) AS booked_cnt, - greatest(count(passenger_id) - capacity, 0) AS waitlist_cnt + LEAST(COUNT(passenger_id), capacity) AS booked_cnt, + GREATEST(COUNT(passenger_id) - capacity, 0) AS waitlist_cnt FROM Flights LEFT JOIN Passengers USING (flight_id) diff --git a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md index ba42e52c4befa..899804f853470 100644 --- a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md +++ b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/README_EN.md @@ -87,8 +87,8 @@ Passengers table: # Write your MySQL query statement below SELECT flight_id, - least(count(passenger_id), capacity) AS booked_cnt, - greatest(count(passenger_id) - capacity, 0) AS waitlist_cnt + LEAST(COUNT(passenger_id), capacity) AS booked_cnt, + GREATEST(COUNT(passenger_id) - capacity, 0) AS waitlist_cnt FROM Flights LEFT JOIN Passengers USING (flight_id) diff --git a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/Solution.sql b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/Solution.sql index b40447a211ec2..0cd61a149c52f 100644 --- a/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/Solution.sql +++ b/solution/2700-2799/2783.Flight Occupancy and Waitlist Analysis/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below SELECT flight_id, - least(count(passenger_id), capacity) AS booked_cnt, - greatest(count(passenger_id) - capacity, 0) AS waitlist_cnt + LEAST(COUNT(passenger_id), capacity) AS booked_cnt, + GREATEST(COUNT(passenger_id) - capacity, 0) AS waitlist_cnt FROM Flights LEFT JOIN Passengers USING (flight_id) diff --git a/solution/2700-2799/2793.Status of Flight Tickets/README.md b/solution/2700-2799/2793.Status of Flight Tickets/README.md index 28312b2e02a67..083a2813faec3 100644 --- a/solution/2700-2799/2793.Status of Flight Tickets/README.md +++ b/solution/2700-2799/2793.Status of Flight Tickets/README.md @@ -103,9 +103,9 @@ Passengers 表: # Write your MySQL query statement below SELECT passenger_id, - if( + IF( ( - rank() OVER ( + RANK() OVER ( PARTITION BY flight_id ORDER BY booking_time ) diff --git a/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md b/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md index 66ba7717460f2..8fedce491a3ff 100644 --- a/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md +++ b/solution/2700-2799/2793.Status of Flight Tickets/README_EN.md @@ -93,9 +93,9 @@ Passengers table: # Write your MySQL query statement below SELECT passenger_id, - if( + IF( ( - rank() OVER ( + RANK() OVER ( PARTITION BY flight_id ORDER BY booking_time ) diff --git a/solution/2700-2799/2793.Status of Flight Tickets/Solution.sql b/solution/2700-2799/2793.Status of Flight Tickets/Solution.sql index 987db9c9dd144..0bdfd461461be 100644 --- a/solution/2700-2799/2793.Status of Flight Tickets/Solution.sql +++ b/solution/2700-2799/2793.Status of Flight Tickets/Solution.sql @@ -1,9 +1,9 @@ # Write your MySQL query statement below SELECT passenger_id, - if( + IF( ( - rank() OVER ( + RANK() OVER ( PARTITION BY flight_id ORDER BY booking_time ) diff --git a/solution/2800-2899/2820.Election Results/README.md b/solution/2800-2899/2820.Election Results/README.md index 3c0615655972d..3252747fcd9eb 100644 --- a/solution/2800-2899/2820.Election Results/README.md +++ b/solution/2800-2899/2820.Election Results/README.md @@ -80,12 +80,12 @@ Votes table: # Write your MySQL query statement below WITH T AS ( - SELECT candidate, sum(vote) AS tot + SELECT candidate, SUM(vote) AS tot FROM ( SELECT candidate, - 1 / (count(candidate) OVER (PARTITION BY voter)) AS vote + 1 / (COUNT(candidate) OVER (PARTITION BY voter)) AS vote FROM Votes WHERE candidate IS NOT NULL ) AS t @@ -94,7 +94,7 @@ WITH P AS ( SELECT candidate, - rank() OVER (ORDER BY tot DESC) AS rk + RANK() OVER (ORDER BY tot DESC) AS rk FROM T ) SELECT candidate diff --git a/solution/2800-2899/2820.Election Results/README_EN.md b/solution/2800-2899/2820.Election Results/README_EN.md index 0b67b617f61f0..e19ce526ba91b 100644 --- a/solution/2800-2899/2820.Election Results/README_EN.md +++ b/solution/2800-2899/2820.Election Results/README_EN.md @@ -67,12 +67,12 @@ Since Ryan and Christine received an equal number of votes, we will display thei # Write your MySQL query statement below WITH T AS ( - SELECT candidate, sum(vote) AS tot + SELECT candidate, SUM(vote) AS tot FROM ( SELECT candidate, - 1 / (count(candidate) OVER (PARTITION BY voter)) AS vote + 1 / (COUNT(candidate) OVER (PARTITION BY voter)) AS vote FROM Votes WHERE candidate IS NOT NULL ) AS t @@ -81,7 +81,7 @@ WITH P AS ( SELECT candidate, - rank() OVER (ORDER BY tot DESC) AS rk + RANK() OVER (ORDER BY tot DESC) AS rk FROM T ) SELECT candidate diff --git a/solution/2800-2899/2820.Election Results/Solution.sql b/solution/2800-2899/2820.Election Results/Solution.sql index 94472ef7e693c..d36b4aad5f471 100644 --- a/solution/2800-2899/2820.Election Results/Solution.sql +++ b/solution/2800-2899/2820.Election Results/Solution.sql @@ -1,12 +1,12 @@ # Write your MySQL query statement below WITH T AS ( - SELECT candidate, sum(vote) AS tot + SELECT candidate, SUM(vote) AS tot FROM ( SELECT candidate, - 1 / (count(candidate) OVER (PARTITION BY voter)) AS vote + 1 / (COUNT(candidate) OVER (PARTITION BY voter)) AS vote FROM Votes WHERE candidate IS NOT NULL ) AS t @@ -15,7 +15,7 @@ WITH P AS ( SELECT candidate, - rank() OVER (ORDER BY tot DESC) AS rk + RANK() OVER (ORDER BY tot DESC) AS rk FROM T ) SELECT candidate diff --git a/solution/2800-2899/2837.Total Traveled Distance/README.md b/solution/2800-2899/2837.Total Traveled Distance/README.md index cd90e9e7a5685..8467aa8068c36 100644 --- a/solution/2800-2899/2837.Total Traveled Distance/README.md +++ b/solution/2800-2899/2837.Total Traveled Distance/README.md @@ -101,7 +101,7 @@ Rides table: ```sql # Write your MySQL query statement below -SELECT user_id, name, ifnull(sum(distance), 0) AS 'traveled distance' +SELECT user_id, name, IFNULL(SUM(distance), 0) AS 'traveled distance' FROM Users LEFT JOIN Rides USING (user_id) diff --git a/solution/2800-2899/2837.Total Traveled Distance/README_EN.md b/solution/2800-2899/2837.Total Traveled Distance/README_EN.md index 16d601c2337c5..4036f3eb2d987 100644 --- a/solution/2800-2899/2837.Total Traveled Distance/README_EN.md +++ b/solution/2800-2899/2837.Total Traveled Distance/README_EN.md @@ -90,7 +90,7 @@ Returning the table orderd by user_id in ascending order. ```sql # Write your MySQL query statement below -SELECT user_id, name, ifnull(sum(distance), 0) AS 'traveled distance' +SELECT user_id, name, IFNULL(SUM(distance), 0) AS 'traveled distance' FROM Users LEFT JOIN Rides USING (user_id) diff --git a/solution/2800-2899/2837.Total Traveled Distance/Solution.sql b/solution/2800-2899/2837.Total Traveled Distance/Solution.sql index 58a9c6dc3bf61..f6402b5c20111 100644 --- a/solution/2800-2899/2837.Total Traveled Distance/Solution.sql +++ b/solution/2800-2899/2837.Total Traveled Distance/Solution.sql @@ -1,5 +1,5 @@ # Write your MySQL query statement below -SELECT user_id, name, ifnull(sum(distance), 0) AS 'traveled distance' +SELECT user_id, name, IFNULL(SUM(distance), 0) AS 'traveled distance' FROM Users LEFT JOIN Rides USING (user_id) diff --git a/solution/2800-2899/2853.Highest Salaries Difference/README.md b/solution/2800-2899/2853.Highest Salaries Difference/README.md index 216f669437bc0..936fa83b3a421 100644 --- a/solution/2800-2899/2853.Highest Salaries Difference/README.md +++ b/solution/2800-2899/2853.Highest Salaries Difference/README.md @@ -73,10 +73,10 @@ Salaries table: ```sql # Write your MySQL query statement below -SELECT max(s) - min(s) AS salary_difference +SELECT MAX(s) - MIN(s) AS salary_difference FROM ( - SELECT max(salary) AS s + SELECT MAX(salary) AS s FROM Salaries GROUP BY department ) AS t; diff --git a/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md b/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md index 023abb05df91a..9178821ea9dc1 100644 --- a/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md +++ b/solution/2800-2899/2853.Highest Salaries Difference/README_EN.md @@ -62,10 +62,10 @@ Salaries table: ```sql # Write your MySQL query statement below -SELECT max(s) - min(s) AS salary_difference +SELECT MAX(s) - MIN(s) AS salary_difference FROM ( - SELECT max(salary) AS s + SELECT MAX(salary) AS s FROM Salaries GROUP BY department ) AS t; diff --git a/solution/2800-2899/2853.Highest Salaries Difference/Solution.sql b/solution/2800-2899/2853.Highest Salaries Difference/Solution.sql index a2435ae4b8da6..5733804848b00 100644 --- a/solution/2800-2899/2853.Highest Salaries Difference/Solution.sql +++ b/solution/2800-2899/2853.Highest Salaries Difference/Solution.sql @@ -1,8 +1,8 @@ # Write your MySQL query statement below -SELECT max(s) - min(s) AS salary_difference +SELECT MAX(s) - MIN(s) AS salary_difference FROM ( - SELECT max(salary) AS s + SELECT MAX(salary) AS s FROM Salaries GROUP BY department ) AS t; diff --git a/solution/2800-2899/2854.Rolling Average Steps/README.md b/solution/2800-2899/2854.Rolling Average Steps/README.md index 6c7a0d0e815ff..0583150d28f86 100644 --- a/solution/2800-2899/2854.Rolling Average Steps/README.md +++ b/solution/2800-2899/2854.Rolling Average Steps/README.md @@ -101,17 +101,17 @@ WITH SELECT user_id, steps_date, - round( - avg(steps_count) OVER ( + ROUND( + AVG(steps_count) OVER ( PARTITION BY user_id ORDER BY steps_date ROWS 2 PRECEDING ), 2 ) AS rolling_average, - datediff( + DATEDIFF( steps_date, - lag(steps_date, 2) OVER ( + LAG(steps_date, 2) OVER ( PARTITION BY user_id ORDER BY steps_date ) diff --git a/solution/2800-2899/2854.Rolling Average Steps/README_EN.md b/solution/2800-2899/2854.Rolling Average Steps/README_EN.md index 4b14d8cd143f3..21489b0853265 100644 --- a/solution/2800-2899/2854.Rolling Average Steps/README_EN.md +++ b/solution/2800-2899/2854.Rolling Average Steps/README_EN.md @@ -90,17 +90,17 @@ WITH SELECT user_id, steps_date, - round( - avg(steps_count) OVER ( + ROUND( + AVG(steps_count) OVER ( PARTITION BY user_id ORDER BY steps_date ROWS 2 PRECEDING ), 2 ) AS rolling_average, - datediff( + DATEDIFF( steps_date, - lag(steps_date, 2) OVER ( + LAG(steps_date, 2) OVER ( PARTITION BY user_id ORDER BY steps_date ) diff --git a/solution/2800-2899/2854.Rolling Average Steps/Solution.sql b/solution/2800-2899/2854.Rolling Average Steps/Solution.sql index 973cf3a9f3dd5..b149fd10acbb3 100644 --- a/solution/2800-2899/2854.Rolling Average Steps/Solution.sql +++ b/solution/2800-2899/2854.Rolling Average Steps/Solution.sql @@ -4,17 +4,17 @@ WITH SELECT user_id, steps_date, - round( - avg(steps_count) OVER ( + ROUND( + AVG(steps_count) OVER ( PARTITION BY user_id ORDER BY steps_date ROWS 2 PRECEDING ), 2 ) AS rolling_average, - datediff( + DATEDIFF( steps_date, - lag(steps_date, 2) OVER ( + LAG(steps_date, 2) OVER ( PARTITION BY user_id ORDER BY steps_date ) diff --git a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md index 4af14e1306a29..78e2a5e085a3f 100644 --- a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md +++ b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README.md @@ -83,7 +83,7 @@ WITH T AS ( SELECT minute, - sum(order_count) OVER ( + SUM(order_count) OVER ( ORDER BY minute ROWS 5 PRECEDING ) AS total_orders diff --git a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md index f4203c968815a..c92349c5b8ee2 100644 --- a/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md +++ b/solution/2800-2899/2893.Calculate Orders Within Each Interval/README_EN.md @@ -73,7 +73,7 @@ WITH T AS ( SELECT minute, - sum(order_count) OVER ( + SUM(order_count) OVER ( ORDER BY minute ROWS 5 PRECEDING ) AS total_orders diff --git a/solution/2800-2899/2893.Calculate Orders Within Each Interval/Solution.sql b/solution/2800-2899/2893.Calculate Orders Within Each Interval/Solution.sql index f096d55a95dc5..06975be2cdf98 100644 --- a/solution/2800-2899/2893.Calculate Orders Within Each Interval/Solution.sql +++ b/solution/2800-2899/2893.Calculate Orders Within Each Interval/Solution.sql @@ -3,7 +3,7 @@ WITH T AS ( SELECT minute, - sum(order_count) OVER ( + SUM(order_count) OVER ( ORDER BY minute ROWS 5 PRECEDING ) AS total_orders