From 490aed47740135d90c48383b3fa92cca04c1adf9 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Thu, 12 May 2022 19:05:39 +0800 Subject: [PATCH] add pre commit hook --- .pre-commit-config.yaml | 6 + .../1.HelloWorld/config.json" | 10 -- .../1.HelloWorld/helloworld.json" | 7 -- .../1.HelloWorld/helloworld.md" | 21 ---- .../config.json" | 20 ++++ .../relation.json" | 7 ++ .../relation.md" | 29 +++++ .../client.json" | 7 ++ .../client.md" | 30 +++++ .../config.json" | 19 ++++ .../server.json" | 7 ++ .../server.md" | 30 +++++ .../config.json" | 2 +- .../1.\345\256\211\350\243\205/config.json" | 15 +++ .../1.\345\256\211\350\243\205/install.json" | 7 ++ .../1.\345\256\211\350\243\205/install.md" | 30 +++++ .../2.\347\231\273\345\275\225/config.json" | 17 +++ .../2.\347\231\273\345\275\225/login.json" | 7 ++ .../2.\347\231\273\345\275\225/login.md" | 60 ++++++++++ .../2.\347\231\273\345\275\225/rds.json" | 7 ++ .../2.\347\231\273\345\275\225/rds.md" | 43 +++++++ .../3.\344\275\277\347\224\250/config.json" | 17 +++ .../3.\344\275\277\347\224\250/develop.json" | 7 ++ .../3.\344\275\277\347\224\250/develop.md" | 42 +++++++ .../config.json" | 6 + .../1.psql/config.json" | 16 +++ .../1.psql/psql.json" | 7 ++ .../1.psql/psql.md" | 50 ++++++++ .../basic.json" | 7 ++ .../basic.md" | 43 +++++++ .../config.json" | 16 +++ .../concept.json" | 7 ++ .../concept.md" | 31 +++++ .../config.json" | 24 ++++ .../delete.json" | 7 ++ .../delete.md" | 89 +++++++++++++++ .../insert.json" | 7 ++ .../insert.md" | 55 +++++++++ .../update.json" | 7 ++ .../update.md" | 49 ++++++++ .../config.json" | 6 + .../1.\350\241\250/config.json" | 18 +++ .../1.\350\241\250/create_table.json" | 7 ++ .../1.\350\241\250/create_table.md" | 46 ++++++++ .../1.\350\241\250/serial.json" | 7 ++ .../1.\350\241\250/serial.md" | 25 ++++ .../1.\350\241\250/table.json" | 7 ++ .../1.\350\241\250/table.md" | 26 +++++ .../2.\345\207\275\346\225\260/config.json" | 16 +++ .../2.\345\207\275\346\225\260/function.json" | 7 ++ .../2.\345\207\275\346\225\260/function.md" | 29 +++++ .../config.json" | 28 +++++ .../grant.json" | 7 ++ .../grant.md" | 41 +++++++ .../revoke.json" | 7 ++ .../revoke.md" | 32 ++++++ .../role.json" | 7 ++ .../role.md" | 36 ++++++ .../config.json" | 22 ++++ .../primary_key.json" | 7 ++ .../primary_key.md" | 30 +++++ .../unique.json" | 7 ++ .../unique.md" | 42 +++++++ .../unique_2.json" | 7 ++ .../unique_2.md" | 46 ++++++++ .../config.json" | 16 +++ .../trigger.json" | 7 ++ .../trigger.md" | 39 +++++++ .../config.json" | 18 +++ .../extension.json" | 7 ++ .../extension.md" | 33 ++++++ .../language.json" | 7 ++ .../language.md" | 25 ++++ .../config.json" | 6 + .../config.json" | 17 +++ .../salary.json" | 7 ++ .../salary.md" | 63 +++++++++++ .../config.json" | 16 +++ .../customer_order.json" | 7 ++ .../customer_order.md" | 52 +++++++++ .../config.json" | 16 +++ .../subquery.json" | 7 ++ .../subquery.md" | 58 ++++++++++ .../config.json" | 18 +++ .../paged.json" | 7 ++ .../paged.md" | 53 +++++++++ .../5.CTE/config.json" | 16 +++ .../5.CTE/to_root.json" | 7 ++ .../5.CTE/to_root.md" | 67 +++++++++++ .../config.json" | 15 +++ .../loop.json" | 7 ++ .../loop.md" | 80 +++++++++++++ .../7.DDL/analyze.json" | 7 ++ .../7.DDL/analyze.md" | 38 +++++++ .../7.DDL/config.json" | 19 ++++ .../7.DDL/create_table.json" | 7 ++ .../7.DDL/create_table.md" | 29 +++++ .../config.json" | 6 + .../1.standby/backup.json" | 7 ++ .../1.standby/backup.md" | 41 +++++++ .../1.standby/config.json" | 18 +++ .../1.standby/standby.json" | 7 ++ .../1.standby/standby.md" | 33 ++++++ .../config.json" | 18 +++ .../stream.json" | 7 ++ .../stream.md" | 38 +++++++ .../3.fdw/config.json" | 16 +++ .../3.fdw/fdw.json" | 7 ++ .../3.fdw/fdw.md" | 28 +++++ .../config.json" | 6 + .../config.json" | 16 +++ .../gis.json" | 7 ++ .../gis.md" | 66 +++++++++++ .../2.JSON\345\222\214JSONB/config.json" | 18 +++ .../2.JSON\345\222\214JSONB/json.json" | 7 ++ .../2.JSON\345\222\214JSONB/json.md" | 31 +++++ .../2.JSON\345\222\214JSONB/match.json" | 7 ++ .../2.JSON\345\222\214JSONB/match.md" | 56 +++++++++ .../2.JSON\345\222\214JSONB/tags.json" | 7 ++ .../2.JSON\345\222\214JSONB/tags.md" | 46 ++++++++ .../3.\345\207\275\346\225\260/config.json" | 23 ++++ .../3.\345\207\275\346\225\260/distinct.json" | 7 ++ .../3.\345\207\275\346\225\260/distinct.md" | 51 +++++++++ .../4.\350\247\206\345\233\276/config.json" | 16 +++ .../4.\350\247\206\345\233\276/view.json" | 7 ++ .../4.\350\247\206\345\233\276/view.md" | 30 +++++ .../config.json" | 6 + .../config.json" | 18 +++ .../continuous.json" | 7 ++ .../continuous.md" | 69 +++++++++++ .../2.Window Function/config.json" | 17 +++ .../2.Window Function/salary.json" | 7 ++ .../2.Window Function/salary.md" | 74 ++++++++++++ .../config.json" | 18 +++ .../pivot.json" | 7 ++ .../pivot.md" | 90 +++++++++++++++ .../config.json" | 17 +++ .../score.json" | 7 ++ .../score.md" | 50 ++++++++ .../5.\344\272\213\345\212\241/config.json" | 16 +++ .../transaction.json" | 7 ++ .../transaction.md" | 48 ++++++++ .../config.json" | 21 ++++ .../daily_payment.json" | 7 ++ .../daily_payment.md" | 80 +++++++++++++ .../daily_payment_2.json" | 7 ++ .../daily_payment_2.md" | 107 ++++++++++++++++++ .../config.json" | 6 + .../.gitkeep" | 0 .../config.json" | 14 +++ .../qa.json" | 9 ++ .../qa.md" | 42 +++++++ .../config.json" | 6 + 153 files changed, 3497 insertions(+), 39 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/config.json" delete mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.json" delete mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.md" rename "data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/config.json" => "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/config.json" (54%) create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/config.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.json" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.md" create mode 100644 "data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/config.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.json" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.md" create mode 100644 "data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/.gitkeep" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/config.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.json" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.md" create mode 100644 "data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/config.json" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..503b3fa --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: + - repo: git@codechina.csdn.net:csdn/skill_tree_hook.git + rev: 8cb76ab3b493582d3dab0021fb6fddfa28ec5a66 + hooks: + - id: pre-commit + verbose: true \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/config.json" "b/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/config.json" deleted file mode 100644 index b0dd4e9..0000000 --- "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/config.json" +++ /dev/null @@ -1,10 +0,0 @@ -{ - "node_id": "mysql-96403217971e4115835e31bba9366fcb", - "keywords": [], - "children": [], - "export": [ - "helloworld.json" - ], - "keywords_must": [], - "keywords_forbid": [] -} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.json" "b/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.json" deleted file mode 100644 index f6b9daa..0000000 --- "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "author": null, - "source": "helloworld.md", - "notebook_enable": false, - "exercise_id": "c58c8c60118e4603b5255168de60d79e" -} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.md" "b/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.md" deleted file mode 100644 index a447c18..0000000 --- "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/1.HelloWorld/helloworld.md" +++ /dev/null @@ -1,21 +0,0 @@ -# {在此填写标题} - -{在此填写题目描述} - -## 答案 - -{在此填写答案} - -## 选项 - -### A - -{在此填写选项A} - -### B - -{在此填写选项B} - -### C - -{在此填写选项C} diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/config.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/config.json" new file mode 100644 index 0000000..91e9d01 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/config.json" @@ -0,0 +1,20 @@ +{ + "node_id": "", + "keywords": [ + "关系型数据库", + "database", + "relational", + "rdbms" + ], + "children": [], + "export": [ + "relation.json" + ], + "keywords_must": [ + "关系型数据库", + "database", + "relational", + "rdbms" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.json" new file mode 100644 index 0000000..c596dd1 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "relation.md", + "notebook_enable": false, + "exercise_id": "e50c1cee116d4054b9794c57effa9f5a" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.md" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.md" new file mode 100644 index 0000000..741ecbe --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/1.\345\205\263\347\263\273\345\236\213\346\225\260\346\215\256\345\272\223/relation.md" @@ -0,0 +1,29 @@ +# 关系型数据库 + +下列数据库产品中,哪一个通常不被视作关系型数据库? + +## 答案 + +redis + +## 选项 + +### A + +PostgreSQL + +### B + +SQL Server + +### C + +Oracle + +### D + +H2 + +### E + +MySQL \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.json" new file mode 100644 index 0000000..5093846 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "client.md", + "notebook_enable": false, + "exercise_id": "88b033cd97c642ef9900e5e091e335ff" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.md" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.md" new file mode 100644 index 0000000..7ac3208 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/client.md" @@ -0,0 +1,30 @@ +# 连接 PostgreSQL 数据库 + +下列选项中,可以用于连接到PostgreSQL数据库的有: + +## 答案 + +全部都可以 + +## 选项 + +### A + +命令行工具 psql + +### B + +GUI 工具 PgAdmin + +### C + +JDBC 库 `org.postgresql:postgresql` + +### D + +Python DBAPI 实现 psycopg2 + +### E + +Go 语言驱动库 PQ。 + diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/config.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/config.json" new file mode 100644 index 0000000..ca81114 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/config.json" @@ -0,0 +1,19 @@ +{ + "node_id": "", + "keywords": [ + "server", + "client", + "数据库服务器", + "数据库客户端" + ], + "children": [], + "export": [ + "client.json", + "server.json" + ], + "keywords_must": [ + "服务器", + "客户端" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" new file mode 100644 index 0000000..cda5b39 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "server.md", + "notebook_enable": false, + "exercise_id": "55868ca50313434d855bbc1e997cf61b" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.md" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.md" new file mode 100644 index 0000000..0214e44 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/2.\346\234\215\345\212\241\345\231\250\345\222\214\345\256\242\346\210\267\347\253\257/server.md" @@ -0,0 +1,30 @@ +# PostgreSQL 服务器 + +关于 PostgreSQL 服务器,以下说法错误的是: + +## 答案 + +PostgreSQL 的服务器和客户端必须运行在不同的计算机上。 + +## 选项 + +### A + +PostgreSQL 的每个活跃连接对应一个 worker 进程。 + +### B + +PostgreSQL 的服务器将数据存储在一个 owner 为 postgres 的目录下。 + +### C + +PostgreSQL 可以设置监听端口、地址和最大连接数 + +### D + +PostgreSQL 的超级用户默认为 postgres + +### E + +PostgreSQL 可以运行在 FreeBSD、Linux或Windows系统。 + diff --git "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/config.json" "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/config.json" similarity index 54% rename from "data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/config.json" rename to "data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/config.json" index 1498d31..b89e9d8 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/1.MySQL\345\205\245\351\227\250/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/1.\345\237\272\346\234\254\346\246\202\345\277\265/config.json" @@ -1,5 +1,5 @@ { - "node_id": "mysql-2cd5f68281704161820ee048e1f9de36", + "node_id": "", "keywords": [], "keywords_must": [], "keywords_forbid": [] diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/config.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/config.json" new file mode 100644 index 0000000..53ac7a9 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/config.json" @@ -0,0 +1,15 @@ +{ + "node_id": "", + "keywords": [ + "安装", + "PostgreSQL" + ], + "children": [], + "export": [ + "install.json" + ], + "keywords_must": [ + "安装" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.json" new file mode 100644 index 0000000..25e3ff0 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "install.md", + "notebook_enable": false, + "exercise_id": "ca4669e5d66944df830390aec841cc7b" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.md" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.md" new file mode 100644 index 0000000..9fcbd28 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/1.\345\256\211\350\243\205/install.md" @@ -0,0 +1,30 @@ +# 安装 + +下列内容,不正确的是哪一项? + +## 答案 + +安装过程需要 root 权限,也应该将 root 设置为超级用户。 + +## 选项 + +### A + +在 Linux 上,可以用发行版自带的软件安装服务安装,用 systemctl 管理。 + +### B + +在 FreeBSD 上,可以用 ports 安装。 + +### C + +在 windows 上,可以下载安装包进行安装。 + +### D + +PostgreSQL 默认的超级用户名为 postgres 。 + +### E + +修改 postgres.conf 配置文件,可以修改 PG 的监听地址和端口。 + diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/config.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/config.json" new file mode 100644 index 0000000..dcd1847 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/config.json" @@ -0,0 +1,17 @@ +{ + "node_id": "", + "keywords": [ + "登录", + "身份验证", + "授权" + ], + "children": [], + "export": [ + "login.json", + "rds.json" + ], + "keywords_must": [ + "登录" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.json" new file mode 100644 index 0000000..1bafe5c --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "login.md", + "notebook_enable": false, + "exercise_id": "54917a4c69af41749d1c2a4430267f27" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.md" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.md" new file mode 100644 index 0000000..038122f --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/login.md" @@ -0,0 +1,60 @@ +# 登录 + +你的团队有一个公用的开发服务器,你要安装一个 PostgreSQL 服务公用,你们希望每位同事 +使用一个独立的开发数据库,不互相混淆。同时这个服务器不向其他部门开放。数据也希望有足 +够的安全保障。你的同事们都有这台开发服务器的 ssh 账号,平时远程登录到服务器上工作。 +下面哪个组合最符合你们的需求? + +1. 为每位同事建立一个数据库账号 +2. 初始化口令为123456,告知他们登录后修改密码。 +3. 为每位同事建立对应的开发数据库,将他们的用户设置为该数据库的 owner +4. 将每位同事的用户身份都设置为superuser,并禁止他们登录别人的数据库 +5. 为每位同事建立一个与操作系统账号同名的数据库账号 +6. 修改 pg_hba.conf ,设置本地用户可以用操作系统集成登录 +7. 设置 postgres 账号口令为 123456,群发告知同事 + +## 答案 + +``` +5, 3, 6 +``` + +## 选项 + + +### A + +``` +1, 2, 4 +``` + +### B + +``` +1, 2, 4, 6 +``` + +### C + +``` +5, 2, 4 +``` + +### D + +``` +5, 2, 4, 6 +``` + + +### E + +``` +7, 6 +``` + +### F + +``` +2, 3, 4, 5, 6, 7 +``` \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.json" new file mode 100644 index 0000000..7616405 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "rds.md", + "notebook_enable": false, + "exercise_id": "6b04760cd212469c925eb4a9c4a66757" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.md" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.md" new file mode 100644 index 0000000..6cff8a1 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/2.\347\231\273\345\275\225/rds.md" @@ -0,0 +1,43 @@ +# RDS 管理 + +RShop 公司在云服务商处购买了一个 PostgreSQL RDS 服务,作为 DBA ,你会采取哪些措施来管理它? + +1. 将云服务商提供的用户名口令交付开发团队 +2. 要求开发团队交付数据库部署脚本 +3. 部署并初始化数据库结构 +4. 建立应用用户,采用口令登录,仅赋予数据查询和 DML 权限 +5. 将应用用户的连接方式写入配置中心,供应用系统访问 +6. 待开发团队初始化数据库后,修改用户名口令 +7. 修改用户名口令后,将系统用户和口令保存在可信的存储中 + +## 答案 + +``` +2, 3, 4, 5, 7 +``` + +## 选项 + +### A + +``` +1, 3, 6, 4, 5, 7 +``` + +### B + +``` +1, 3 +``` + +### C + +``` +2, 4, 6 +``` + +### D + +``` +1, 3, 5, 7 +``` \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/config.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/config.json" new file mode 100644 index 0000000..e324932 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/config.json" @@ -0,0 +1,17 @@ +{ + "node_id": "", + "keywords": [ + "login", + "connect" + ], + "children": [], + "export": [ + "develop.json" + ], + "keywords_must": [ + "使用", + "基本用法", + "入门" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.json" new file mode 100644 index 0000000..f178339 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "develop.md", + "notebook_enable": false, + "exercise_id": "257414ca11f24a35a6270166b6bd2830" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.md" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.md" new file mode 100644 index 0000000..d094114 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/3.\344\275\277\347\224\250/develop.md" @@ -0,0 +1,42 @@ +# 开发环境中的 PostgreSQL + +你是 SmartMarket 公司的一名开发人员,公司使用 Linux 运行 PostgreSQL 服务,而你的开发机使用 MacOS。下列说法正确的是: + +1. 在 MacOS 上,使用 Homebrew 安装 PostgreSQL 后,在当前用户下执行 psql postgres 可以登入数据库 +2. 在 Linux 上,使用 yum 或 apt 安装 PostgreSQL 后,sudo su postgres 切换到 postgres 用户,可以执行 psql 登入数据库 +3. 对于自己安装的数据库服务器(非RDS),如果需要开放远程登录,需要编辑数据目录下的 postgresql.conf 和 pg_hua.conf +4. 安装 PostgreSQL 前,需要重装系统以获得一个干净的内核环境 +5. 安装 PostgreSQL 前,需要手工建立一个名为 postgres 的超级用户 +6. 安装 PostgreSQL 需要先安装 gcc 或 llvm clang +7. 对于使用 linux 的开发者,通常需要安装 postgresql 的开发包,这通常可以在主流的 linux 发行版的软件服务中找到,一般叫 postgresql-devel 或 postgresql-dev + +## 答案 + +1, 2, 3, 7 + +## 选项 + +### A + +1, 2, 3, 4, 5, 6, 7 + +### B + +1, 2, 3 + +### C + +2, 3, 4, 5 + +### D + +5, 6, 7 + +### E + +1, 3, 5, 7 + +### F + +2, 4, 6 + diff --git "a/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/config.json" "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/2.\345\256\211\350\243\205\345\222\214\344\275\277\347\224\250/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/config.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/config.json" new file mode 100644 index 0000000..a1ac975 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "sql", + "psql", + " 数据库客户端" + ], + "children": [], + "export": [ + "psql.json" + ], + "keywords_must": [ + "psql" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.json" new file mode 100644 index 0000000..895882b --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "psql.md", + "notebook_enable": false, + "exercise_id": "47faab6fba92431da6cbb2dacbf5bae4" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.md" new file mode 100644 index 0000000..1945295 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/1.psql/psql.md" @@ -0,0 +1,50 @@ +# PSQL 命令行 + +关于 PSQL 命令行,以下说法正确的是: + +1. psql 命令行内置在 postgresql 安装包中 +2. psql 命令行默认以系统当前用户身份登录本机,连接用户同名数据库 +3. 进入 psql 命令行,可以使用 `\?` 查看内置的快捷指令 +4. 在 psql 命令行中,可以通过 `\!` 在服务端执行shell命令 +5. psql 命令行必须以 postgres 用户身份执行 +6. psql 命令行必须以 root 用户身份执行 +7. psql 只能用于 linux 和 bsd 系统 +8. 在 psql 中执行 `\d` 可以查看 relations 列表,即用户表和视图 +9. 在 psql 中执行 `\l` 可以查看数据库列表 +10. 在 psql 中执行 `\d 表名` 可以查看指定表或视图的详细信息 +11. 在 psql 中执行 `\timing` 可以开关查询计时 +12. `analyze 表名;` 和 `explain 查询;` 以及 `explain analyze 查询;` 都是 psql 特有的命令 + +## 答案 + +1, 2, 3, 4, 8, 9, 10, 11 + +## 选项 + +### A + +全部都对 + +### B + +1, 2, 3, 4, 5, 6 + +### C + +2, 3, 4, 5, 6, 7, 8, 9 + +### D + +全部都错 + +### E + +9, 10, 11, 12 + +### F + +5, 6, 7, 8, 9, 10, 11, 12 + +### G + +5, 6, 7, 12 \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" new file mode 100644 index 0000000..14648d8 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "basic.md", + "notebook_enable": false, + "exercise_id": "76fffa1781f140fd9abee9231a7186f4" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" new file mode 100644 index 0000000..9d3b09c --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/basic.md" @@ -0,0 +1,43 @@ +# 基本语法 + +下列 SQL 语句,哪一项不合法? + +## 答案 + +```postgresql +from test select abc; +``` + +## 选项 + + +### A + +```postgresql +select 3.14; +``` + +### B + +```postgresql +select * from employee; +``` + +### C + +```postgresql +select * from employee where dept = 'hr'; +``` + +### D + +```postgresql +select id, name, dept, salary from employee where salary > 10000::money; +``` + +### E + +```postgresql +select now(); +``` + diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" new file mode 100644 index 0000000..ed920b1 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/2.SQL\345\237\272\346\234\254\350\257\255\346\263\225/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "语法", + "select" + ], + "children": [], + "export": [ + "basic.json" + ], + "keywords_must": [ + "语法", + "SQL" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.json" new file mode 100644 index 0000000..0cf5ed2 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "concept.md", + "notebook_enable": false, + "exercise_id": "ce2be9e86c6643a8a545115ae70ee8c1" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.md" new file mode 100644 index 0000000..66f30a9 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/concept.md" @@ -0,0 +1,31 @@ +# 基本概念 + +下列叙述中,正确的是 + +1. 带有 select 关键字的查询不会修改数据 +2. 查询表需要 select 权限 +3. 修改一个数据库表或对象的结构,通常语句中会出现 create、add、drop、alter 等关键字 +4. 修改数据内容,通常会出现update、insert、delete等关键字 +5. update、insert、delete可以单独授权 + +## 答案 + +2, 3, 4, 5 + +## 选项 + +### A + +1, 2, 3, 4, 5 + +### B + +4, 5 + +### C + +1, 2, 3 + +### D + +3, 4, 5 \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/config.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/config.json" new file mode 100644 index 0000000..acd89ef --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/config.json" @@ -0,0 +1,24 @@ +{ + "node_id": "", + "keywords": [ + "DML", + "insert", + "update", + "delete" + ], + "children": [], + "export": [ + "insert.json", + "update.json", + "delete.json", + "concept.json" + ], + "keywords_must": [ + "DML", + "DDL", + "insert", + "update", + "delete" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.json" new file mode 100644 index 0000000..29c89c8 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "delete.md", + "notebook_enable": false, + "exercise_id": "78e6ca15ba794ef3b2092de4640308b9" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.md" new file mode 100644 index 0000000..57f50db --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/delete.md" @@ -0,0 +1,89 @@ +# 删除 + +SmartMarket 公司的业务数据库中,有一个 orders 表,其结构主要是以下形态: + +```postgresql +create table orders +( + id serial primary key, + meta jsonb default '{}'::jsonb, + content jsonb default '{}'::jsonb, + created_at timestamp default now(), + deal boolean +) +``` + +有一个业务系统会实时的将已经成交(deal 字段为 true)的订单数据转储,现在我们仅需要一个清理 程序,将已经成 交的数据从 orders 表删除并记录被删除的数据id。下面哪个操作是对的? + +## 答案 + +在一个独立的定时任务中执行 + +```postgresql +delete +from orders +where deal +returning id; +``` + +并记录id + +## 选项 + +### A + +在一个独立的定时任务中执行 + +```postgresql +truncate orders; +``` + +### B + +在一个独立的定时任务中执行 + +```postgresql +delete +from orders; +``` + +### C + +在一个独立的定时任务中执行 + +```postgresql +drop table orders; +create table orders +( + id serial primary key, + meta jsonb default '{}'::jsonb, + content jsonb default '{}'::jsonb, + created_at timestamp default now(), + deal boolean +); +``` + +### D + +建立视图 + +```postgresql +create view order_view as +select id, meta, content, created_at +from orders +where not deal; +``` + +并要求业务系统只能访问这个视图。 + +### E + +在一个独立的定时任务中执行 + +```postgresql +delete +from orders +where deal; +``` + +并记录操作前后表中的最大 id \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.json" new file mode 100644 index 0000000..88d3791 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "insert.md", + "notebook_enable": false, + "exercise_id": "2d562e3ae4a84e648de31452a67ba71f" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.md" new file mode 100644 index 0000000..60ea20f --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/insert.md" @@ -0,0 +1,55 @@ +# 插入 + +现有一个表: + +```postgresql +create table book( + id serial primary key , + title text not null , + meta jsonb default '{}'::jsonb, + price money, + isbn text not null , + publish_at date not null +); +create unique index on book(isbn); +create index on book using gin(meta); +``` + +那么下列哪个选项的代码可以执行成功? + +## 答案 + +```postgresql +insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; +insert into book(title, price, isbn, publish_at) select 'a other book title', 25.4, 'yy-yyyy-xxxx', '2019-12-1'::date; +``` + +## 选项 + +### 唯一键冲突 + +```postgresql +insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; +insert into book(title, price, isbn, publish_at) select 'a other book title', 35.4, 'xx-xxxx-xxxx', '2019-12-1'::date; +``` + +### 缺少必要的列 + +```postgresql +insert into book(price, isbn, publish_at) select 25.4, 'xx-xxxx-xxxx', '2019-12-1'::date; +insert into book(price, isbn, publish_at) select 35.4, 'yy-yyyy-xxxx', '2019-12-1'::date; +``` + +### 类型错误 + +```postgresql +insert into book(title, price, isbn, publish_at) select 'a book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; +insert into book(title, price, isbn, publish_at) select 'a other book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; +``` + +### 违反非空约束 + +```postgresql +insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; +insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'::date; +``` diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.json" new file mode 100644 index 0000000..41b52ea --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "update.md", + "notebook_enable": false, + "exercise_id": "d6f2c270c3cd41a499715e55a2c565ba" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.md" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.md" new file mode 100644 index 0000000..c4b998f --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/3.SQL\343\200\201DML\345\222\214DDL/update.md" @@ -0,0 +1,49 @@ +# 更新数据 + +现有 employee 表如下: + +```postgresql +create table employee +( + id serial primary key, + name text, + dept text, + salary money +); +``` + +我们希望修改销售部(dept 字段为 sale)员工 Dora Muk 的工资,将其增加 1000,返回她的工号。正确的修改语句是: + +## 答案 + +```postgresql +update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk' returning id; +``` + +## 选项 + +### 过滤条件不严谨 + +```postgresql +update employee set salary = salary + 1000 where name = 'Dora Muk' returning id; +``` + +### 没有返回员工id + +```postgresql +update employee set salary = salary + 1000 where dept = 'sale' and name = 'Dora Muk'; +``` + + +### 缺少过滤条件 + +```postgresql +update employee set salary = salary + 1000 returning id; +``` + +### 错误的赋值语句 + +```postgresql +update employee set salary += 1000 returning id; +``` + diff --git "a/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/config.json" "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/3.\346\237\245\350\257\242\346\225\260\346\215\256/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/config.json" new file mode 100644 index 0000000..cedd88b --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "表", + "table" + ], + "children": [], + "export": [ + "table.json", + "create_table.json", + "serial.json" + ], + "keywords_must": [ + "表", + "table" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.json" new file mode 100644 index 0000000..699003a --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "create_table.md", + "notebook_enable": false, + "exercise_id": "14cc4d8de8c44415b80e9c94ea617464" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.md" new file mode 100644 index 0000000..570e2c5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/create_table.md" @@ -0,0 +1,46 @@ +# 建表语句 + +现在我们尝试建立一个简化的交易流水表 trade,需要一个自增主键,一个content字段保存订单详情,, +需要有一个时间戳字段记录订单入库时间,那么哪一个语句是对的? + +## 答案 + +```postgresql +create table trade ( + id serial primary key, + content text, + created_at timestamp default now() +); +``` + +## 选项 + +### 主键没有设置自增,不符合题意 + +```postgresql +create table trade ( + id integer primary key, + content text, + created_at timestamp default now() +); +``` + +### 时间戳没有设置默认值 + +```postgresql +create table trade ( + id serial primary key, + content text, + created_at timestamp +); +``` + +### 没有主键,不符合题设 + +```postgresql +create table trade ( + id serial, + content text, + created_at timestamp default now() +); +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.json" new file mode 100644 index 0000000..f4eb74e --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "serial.md", + "notebook_enable": false, + "exercise_id": "69bcc5f08a4e4328b54e389d74363e2a" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.md" new file mode 100644 index 0000000..987689e --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/serial.md" @@ -0,0 +1,25 @@ +# 自增序列 + +PostgreSQL 表中的自增列 serial 的底层实现机制是: + +## 答案 + +绑定 sequence 对象的表达式默认值 + +## 选项 + +### PG采用的是独立的序列器 + +auto increment 计数器 + +### B + +触发器 + +### C + +系统表 + +### D + +Serial 文件 diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.json" new file mode 100644 index 0000000..7292e1f --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "table.md", + "notebook_enable": false, + "exercise_id": "17b32ec3157e4b7aaa6948fa04db51e3" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.md" new file mode 100644 index 0000000..37182a5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/1.\350\241\250/table.md" @@ -0,0 +1,26 @@ +# 表的基本结构 + +关于数据表的介绍,哪一句是对的? + +## 答案 + +表中每一行记录的结构都要遵循表定义。 + +## 选项 + +### 虽然不推荐,但是可以没有主键 + +表一定要有主键 + +### 表的主键是任意可以建立唯一索引的字段组合 + +表的主键必须是自增的整数 id + +### 索引可以不唯一 + +索引列的内容是唯一的 + +### 虽然不推荐,索引、唯一约束都可以不止一个 + +每个表只能有一个索引 + diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/config.json" new file mode 100644 index 0000000..c705d2d --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "函数", + "function" + ], + "children": [], + "export": [ + "function.json" + ], + "keywords_must": [ + "函数", + "function" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.json" new file mode 100644 index 0000000..b44f17d --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "function.md", + "notebook_enable": false, + "exercise_id": "7d0a6977f12a4d93bd684b56b2ad7003" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.md" new file mode 100644 index 0000000..7f0e049 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/2.\345\207\275\346\225\260/function.md" @@ -0,0 +1,29 @@ +# 函数 + +关于 PostgreSQL 函数,错误的是: + +## 答案 + +函数必须是无副作用的 + +## 选项 + +### A + +函数可以用 SQL 写,也可以用 PLPGSQL,还可以用 Python、Perl、LUA等语言。 + +### B + +函数的参数和返回值可以是简单变量,也可以是结果集或自定义类型 + +### C + +函数可以递归引用 + +### D + +函数之间可以互相引用 + +### E + +函数的使用权限可以通过 grant/revoke/deny 管理 diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/config.json" new file mode 100644 index 0000000..77b0134 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/config.json" @@ -0,0 +1,28 @@ +{ + "node_id": "", + "keywords": [ + "role", + "login", + "user", + "用户", + "角色", + "权限", + "privilege" + ], + "children": [], + "export": [ + "grant.json", + "revoke.json", + "role.json" + ], + "keywords_must": [ + "role", + "login", + "user", + "用户", + "角色", + "权限", + "privilege" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" new file mode 100644 index 0000000..31e82ec --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "grant.md", + "notebook_enable": false, + "exercise_id": "0766e022b61f4c83b4fe64cd8e4e5e9b" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.md" new file mode 100644 index 0000000..bdef587 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/grant.md" @@ -0,0 +1,41 @@ +# 授权 + +管理员要给用户 fred 授权,允许他查询 emplyee 表,应用哪一条语句? + +## 答案 + +```postgresql +grant select on table employee to fred; +``` + +## 选项 + +### 权限名错误 + +```postgresql +grant query on table employee to fred;``` +``` + +### 权限名错误 + +```postgresql +grant read on table employee to fred;``` +``` + +### 操作关键词错误 + +```postgresql +grant select on table employee of fred;``` +``` + +### 操作错误 + +```postgresql +grant select on table employee.* of fred;``` +``` + +### 权限过高 + +```postgresql +grant all on table employee to fred;``` +``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" new file mode 100644 index 0000000..fd0b461 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "revoke.md", + "notebook_enable": false, + "exercise_id": "65de2267ccb7478db916d517d4b5bce7" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.md" new file mode 100644 index 0000000..815419a --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/revoke.md" @@ -0,0 +1,32 @@ +# 撤销权限 + +数据组的 Fred 调到了研发团队,不再参与分析生产数据,现在管理员要收回他对 trade 表的查询权限,假设这个权限是授予他本人的数据库 +用户 fred ,下面哪个操作是对的? + +## 答案 + +```postgresql +revoke select on trade from fred; +``` + +## 选项 + +### 操作错误 + +```postgresql +grant not select on trade to fred; +``` + +### 操作关键字错误 + +```postgresql +revoke select on trade to fred; +``` + +### 指定权限错误 + +```postgresql +revoke owned trade from fred; +``` + + diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" new file mode 100644 index 0000000..a12fc3a --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "role.md", + "notebook_enable": false, + "exercise_id": "f093e146721541139080bc01ffd39750" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.md" new file mode 100644 index 0000000..575f929 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/3.\347\224\250\346\210\267\345\222\214\346\235\203\351\231\220/role.md" @@ -0,0 +1,36 @@ +# 角色 + +你是 rental dvd 公司的数据库管理员,公司数据分析组有 Fred、Alice、James、Jone 四位成员,现在你需要给数据分析组授权,允许他们 +查询 trade 数据库的 public schema 中的所有表,规范的操作应该是 + +## 答案 + +```postgresql +create role analysis; +grant analysis to fred, alice, james, jone; +grant select on all tables in schema public to analysis; +``` + +## 选项 + +### 将来人员变动管理会很繁琐 + +```postgresql +grant select on all tables in schema public to fred, alice, james, jone; +``` + +### 过度授权 + +```postgresql +create role analysis; +grant analysis to fred, alice, james, jone; +grant all on all tables in schema public to analysis; +``` + +### 语句不完整 + +```postgresql +create role analysis; +grant analysis to fred, alice, james, jone; +grant select on all to analysis; +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/config.json" new file mode 100644 index 0000000..5be94ef --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/config.json" @@ -0,0 +1,22 @@ +{ + "node_id": "", + "keywords": [ + "索引", + " 约束", + "constraints", + "index" + ], + "children": [], + "export": [ + "primary_key.json", + "unique.json", + "unique_2.json" + ], + "keywords_must": [ + "索引", + " 约束", + "constraints", + "index" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.json" new file mode 100644 index 0000000..3694031 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "primary_key.md", + "notebook_enable": false, + "exercise_id": "412c89270d24418ab35a1d919a5017e7" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.md" new file mode 100644 index 0000000..72fd10d --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/primary_key.md" @@ -0,0 +1,30 @@ +# 主键 + +关于 PostgreSQL 的主键,哪一项是错误的? + +## 答案 + +主键列只能是自增 id。 + +## 选项 + +### A + +主键隐含了聚集索引和唯一约束 + +### B + +主键可以是一个字段,也可以是多个字段的组合 + +### C + +语法约束上,可以允许无主键的表,但是从工程实践上,应该保持每个表都有正确的主键。 + +### D + +主键或唯一键可以被引用为外键约束 + +### E + +主键应可以唯一的标识数据,并且主键的一部分不应该依赖另一部分。 + diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.json" new file mode 100644 index 0000000..0bde4fa --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "unique.md", + "notebook_enable": false, + "exercise_id": "482896ba26ec43bc8ddedbf3448d47bb" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" new file mode 100644 index 0000000..431506f --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique.md" @@ -0,0 +1,42 @@ +# 唯一约束 + +现有一个图书登记表: + +```postgresql +create table book( + id serial primary key , + title text, + publish_at date, + isbn text, + meta jsonb default '{}'::jsonb +) +``` + +我们发现有时候客户可能会重复输入同一本书的信息,怎样约束用户不会输入同一本书? + +1. 删除id列,将isbn设置为主键 +2. 在 isbn 列上加唯一约束 +3. 执行 `create index on book(id, title, publish_at, isbn, meta)` +4. 在 id 键上加唯一约束 + +## 答案 + +1 或者 2 + +## 选项 + +### A + +3 + +### B + +4 + +### C + +3 或 4 + +### D + +3 和 4 diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.json" new file mode 100644 index 0000000..0deb289 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "unique_2.md", + "notebook_enable": false, + "exercise_id": "f1f5779378ef4684a210188e5730b6a1" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" new file mode 100644 index 0000000..ab9a1a6 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/4.\347\264\242\345\274\225\345\222\214\347\272\246\346\235\237/unique_2.md" @@ -0,0 +1,46 @@ +# 唯一约束 + +现有一个图书登记表: + +```postgresql +create table book( + id serial primary key , + title text, + publish_at date, + isbn text, + meta jsonb default '{}'::jsonb +) +``` + +我们发现有时候客户可能会重复输入同一本书的信息,*在不修改应用层程序的前提下*,怎样约束用户不会输入同一本书? + +1. 删除id列,将isbn设置为主键 +2. 在 isbn 列上加唯一约束 +3. 执行 `create index on book(id, title, publish_at, isbn, meta)` +4. 在 id 键上加唯一约束 + +## 答案 + +2 + +## 选项 + +### A + +3 + +### B + +4 + +### C + +3 或 4 + +### D + +3 和 4 + +### E + +1 或 2 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/config.json" new file mode 100644 index 0000000..9fbe89a --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "trigger", + "触发器" + ], + "children": [], + "export": [ + "trigger.json" + ], + "keywords_must": [ + "trigger", + "触发器" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.json" new file mode 100644 index 0000000..0feefd5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "trigger.md", + "notebook_enable": false, + "exercise_id": "2724dfb0a71c473b8a071e1d2aecc030" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.md" new file mode 100644 index 0000000..a8cc384 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/5. \350\247\246\345\217\221\345\231\250/trigger.md" @@ -0,0 +1,39 @@ +# 触发器 + +SmartMarket 公司的OA数据库中包含以下结构: + +```postgresql +create table employee( + id serial primary key , + name text, + dept text, + salary money, + meta jsonb default '{}'::jsonb +); + +create table budget( + id serial primary key , + dept text, + amount money +) +``` + +我们省略了无关的内容。当某个员工的工资发生变动时,我们要修改他所在部门的预算。那么以下哪个选项可以解决问题? + +## 答案 + +在 employee 表添加一个 after 触发器,当员工信息变动时,重算相关部门的预算。 + +## 选项 + +### A + +在 budget 表添加触发器,当员工信息变动时,重算相关部门的预算。 + +### B + +将预算总额字段变成计算列,通过统计员工工资生成。 + +### C + +将员工信息表的工资字段设置为部门预算总额的外键引用字段,并设置级联更新。 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/config.json" new file mode 100644 index 0000000..ed19c63 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "数据库扩展", + "数据库插件", + "extension" + ], + "children": [], + "export": [ + "language.json", + "extension.json" + ], + "keywords_must": [ + "数据库扩展", + "extension" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.json" new file mode 100644 index 0000000..dc0900e --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "extension.md", + "notebook_enable": false, + "exercise_id": "fad124e7fe1a420dbfbe72de8d4b3f11" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.md" new file mode 100644 index 0000000..6dc9ad1 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/extension.md" @@ -0,0 +1,33 @@ +# 外部扩展 + +下列哪个功能需要通过`create exension`语句安装扩展得到? + +## 答案 + +postgis + +## 选项 + +### A + +全文检索 + +### B + +JSONB + +### C + +GIST 和 GIN 索引 + +### D + +JSON Path 支持 + +### E + +XML 和 XSLT 支持 + +### F + +面向对象语法 diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.json" new file mode 100644 index 0000000..b3d1995 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "language.md", + "notebook_enable": false, + "exercise_id": "4657a4c34eec421a913625fb61af00d4" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.md" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.md" new file mode 100644 index 0000000..2b59cb5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/6.\346\225\260\346\215\256\345\272\223\346\211\251\345\261\225/language.md" @@ -0,0 +1,25 @@ +# 过程语言 + +关于 PostgreSQL PL 语言,错误的是: + +## 答案 + +要安装新的扩展语言,需要重新编译 PostgreSQL 内核。 + +## 选项 + +### A + +PG 可以支持 Python、Perl、Lua 等多种 PL 语言编写函数。 + +### B + +通过 create language 可以安装新的 pl 语言支持 + +### C + +实现新的 PL 语言需要遵循 PostgreSQL 的语言扩展规范。 + +### D + +用外部语言实现函数,要考虑跨边界传递数据的开销 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/config.json" "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/1.\345\237\272\346\234\254\347\273\223\346\236\204/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/config.json" new file mode 100644 index 0000000..c68c334 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/config.json" @@ -0,0 +1,17 @@ +{ + "node_id": "", + "keywords": [ + "group by", + "分组" + ], + "children": [], + "export": [ + "salary.json" + ], + "keywords_must": [ + "group by", + "分组", + "聚合" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.json" new file mode 100644 index 0000000..d1ed8c2 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "salary.md", + "notebook_enable": false, + "exercise_id": "31deab40b4af44c38c363b2333bdd977" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.md" new file mode 100644 index 0000000..fb45ec5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/1.\350\201\232\345\220\210\345\222\214\345\210\206\347\273\204/salary.md" @@ -0,0 +1,63 @@ +# 工资最高的人 + +现有员工信息表如下: + +```postgresql +create table employee +( + id serial primary key, + name text, + dept text, + salary money +); +``` + +下面哪条查询,可以给出每个部门工资最高的员工的 id, name, dept, salary 四项信息? + +## 答案 + +```postgresql +select l.id, l.name, l.dept, l.salary +from employee as l + join (select max(salary) as salary, dept + from employee + group by dept) as r + on l.dept = r.dept and l.salary = r.salary +``` + +## 选项 + +### select 与 group by 不匹配 + +```postgresql +select id, name, dept, max(salary) +from employee +group by dept; +``` + +### group by 不对 + +```postgresql +select id, name, dept, max(salary) +from employee +group by dept, id, name; +``` + +### group by 不对 + +```postgresql +select id, name, dept, max(salary) +from employee +group by dept, id, name +having salary = max(salary); +``` + +### 结构错误 + +```postgresql +select id, name, dept, max(salary) +from employee +where salary = max(salary) +group by dept; +``` + diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/config.json" new file mode 100644 index 0000000..618ed6d --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "join", + "连接查询" + ], + "children": [], + "export": [ + "customer_order.json" + ], + "keywords_must": [ + "join", + "连接查询" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.json" new file mode 100644 index 0000000..3988606 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "customer_order.md", + "notebook_enable": false, + "exercise_id": "18d5a22c34874bb4b73aac6846674243" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.md" new file mode 100644 index 0000000..3b1df39 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/2.\350\277\236\346\216\245\346\237\245\350\257\242/customer_order.md" @@ -0,0 +1,52 @@ +# 客户和订单 + +我们现在看下面这个客户/订单系统 + +```postgresql +create table customers +( + id serial primary key, + company_name text, + address text, + city text, + state text +); + +create table products +( + id serial primary key, + description text, + unit_price money +); + +create table orders +( + id serial primary key, + product_id integer references products (id), + order_date timestamp, + quantity integer, + customer_id integer references customers(id) +); + +``` + +我们希望这个数据库能够允许每个订单包含多种商品,那么应该如何改造? + +## 答案 + +* 添加一个 order_detail 表,引用 order id、product id,增加 quantity 列 +* order 表中删除 product id 和 quantity 列 + +## 选项 + +### A + +将 order 表的修改为以 product id 和 customer id 作为联合主键 + +### B + +删除 orders 表中的 product id 和 quantity 列 + +### C + +在 order 表的主键上加唯一约束 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/config.json" new file mode 100644 index 0000000..408f435 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "子查询", + "subquery" + ], + "children": [], + "export": [ + "subquery.json" + ], + "keywords_must": [ + "子查询", + "subquery" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" new file mode 100644 index 0000000..b6a2f58 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "subquery.md", + "notebook_enable": false, + "exercise_id": "82be2aa951304dc9869cd7177fcba99f" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.md" new file mode 100644 index 0000000..46db4df --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/3.\345\255\220\346\237\245\350\257\242/subquery.md" @@ -0,0 +1,58 @@ +# 子查询 + +现有员工表 + +```postgresql +create table employee +( + id serial primary key, + name text, + dept text, + salary money +) +``` + +我们希望找出比销售部(dept 为 sale)工资最高的员工工资更高的那部分人,查询出他们的完整信息,下面哪一项可以满足要求? + +## 答案 + +```postgresql +select id, name, dept, salary +from employee +where salary > (select max(salary) + from employee + where dept = 'sale') +``` + +## 选项 + +### A + +```postgresql +select id, name, dept, salary +from employee +where dept = 'sale' +group by dept +having salary > max(salary) +``` + +### B + +```postgresql +select l.id, l.name, l.dept, l.salary +from employee as l + join employee as r on l.salary > max(r.salary) +where r.dept = 'sale' +group by r.dept +``` + +### C + +```postgresql +select id, name, dept, salary +from employee +having salary > (select max(salary) from employee where dept = 'sale') +``` + + + diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" new file mode 100644 index 0000000..6f3b4a1 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "分页", + "limit", + "offset" + ], + "children": [], + "export": [ + "paged.json" + ], + "keywords_must": [ + "分页", + "limit", + "offset" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.json" new file mode 100644 index 0000000..3e499ac --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "paged.md", + "notebook_enable": false, + "exercise_id": "c92fab72b5c24e76b1032ca7a0c64c44" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.md" new file mode 100644 index 0000000..9ca4cf8 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/4.\345\210\206\351\241\265\346\237\245\350\257\242/paged.md" @@ -0,0 +1,53 @@ +# 分页 + +我们有如下订单表: + +```postgresql +create table orders +( + id serial primary key, + product_id integer, + order_date date default now(), + quantity integer, + customer_id integer +); +``` + +现在开发人员希望查询指定的某一天内的数据,并按每一百条一页查询,那么正确的语句应该是: + +## 答案 + +```postgresql +select id, product_id, order_date, quantity, customer_id +from orders +where date = $1 +offset $2 limit 100; +``` + +## 选项 + +### 缺少 limit + +```postgresql +select id, product_id, order_date, quantity, customer_id +from orders +where date = $1 +offset $2; +``` + +### 缺少 offset + +```postgresql +select id, product_id, order_date, quantity, customer_id +from orders +where date = $1; +``` + +### 结构不对 + +```postgresql +select id, product_id, order_date, quantity, customer_id +from orders +where date = $1 and +offset $2 and limit 100; +``` diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/config.json" new file mode 100644 index 0000000..4d625e5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "common table expression", + "cte", + "recursive" + ], + "children": [], + "export": [ + "to_root.json" + ], + "keywords_must": [ + "cte" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.json" new file mode 100644 index 0000000..d0b0d05 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "to_root.md", + "notebook_enable": false, + "exercise_id": "45f0cef12fcf4f9e90276dff6a336657" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.md" new file mode 100644 index 0000000..fa140c5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/5.CTE/to_root.md" @@ -0,0 +1,67 @@ +# 树结构溯根 + +现有一个表 node + +```postgresql +create table node +( + id serial primary key, + pid integer, + content text +); +``` + +其 pid 列引用 id 列,形成一个树结构,根节点的 pid 为 0。 + +现在我们希望写一个查询,找到某一个给定id的记录,其父节点、父节点的父节点,直至根节点的路径。那么这个查询应该是: + +## 答案 + +```postgresql +with recursive t(id, pid, content) as ( + select id, pid, content + from node + where id = $1 + union all + select node.id, node.pid, node.content + from node + join t on node.id = t.pid) +select node.id, node.pid, content +from node + join t on node.id = t.id; +``` + +## 选项 + +### 没有递归定义 + +```postgresql +with t as ( + select id, pid, content + from node + where id = $1 + union all + select node.id, node.pid, node.level + from node + join t on node.id = t.pid) +select node.id, node.pid, content +from node + join t on node.id = t.id; +``` + +### 平凡的连接查询无法处理递归问题 + +```postgresql +select node.id, node.pid, node.content +from node + join node as p on node.pid = p.id +where id = $1; +``` + +### 子查询无法处理递归问题 + +```postgresql +select node.id, node.pid, node content +from node as t +where t.pid = (select id from t where id = t.pid) +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" new file mode 100644 index 0000000..c70722b --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/config.json" @@ -0,0 +1,15 @@ +{ + "node_id": "", + "keywords": [ + "plsql", + "过程化" + ], + "children": [], + "export": [ + "loop.json" + ], + "keywords_must": [ + "过程化" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" new file mode 100644 index 0000000..a971b7c --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "loop.md", + "notebook_enable": false, + "exercise_id": "8d25c0639365404ba3c61282e5ea32ba" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" new file mode 100644 index 0000000..318e541 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/6.\350\277\207\347\250\213\345\214\226\347\274\226\347\250\213/loop.md" @@ -0,0 +1,80 @@ +# 循环 + +下面哪一项定义的函数可以生成指定范围内的整数数列? + +## 答案 + +```postgresql +create function gen(start integer, stop integer) + returns setof integer as +$$ +begin + for idx in start .. stop + loop + return next idx; + end loop; +end; +$$ language plpgsql; +``` + +## 选项 + +### A + +```postgresql +create function gen(start integer, stop integer) returns integer as +$$ +begin + for idx in start .. stop + loop + return idx; + end loop; +end; +$$ language plpgsql; +``` + +### B + +```postgresql +create function gen(start integer, stop integer) + returns integer as +$$ +begin + for idx in start .. stop + loop + yield idx; + end loop; +end; +$$ language plpgsql; +``` + +### C + +```postgresql +create function gen(start integer, stop integer) + returns setof integer as +$$ +begin + for idx in start .. stop + loop + return idx; + idx += 1; + end loop; +end; +$$ language plpgsql; +``` + +### D + +```postgresql +create function gen(start integer, stop integer) + returns setof integer as +$$ +begin + for idx in start .. stop + loop + select idx; + end loop; +end; +$$ language plpgsql; +``` \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.json" new file mode 100644 index 0000000..387de4f --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "analyze.md", + "notebook_enable": false, + "exercise_id": "ee4d10ae488b4900835e52d184822962" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.md" new file mode 100644 index 0000000..5649fd6 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/analyze.md" @@ -0,0 +1,38 @@ +# 建表权限 + +SmartMarket 公司有一百名分析师,他们都属于 analyst 团队,现在他们希望能够在 market 仓库的 ana schema 下 +自由的建表和删除表,以便进行模型试验。下列操作步骤中需要选择哪几项?(ana schema 和分析师的团队角色还不存在) + +1. `create schema ana` +2. `create role analyst` +3. `grant create, usage on schema ana to analyst` +4. 将 analyst 角色授予每个分析师的账号 +5. 删除 public schema +6. `grant superuser on schema ana to analyst` +7. `grant owner on schema ana to analyst;` + +## 答案 + +1,2, 3, 4 + +## 选项 + +### A + +所有全部 + +### B + +1, 2, 5, 6, 7 + +### C + +1, 2, 6, 7 + +### D + +1, 2, 3, 6, 7 + +### E + +2, 3, 4, 5 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/config.json" new file mode 100644 index 0000000..d3ba818 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/config.json" @@ -0,0 +1,19 @@ +{ + "node_id": "", + "keywords": [ + "创建表", + "授权", + "ddl" + ], + "children": [], + "export": [ + "create_table.json", + "analyze.json" + ], + "keywords_must": [ + "创建表", + "授权", + "ddl" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.json" new file mode 100644 index 0000000..5a0f9e5 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "create_table.md", + "notebook_enable": false, + "exercise_id": "b9fc3c13d8df447fa9244f142b5c8c16" +} \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.md" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.md" new file mode 100644 index 0000000..f723a5c --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/7.DDL/create_table.md" @@ -0,0 +1,29 @@ +# 创建表 + +下列方法中,可以创建表的有: + +1. 使用 `create table xxx();`语句 +2. 使用 `copy` 语句从 csv 导入数据 +3. 使用 `create table as select...` 语句从查询中创建表 + +## 答案 + +1, 3 + +## 选项 + +### A + +1, 2, 3 + +### B + +1, 2 + +### C + +2, 3 + +### D + +只有 1 \ No newline at end of file diff --git "a/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/config.json" "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/2.MySQL\344\270\255\351\230\266/2.\346\234\215\345\212\241\347\253\257\347\274\226\347\250\213/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" new file mode 100644 index 0000000..4ad4ea3 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "backup.md", + "notebook_enable": false, + "exercise_id": "261517a14bca4cfd98ce23caf63c9cf5" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" new file mode 100644 index 0000000..ecfe8b2 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/backup.md" @@ -0,0 +1,41 @@ +# 高可靠备份 + +你的团队有一个非常重要的业务数据库,希望在需要时,可以重建它在一周内任意某个时间点的状态。下列规划中不必要的是: + +1. 对 WAL 日志建立备份,按时间保留所有的 WAL 文件作为增量备份 +2. 每天做一次冷备 +3. 需要重现时,用离目标时间点最近的前一次冷备恢复一个数据库节点,启动为 standby 状态,用对应的 wal 恢复。 +4. 建立流备份节点 +5. 每天非高峰期将数据库离线,完整复制一份数据区目录 + +## 答案 + +``` +4, 5 +``` + +## 选项 + +### A + +``` +1, 2 +``` + +### B + +``` +3 +``` + +### C + +``` +以上所有工作都需要,没有多余项 +``` + +### D + +``` +2, 4 +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" new file mode 100644 index 0000000..3a4aa47 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "standby", + "热备份", + "高可用", + "流复制" + ], + "children": [], + "export": [ + "standby.json", + "backup.json" + ], + "keywords_must": [ + "standby" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" new file mode 100644 index 0000000..1340b40 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "standby.md", + "notebook_enable": false, + "exercise_id": "491d9bdd19c04279ac607b73a63bb3e6" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.md" new file mode 100644 index 0000000..fe5f6c0 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/1.standby/standby.md" @@ -0,0 +1,33 @@ +# standby + +关于 PG Standby,错误的是: + +## 答案 + +复制节点需要有主节点的超级用户权限。 + +## 选项 + +### A + +Hot standby 是通过同步 WAL 实现的。 + +### B + +从节点处于制度状态 + +### C + +可以设置从节点切换为主节点的超时阈值 + +### D + +从节点会保持与主节点的数据和结构一致 + +### E + +从节点不需要和主节点保持长连接 + +### F + +从节点不需要和主节点硬件环境一致 \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/config.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/config.json" new file mode 100644 index 0000000..498ac56 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "standby", + "高可用", + "流复制", + "wal" + ], + "children": [], + "export": [ + "stream.json" + ], + "keywords_must": [ + "流式复制", + "流复制" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" new file mode 100644 index 0000000..723ccf8 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "stream.md", + "notebook_enable": false, + "exercise_id": "061bfb92b674438cb56a6cf72c406cbb" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.md" new file mode 100644 index 0000000..ce48126 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/2.\346\265\201\345\274\217\345\244\215\345\210\266\351\233\206\347\276\244/stream.md" @@ -0,0 +1,38 @@ +# 流式复制 + +关于流式复制,错误的是: + +## 答案 + +流式复制的主节点损坏,会导致订阅节点也损坏。 + +## 选项 + +### A + +订阅数据流的需要特定的复制角色 + +### B + + 订阅节点可以作为只读的从节点,提供读写分离 + + +### C + +主节点崩溃,子节点会将自己切换为独立工作状态 + +### D + +节点间传输的是 wal 数据流 + +### E + +主从节点的硬件配置可以不一致 + +### F + +可以配置多级订阅 + +### G + +可以多个从节点订阅一个主节点 \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/config.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/config.json" new file mode 100644 index 0000000..83eb165 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "外部数据连接", + "fdw" + ], + "children": [], + "export": [ + "fdw.json" + ], + "keywords_must": [ + "外部数据连接", + "fdw" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.json" new file mode 100644 index 0000000..116908a --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "fdw.md", + "notebook_enable": false, + "exercise_id": "762a9c3f032b4ce884858c18e2bb580c" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.md" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.md" new file mode 100644 index 0000000..e9345c3 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/3.fdw/fdw.md" @@ -0,0 +1,28 @@ +# 外部数据源 + +RDVD 公司有一个 Oracle 数据库和一个PG数据库,现在需要每天汇总一次 PG 中的订单表和 oracle 中的客户信息表,从中生成一份 +报表。现在你想在尽量不增加冗余数据的前提下,在PG服务上每天执行一次简单的查询任务来生成报表,那么应该: + +## 答案 + +* 在 PG 数据库建立一个 fdw 数据源,连接 Oracle 数据库 +* 在 PG 服务器中建立一个视图, 对客户信息表进行的查询变成一个 PG 查询 +* 基于客户信息视图和订单表生成每日报表 + +## 选项 + +### 异构平台无法直接复制,且复制节点会影响功能 + +* 设置 PG 为 Oracle 的复制节点 +* 订阅 Oracle 的变更流 + +### 不可靠的方法 + +* 用一个定时任务复制 Oracle 中的客户信息变更 +* 写入 PG 数据库 + +### 低效且占用空间 + +* 在 PG 服务器上建一个同构的客户表 +* 在 Oracle 服务器上写一个触发器 +* 将客户信息写入 PostgreSQL 数据库 \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/config.json" "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/1.\351\233\206\347\276\244\345\222\214\345\244\215\345\210\266/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" new file mode 100644 index 0000000..80df7ab --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "gis", + "地理信息" + ], + "children": [], + "export": [ + "gis.json" + ], + "keywords_must": [ + "gis", + "几何" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" new file mode 100644 index 0000000..dcf6e51 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "gis.md", + "notebook_enable": false, + "exercise_id": "617b947cb29b4a75b4b9367eaf7b8a7d" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" new file mode 100644 index 0000000..3d54b4a --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/1.\345\207\240\344\275\225\347\261\273\345\236\213\345\222\214GIS/gis.md" @@ -0,0 +1,66 @@ +# 邻近查找 + +我们有一个简化的表结构如下: + +```postgresql +create table city +( + id serial8, + city text, + poi point +); +create index idx_tbl_point on city using gist (poi) with (buffering = on); +``` + +要查找给定的点位于哪个城市,或者离哪个城市最近,应该是下列哪一项? + +## 答案 + +```postgresql +select city, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +order by poi <-> point($1, $2) +limit 1; +``` + +## 选项 + +### A + +```postgresql +select city, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +order by poi <-> point($1, $2) desc +limit 1; +``` + +### B + +```postgresql +select *, poi <-> point($1, $2) dist +from city +where poi <-> point($1, $2) < 100 +limit 1; +``` + +### C + +```postgresql +select *, poi - point($1, $2) dist +from city +where poi - point($1, $2) < 100 +order by poi - point($1, $2) +limit 1; +``` + +### D + +```postgresql +select *, abs(poi - point($1, $2)) dist +from city +where abs(poi - point($1, $2)) < 100 +order by abs(poi - point($1, $2)) +limit 1; +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/config.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/config.json" new file mode 100644 index 0000000..415fc8e --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "json", + "jsonb" + ], + "children": [], + "export": [ + "json.json", + "match.json", + "tags.json" + ], + "keywords_must": [ + "json", + "jsonb" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.json" new file mode 100644 index 0000000..2d908f6 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "json.md", + "notebook_enable": false, + "exercise_id": "99a960a0b46f4b1ba19bdb4bce6ac31d" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.md" new file mode 100644 index 0000000..f6daaf1 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/json.md" @@ -0,0 +1,31 @@ +# JSON 和 JSONB 类型 + +关于 JSON 和 JSONB 类型,哪句话是错的? + +## 答案 + +JSON 就是 文本类型的封装,JSONB 是 JSON 的二进制压缩格式,JSON 和 JSONB 的功能与 TEXT 类型一样。 + +## 选项 + +### A + +JSONB 是推荐的 JSON 字段类型,更为高效。 + +### B + +JSONB 可以通过 GIST 倒排索引优化对内部结构的查询。 + + +### C + +PostgreSQL JSON 和 JSONB 支持 JSON PATH表达式 + +### D + +JSONB 和 文本可以有效兼容 + +### E + +JSON 和 JSONB 与其它类型一样,不能部分修改,只能作为整体插入或更新 + diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.json" new file mode 100644 index 0000000..b4b7e5c --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "match.md", + "notebook_enable": false, + "exercise_id": "5b730f2a3c734ce780766ad23dcad033" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.md" new file mode 100644 index 0000000..a51534d --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/match.md" @@ -0,0 +1,56 @@ +# 匹配 + +表 book 的 meta 有类似如下结构: + +```json +{ + "author": [ + "Mars Liu", + "Milly Lee" + ], + "ISBN": "xxxx-xxxx-xxxxxx", + "version": 1 +} +``` + +该字段有 gist 索引。 + +如果我们想高效率的找到所有作者包含 Jim Gray 的书,应该如何查询? + +## 答案 + +```postgresql +select * from book where meta @> '{"author": ["Jim Gray"]}'::jsonb; +``` + +## 选项 + +### A + +```postgresql +select * from book where meta @> '["Jim Gray"]'::jsonb; +``` + +### A + +```postgresql +select * from book where 'Jim Gray' in meta; +``` + +### B + +```postgresql +select * from book where meta::text like '%Jim Gray%'; +``` + +### C + +```postgresql +select * from book having meta @> 'Jim Gray' +``` + +### D + +```postgresql +select * from book where 'Jim Gray' in (meta #>> 'author'); +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.json" new file mode 100644 index 0000000..73a9ee5 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "tags.md", + "notebook_enable": false, + "exercise_id": "a415bb85ddb3400aae34318b9c142639" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.md" new file mode 100644 index 0000000..b155507 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/2.JSON\345\222\214JSONB/tags.md" @@ -0,0 +1,46 @@ +# 标签 + +现有一个表 sku: + +```postgresql +create table sku( + id serial primary key , + name text, + meta jsonb default '{}'::jsonb, + tags jsonb default '[]'::jsonb +) +``` + +我们希望查找包含所有给定tag的商品,那么查询应该是: + +## 答案 + +```postgresql +select id, name, meta, tags from sku where tags @> $1; +``` + +## 选项 + +### A + +```postgresql +select id, name, meta, tags from sku where tags = $1; +``` + +### B + +```postgresql +select id, name, meta, tags from sku where tags::text = $1; +``` + +### C + +```postgresql +select id, name, meta, tags from sku where $1 in tags; +``` + +### D + +```postgresql +select id, name, meta, tags from sku where tags in $1; +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/config.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/config.json" new file mode 100644 index 0000000..6c5f4f7 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/config.json" @@ -0,0 +1,23 @@ +{ + "node_id": "", + "keywords": [ + "函数", + "过程", + "function", + "produce" + ], + "children": [], + "export": [ + "distinct.json" + ], + "keywords_must": [ + "聚合函数", + "json函数", + [ + "数组", + "函数" + ], + "" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.json" new file mode 100644 index 0000000..9b9f5f2 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "distinct.md", + "notebook_enable": false, + "exercise_id": "e5c4e314fcee480db8f4db8f9d76e0fd" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.md" new file mode 100644 index 0000000..f94e059 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/3.\345\207\275\346\225\260/distinct.md" @@ -0,0 +1,51 @@ +# 去重 + +下列函数中,有一个实现了合并两个 jsonb 对象并对其去重,是哪一项? + +## 答案 + +```postgresql +create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as +$$ +select jsonb_agg(distinct (value)) +from jsonb_array_elements(a || b) +$$ language sql +``` + +## 选项 + +### A + +```postgresql +create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as +$$ +select a || b +$$ language sql +``` + +### B + +```postgresql +create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as +$$ return jsonb_agg(distinct(value)) from jsonb_array_elements(a||b) +$$ + language sql +``` + +### C + +```postgresql +create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as +$$ return next jsonb_agg(distinct(value)) from jsonb_array_elements(a||b) +$$ + language sql +``` + +### D + +```postgresql +create function jsonb_distinct_merge(a jsonb, b jsonb) returns jsonb as +$$ +select a + b; +$$ language sql +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/config.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/config.json" new file mode 100644 index 0000000..9db7e2f --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "视图", + "view" + ], + "children": [], + "export": [ + "view.json" + ], + "keywords_must": [ + "视图", + "view" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.json" new file mode 100644 index 0000000..e3c7579 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "view.md", + "notebook_enable": false, + "exercise_id": "29e05c6b76c648f8bf9bcf08be3de364" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.md" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.md" new file mode 100644 index 0000000..9d4c2f4 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/4.\350\247\206\345\233\276/view.md" @@ -0,0 +1,30 @@ +# 视图 + +SmartMarket 公司的数据分析师,每天要执行一个固定的复杂查询,生成每日报表。我们准备将其创建为视图,这能够解决: + +1. 简化查询 +2. 降低查询时死锁的风险 +3. 大幅优化查询性能 +4. 限制权限 + +## 答案 + +1, 4 + +## 选项 + +### A + +1. 2, 3, 4 + +### B + +1, 2, 3 + +### C + +2, 3 + +### D + +3, 4 \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/config.json" "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/2.\351\253\230\347\272\247\346\225\260\346\215\256\347\261\273\345\236\213/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/config.json" new file mode 100644 index 0000000..527e45c --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "cte", + "递归查询", + "recursive" + ], + "children": [], + "export": [ + "continuous.json" + ], + "keywords_must": [ + "cte", + "递归查询", + "recursive" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.json" new file mode 100644 index 0000000..d53a0fc --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "continuous.md", + "notebook_enable": false, + "exercise_id": "bd4568ed83594d12b510c6c69bf611f2" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" new file mode 100644 index 0000000..ac72265 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/1.\351\200\222\345\275\222\346\237\245\350\257\242/continuous.md" @@ -0,0 +1,69 @@ +# 获取连续区间 + +SmartMarket 交易所的系统中,所有订单在生成时,都从一个 PostgreSQL Sequence 中获取唯一的 序列号,完成交易计算后各个撮合程序将其插入如下的 orders 表中: + +```postgresql +create table orders +( + id integer primary key, + meta jsonb default '{}'::jsonb, + content jsonb default '{}'::jsonb + -- ignore other definitions... +); +``` + +后续的结算系统需要连续的获取订单,以便处理一些顺序敏感的业务。但是撮合发生在很多个异步节点上,它们只能保证最终会将所有订单都保存到 orders 表,确保 id 列最终是连续的,但是最新插入的一段记录集有可能不连续。而我们希望结算系统成批 +的读取数据,以优化性能,那么在结算系统有它最后处理的订单id的前提下,下面哪一个查询可以确保从这个id向前读取 id 连续 的一批订单? + +## 答案 + +```postgresql +with recursive r(id) as (select id + from orders + where id = $1 + union + select d.id + from orders as d + join r on d.id = r.id + 1) +select orders.id, meta, content +from orders + join r on orders.id = r.id; +``` + +## 选项 + +### A + +没有办法构造一个简单查询实现这个功能,因为它的数据过滤条件递归的依赖查询结果。 + +### B + +```postgresql +select data.id, meta, content +from orders + join orders as r on orders.id = r.id - 1 +where id = $1; +``` + +### C + +```postgresql +select id, meta, content +from orders +where id in (select id from orders where id = id + 1); +``` + +### D + +```postgresql +with r as (select id + from orders + where id = $1 + union + select d.id + from orders as d + join r on d.id = r.id + 1) +select orders.id, meta, content +from orders + join r on orders.id = r.id; +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/config.json" new file mode 100644 index 0000000..323f585 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/config.json" @@ -0,0 +1,17 @@ +{ + "keywords": [ + "函数", + "function" + ], + "children": [], + "node_id": "", + "export": [ + "salary.json" + ], + "keywords_must": [ + "函数", + "function", + "window" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.json" new file mode 100644 index 0000000..c54524d --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "salary.md", + "notebook_enable": false, + "exercise_id": "6dc9ce6d2a354a9986585a458e5476c9" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" new file mode 100644 index 0000000..6af362b --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/2.Window Function/salary.md" @@ -0,0 +1,74 @@ +# 工资最高的人 + +现有员工信息表如下: + +```postgresql +create table employee +( + id serial primary key, + name text, + dept text, + salary money +); +``` + +下面哪条查询,可以给出每个部门工资最高的前五个员工的 id, name, dept, salary 四项信息? + +## 答案 + +```postgresql +select id, name, dept, salary +from (select id, name, dept, salary, rank() over (partition by dept order by salary desc) as r + from employee) as t +where r <= 5; +``` + +## 选项 + +### 结构错误 + +```postgresql +select id, name, dept, max(salary) as salary +from employee +group by dept +having id < 6; +``` + +### 结构错误 + +```postgresql +select l.id, l.name, l.dept, l.salary +from employee as l + join (select max(salary) as salary, dept + from employee + group by dept) as r + on l.dept = r.dept and l.salary = r.salary +where count(r.id) <= 5; +``` + +### 结构错误 + +```postgresql +select l.id, l.name, l.dept, l.salary +from employee as l + join (select max(salary, 5) as salary, dept + from employee + group by dept) as r + on l.dept = r.dept and l.salary = r.salary +``` + +### 结构错误 + +```postgresql +select id, name, dept, salary, rank() over (partition by dept order by salary desc) as r +from employee +where r <= 5; +``` + +### 结构错误 + +```postgresql +select id, name, dept, salary, rank() as r over (partition by dept order by salary desc) +from employee +where r <= 5; +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /config.json" new file mode 100644 index 0000000..5707411 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /config.json" @@ -0,0 +1,18 @@ +{ + "node_id": "", + "keywords": [ + "透视表", + "交叉透视表", + "pivot" + ], + "children": [], + "export": [ + "pivot.json" + ], + "keywords_must": [ + "透视表", + "交叉透视表", + "pivot" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.json" new file mode 100644 index 0000000..fd3bd72 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "pivot.md", + "notebook_enable": false, + "exercise_id": "e39489bf015448fb87c9722d05b357a4" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" new file mode 100644 index 0000000..450687c --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/3.\351\200\217\350\247\206\350\241\250 /pivot.md" @@ -0,0 +1,90 @@ +# 透视表 + +现有销售记录表 + +```postgresql +create table sales( + id serial primary key , + sku_id integer not null , + amount money, + meta jsonb default '{}'::jsonb, + created_at timestamp default now() +); +create index on sales(created_at); +``` + +现在我们希望对这个表做一个月度的透视汇总,得到2020年每个月每种商品(sku_id)的的销售总额,每个月一列,哪一项可以实现? + +## 答案 + +```postgresql +select sku_id, + sum(case extract(month from created_at) when 1 then amount else 0::money end) as Jan, + sum(case extract(month from created_at) when 2 then amount else 0::money end) as Feb, + sum(case extract(month from created_at) when 3 then amount else 0::money end) as Mar, + sum(case extract(month from created_at) when 4 then amount else 0::money end) as Apr, + sum(case extract(month from created_at) when 5 then amount else 0::money end) as May, + sum(case extract(month from created_at) when 6 then amount else 0::money end) as June, + sum(case extract(month from created_at) when 7 then amount else 0::money end) as July, + sum(case extract(month from created_at) when 8 then amount else 0::money end) as Aug, + sum(case extract(month from created_at) when 9 then amount else 0::money end) as Sept, + sum(case extract(month from created_at) when 10 then amount else 0::money end) as Oct, + sum(case extract(month from created_at) when 11 then amount else 0::money end) as Nov, + sum(case extract(month from created_at) when 12 then amount else 0::money end) as Dec +from sales +where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp +group by sku_id; +``` + +## 选项 + +### 格式不相符 + +```postgresql +select sku_id, extract(month from created_at) as month, sum(amount) +from sales +where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp +group by 1, 2; +``` + +### 计算逻辑错误 + +```postgresql +select sku_id, + sum(amount) as Jan, + sum(amount) as Feb, + sum(amount) as Mar, + sum(amount) as Apr, + sum(amount) as May, + sum(amount) as June, + sum(amount) as July, + sum(amount) as Aug, + sum(amount) as Sept, + sum(amount) as Oct, + sum(amount) as Nov, + sum(amount) as Dec +from sales +where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp +group by sku_id, extract(month from created_at); +``` + +### 计算格式错误 + +```postgresql +select sku_id, + sum(amount having extract(month from created_at) = 1) as Jan, + sum(amount having extract(month from created_at) = 2) as Feb, + sum(amount having extract(month from created_at) = 3) as Mar, + sum(amount having extract(month from created_at) = 4) as Apr, + sum(amount having extract(month from created_at) = 5) as May, + sum(amount having extract(month from created_at) = 6) as June, + sum(amount having extract(month from created_at) = 7) as July, + sum(amount having extract(month from created_at) = 8) as Aug, + sum(amount having extract(month from created_at) = 9) as Sept, + sum(amount having extract(month from created_at) = 10) as Oct, + sum(amount having extract(month from created_at) = 11) as Nov, + sum(amount having extract(month from created_at) = 12) as Dec +from sales +where created_at between '2020-01-01'::timestamp and '2021-01-01'::timestamp +group by sku_id, extract(month from created_at); +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/config.json" new file mode 100644 index 0000000..73b0a6e --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/config.json" @@ -0,0 +1,17 @@ +{ + "node_id": "", + "keywords": [ + "conflict", + "冲突", + "唯一约束" + ], + "children": [], + "export": [ + "score.json" + ], + "keywords_must": [ + "conflict", + "冲突" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" new file mode 100644 index 0000000..80fd4f0 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "score.md", + "notebook_enable": false, + "exercise_id": "a4ef62fde91d4f558c6107172ba4f736" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" new file mode 100644 index 0000000..ee43341 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/4.\345\206\231\345\205\245\345\222\214\345\206\262\347\252\201/score.md" @@ -0,0 +1,50 @@ +# 积分累计 + +现有一个表 + +```postgresql +create table book_in( + login integer primary key , + score integer default 0 +); +``` + +用于记录用户行为积分,不同的客户端分布式的异步提交各个login的行为得分,如果一个用户不在表中,我们 +需要插入一条新纪录,如果已经存在,则需要将新提交的score累加到表中,下列哪个查询可以实现此功能? + +## 答案 + +```postgresql +insert into book_in(login, score) values ($1, $2) on conflict do update set score=$2; +``` + +## 选项 + +### A + +```postgresql +try + insert into book_in(login, score) values ($1, $2); +catch + update book_in set score = $2 where login = $1 +finally + commit; +``` + +### B + +```postgresql +insert into book_in(login, score) select $1, $2; +``` + +### C + +```postgresql +replace book_in(login, score) select $1, $2; +``` + +### D + +```postgresql +upsert into book_in(login, score) select $1, $2; +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/config.json" new file mode 100644 index 0000000..7675aac --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/config.json" @@ -0,0 +1,16 @@ +{ + "node_id": "", + "keywords": [ + "事务", + "transaction" + ], + "children": [], + "export": [ + "transaction.json" + ], + "keywords_must": [ + "事务", + "transaction" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.json" new file mode 100644 index 0000000..e5b6818 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "transaction.md", + "notebook_enable": false, + "exercise_id": "bce8976b508942bdbe3bd5b6315e7583" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.md" new file mode 100644 index 0000000..eefdd50 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/5.\344\272\213\345\212\241/transaction.md" @@ -0,0 +1,48 @@ +# 事务 + +现有 test1 表如下 + +```postgresql +create table test1(a integer primary key ); +``` + +我们执行下面的语句 + +```postgresql +CREATE PROCEDURE transaction_test1() +LANGUAGE plpgsql +AS $$ +BEGIN + FOR i IN 0..9 LOOP + INSERT INTO test1 (a) VALUES (i); + IF i % 2 = 0 THEN + COMMIT; + ELSE + ROLLBACK; + END IF; + END LOOP; +END; +$$; + +CALL transaction_test1(); +``` + +时,下面哪一项的解释是对的? + +## 答案 + +每当循环迭代到偶数的时候提交插入,最终 test1 表中是`0,2,4,6,8`。 + +## 选项 + +### A + +以最后一次提交为准,最终 test1 表中是 0 到 9 共九个数字。 + +### B + +所有插入都回滚了。test1 表中没有数据。 + +### C + +这个过程执行会报错。 \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/config.json" new file mode 100644 index 0000000..95a4cd1 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/config.json" @@ -0,0 +1,21 @@ +{ + "node_id": "", + "keywords": [ + "索引", + "index", + "performance", + "优化" + ], + "children": [], + "export": [ + "daily_payment.json", + "daily_payment_2.json" + ], + "keywords_must": [ + "索引", + "index", + "performance", + "优化" + ], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" new file mode 100644 index 0000000..487ecec --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "daily_payment.md", + "notebook_enable": false, + "exercise_id": "5e355cc9197a4d02a54f045301c88ace" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.md" new file mode 100644 index 0000000..268803a --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment.md" @@ -0,0 +1,80 @@ +# 每日报表 + +数据分析组需要经常执行以下查询生成从昨天到之前某一天的交易量统计 + +```postgresql +select payment_date::date as day, sum(amount) +from payment +where (payment_date::date) between $1 and 'yesterday'::date +group by payment_date::date; +``` + +现在这个查询很慢,payment 表的信息如下: + +```text + Table "public.payment" + Column | Type | Collation | Nullable | Default +--------------+-----------------------------+-----------+----------+--------------------------------------------- + payment_id | integer | | not null | nextval('payment_payment_id_seq'::regclass) + customer_id | smallint | | not null | + staff_id | smallint | | not null | + rental_id | integer | | not null | + amount | numeric(5,2) | | not null | + payment_date | timestamp without time zone | | not null | +Indexes: + "payment_pkey" PRIMARY KEY, btree (payment_id) +``` + +应该如何优化这个查询? + +## 答案 + +建立表达式索引 + +```postgresql +create index on payment((payment_date::date)); +``` + +## 选项 + +### 对性能优化并无帮助 + +建立视图 + +```postgresql +create view view_daily_payment as select payment_date::date as day, amount from payment; +``` + +然后在视图 view_daily_payment 上执行 + +```postgresql +select day, sum(amount) +from view_daily_payment +where day between $1 and 'yesterday'::date +group by day +``` + +### 对该查询帮助不大 + +在 payment_date 列上建立索引 + +```postgresql +create index on payment(payment_date); +``` + +### 可以简化语句,但对优化没有帮助 + +建立计算列 + +```postgresql +alter table payment add day date generated always as ( payment_date::date ) stored +``` + +然后使用它改写查询 + +```postgresql +select day as day, sum(amount) +from payment +where day between $1 and 'yesterday'::date +group by day; +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" new file mode 100644 index 0000000..eb7af25 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "daily_payment_2.md", + "notebook_enable": false, + "exercise_id": "9295152720b74c65a0236cec175f6dce" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.md" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.md" new file mode 100644 index 0000000..0dd7469 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/6.\347\264\242\345\274\225\345\222\214\344\274\230\345\214\226/daily_payment_2.md" @@ -0,0 +1,107 @@ +# 每日报表优化 + +# 每日报表 + +统计过去一段时间的数据,你发现 payment 表上每天的订单量很大,下面这个查询的统计过程占用了大多数数据库资源,查询不会 +早止当天,总是在历史上某一个日期段内查询 + +```postgresql +select payment_date::date as day, sum(amount) +from payment +where (payment_date::date) between $1 and $2 +group by payment_date::date; +``` + +payment 表的信息如下: + +```text + Table "public.payment" + Column | Type | Collation | Nullable | Default +--------------+-----------------------------+-----------+----------+--------------------------------------------- + payment_id | integer | | not null | nextval('payment_payment_id_seq'::regclass) + customer_id | smallint | | not null | + staff_id | smallint | | not null | + rental_id | integer | | not null | + amount | numeric(5,2) | | not null | + payment_date | timestamp without time zone | | not null | +Indexes: + "payment_pkey" PRIMARY KEY, btree (payment_id) +``` + +怎样做是最有效的? + +## 答案 + +建立物化视图并建立索引。 + +```postgresql +create materialized view view_daily_payment as + select payment_date::date as day, sum(amount) as amount from payment group by day; + +create index on view_daily_payment(day); + +``` + +使用 + +```postgresql +select day, amount from view_daily_payment where day between $1 and $2; +``` + +进行查询。并且每天定时执行一次刷新命令 + +```postgresql +REFRESH MATERIALIZED VIEW view_daily_payment; +``` + +## 选项 + +### 不会优化 sum 和 group by + +在 payment_date 列上建立索引 + +```postgresql +create index on payment(payment_date); +``` + +### 不会优化 sum + +建立计算列 + +```postgresql +alter table payment add day date generated always as ( payment_date::date ) stored +``` + +然后使用它改写查询 + +```postgresql +select day as day, sum(amount) +from payment +where day between $1 and 'yesterday'::date +group by day; +``` + +### 优化了日期查询,但是不会优化统计过程 + +建立表达式索引 + +```postgresql +create index on payment((payment_date::date)); +``` + +### 不做物化,对查询速度不会有显著改善 + +建立视图 + +```postgresql +create view view_daily_payment as select payment_date::date as day, amount from payment; +``` + +然后在视图 view_daily_payment 上执行 + +```postgresql +select day, sum(amount) +from view_daily_payment +where day between $1 and 'yesterday'::date +group by day +``` \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/config.json" "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/3.SQL\351\253\230\347\272\247\346\212\200\345\267\247/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/.gitkeep" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/.gitkeep" new file mode 100644 index 0000000..e69de29 diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/config.json" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/config.json" new file mode 100644 index 0000000..4e2943c --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/config.json" @@ -0,0 +1,14 @@ +{ + "node_id": "", + "keywords": [ + "数据库问答" + ], + "keywords_must": [ + "数据库问答" + ], + "keywords_forbid": [], + "children": [], + "export": [ + "qa.json" + ] +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.json" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.json" new file mode 100644 index 0000000..c6c94d3 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.json" @@ -0,0 +1,9 @@ +{ + "author": "huanhuilong", + "source": "qa.md", + "depends": [], + "type": "task_qa", + "task_link": "https://ask.csdn.net/channel/20/tag/300001", + "notebook_enable": false, + "exercise_id": "6798dddec5654cee9182e8aedfe70c2d" +} \ No newline at end of file diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.md" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.md" new file mode 100644 index 0000000..5e03394 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/1.\346\225\260\346\215\256\345\272\223\351\227\256\347\255\224/qa.md" @@ -0,0 +1,42 @@ +# 请你在问答社区回答5个数据库问题并获得采纳,证明你的能力 + +数据库用户每天会产生很多实际使用的问题。 + +任务一:请你回答5个用户提出的 [数据库问题](https://ask.csdn.net/channel/20/tag/300001),并获得采纳,证明你的能力。 + +任务二:阅读以下数据库问题,请问对数据库问答描述错误的选项是? + +* [数据库问题一](https://ask.csdn.net/questions/648654) +* [数据库问题二](https://ask.csdn.net/questions/675764) +* [数据库问题三](https://ask.csdn.net/questions/691021) + +## 答案 + +```bash +【数据库问题二】里的问题,使用 PostgreSQL 无法解决 +``` + +## 选项 + +### A + +```bash +一个好的提问包含这5个步骤中的必要部分: +1. 问题遇到的现象和发生背景 +2. 问题相关代码,请勿粘贴截图 +3. 运行结果及报错内容 +4. 我的解答思路和尝试过的方法 +5. 我想要达到的结果 +``` + +### B + +```bash +【数据库问题一】里的问题,使用 PostgreSQL 也可以解决 +``` + +### C + +```bash +【数据库问题三】里的问题,使用 PostgreSQL 也可以解决 +``` diff --git "a/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/config.json" "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/config.json" new file mode 100644 index 0000000..b89e9d8 --- /dev/null +++ "b/data/3.MySQL\351\253\230\351\230\266/4.\350\277\233\351\230\266\344\273\273\345\212\241/config.json" @@ -0,0 +1,6 @@ +{ + "node_id": "", + "keywords": [], + "keywords_must": [], + "keywords_forbid": [] +} \ No newline at end of file -- GitLab