{"id":20064091,"url":"https://github.com/sagframe/sqltoy-online-doc","last_synced_at":"2025-06-23T16:41:38.406Z","repository":{"id":103366259,"uuid":"247022189","full_name":"sagframe/sqltoy-online-doc","owner":"sagframe","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-05T05:38:17.000Z","size":299,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T22:43:48.804Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagframe.png","metadata":{"files":{"readme":"docs/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-13T08:26:21.000Z","updated_at":"2024-09-05T05:38:20.000Z","dependencies_parsed_at":"2023-07-08T19:46:01.953Z","dependency_job_id":"95fdc416-be87-463a-91bf-ed6c98a9f166","html_url":"https://github.com/sagframe/sqltoy-online-doc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagframe%2Fsqltoy-online-doc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagframe%2Fsqltoy-online-doc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagframe%2Fsqltoy-online-doc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagframe%2Fsqltoy-online-doc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagframe","download_url":"https://codeload.github.com/sagframe/sqltoy-online-doc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241494142,"owners_count":19971870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:44:45.442Z","updated_at":"2025-03-02T10:40:59.111Z","avatar_url":"https://github.com/sagframe.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# 文档阅读导航\n\n\u003e 欢迎使用和交流sqltoy-orm，请点击左侧导航栏开始了解sqltoy!\n\n# QQ技术交流群:531812227\n\n# 详细文档见:sagacity-sqltoy/docs/睿智平台SqlToy5.6使用手册.doc\n\n# 1. 感受sqltoy之美--缓存翻译、缓存条件检索\n\n* 缓存翻译和缓存检索化繁为简---查询订单表(简化为单商品订单便于演示)\n\n订单号|客户ID|商品ID|下单日期|商品数量|商品价格|订单金额|订单状态|业务员ID|部门\n------|------|-----|-----|-----|-----|----|---|----|----\nS0001|C10001|101|2020-03-10|10|3000|30000|02|1001|N002\n\n\n* 要求查询日期在2020年1月10日至3月20日、客户名称中含\u003c\u003c星云科技\u003e\u003e字符的全部订单信息，要求显示商品名称、客户名称、业务员姓名、部门名称、订单状态中文\n\n* 往常的做法:硬功夫硬碰硬系列\n\n\u003e 关联客户表做like\n\n\u003e 关联商品表查询品名\n\n\u003e 关联员工信息表显示员工名字\n\n\u003e 关联机构表显示机构名称\n\n\u003e 关联数据字典翻译状态\n\n* 你是这么做的吗?看一下sqltoy怎么做吧！是不是变成了单表查询，效率毫无疑问秒杀多表关联无数倍!\n```xml\n\u003csql id=\"order_showcase\"\u003e\n\t\u003c!-- 通过缓存对最终结果代码进行翻译，显示名称 --\u003e\n\t\u003ctranslate cache=\"organIdName\" columns=\"ORGAN_NAME\" /\u003e\n\t\u003ctranslate cache=\"staffIdName\" columns=\"STAFF_NAME\" /\u003e\n\t\u003ctranslate cache=\"goodsIdName\" columns=\"GOODS_NAME\" /\u003e\n\t\u003ctranslate cache=\"customIdName\" columns=\"CUSTOM_NAME\" /\u003e\n\t\u003ctranslate cache=\"dictKeyName\" cache-type=\"ORDER_STATUS\" columns=\"STATUS_NAME\" /\u003e\n\t\u003cfilters\u003e\n\t\t\u003c!-- 将查询参数customName通过缓存进行类似like检索获取匹配的customId数组作为查询条件 --\u003e\n\t\t\u003ccache-arg cache-name=\"customIdName\" param=\"customName\"\talias-name=\"customIds\" /\u003e\n\t\u003c/filters\u003e\n\t\u003cvalue\u003e\n\t\u003c![CDATA[\n\tselect\n\t\tORDER_ID ,\n\t\tTOTAL_QUANTITY,\n\t\tTOTAL_AMT,\n\t\tORGAN_ID ,\n\t\tORGAN_ID ORGAN_NAME,-- 缓存翻译\n\t\tSTAFF_ID ,\n\t\tSTAFF_ID STAFF_NAME,\n\t\tSIGN_TIME,\n\t\tCUSTOM_ID,\n\t\tCUSTOM_ID CUSTOM_NAME,\n\t\tGOODS_ID ,\n\t\tGOODS_ID GOODS_NAME,\n\t\tSTATUS,\n\t\tSTATUS STATUS_NAME\n\tfrom od_order_info t1\n\twhere #[SIGN_TIME\u003e=:beginTime]\n\t      #[and SIGN_TIME \u003c=:endTime]\n\t      -- 这里就是缓存条件检索\n\t      #[and CUSTOM_ID in (:customIds)]\n\t]]\u003e\n\t\u003c/value\u003e\n\u003c/sql\u003e\n```\n# 2. 感受sqltoy之美--数据旋转\n* 水果销售记录表\n\n品类|销售月份|销售笔数|销售数量(吨)|销售金额(万元)\n----|-------|-------|----------|------------\n苹果|2019年5月|12 | 2000|2400\n苹果|2019年4月|11 | 1900|2600\n苹果|2019年3月|13 | 2000|2500\n香蕉|2019年5月|10 | 2000|2000\n香蕉|2019年4月|12 | 2400|2700\n香蕉|2019年3月|13 | 2300|2700\n\n* sqltoy 实现行转列(category-columns 支持多列,即多维度分组如:\n\u003e 月份下面:5月(上旬、中旬、下旬)、4月(上旬、中旬、下旬)\n\n\u003e 电子产品例如: 手机(华为、三星、小米)、笔记本(苹果、联想、戴尔))\n\n```xml\n\u003c!-- 列转行 --\u003e\n\u003csql id=\"pivot_case\"\u003e\n\t\u003cvalue\u003e\n\t\u003c![CDATA[\n\tselect t.fruit_name,t.order_month,t.sale_count,t.sale_quantity,t.total_amt \n\tfrom sqltoy_fruit_order t\n\torder by t.fruit_name ,t.order_month\n\t]]\u003e\n\t\u003c/value\u003e\n\t\u003c!-- 行转列,将order_month作为分类横向标题，从sale_count列到total_amt 三个指标旋转成行 --\u003e\n\t\u003cpivot start-column=\"sale_count\" end-column=\"total_amt\"\tgroup-columns=\"fruit_name\" category-columns=\"order_month\" /\u003e\n\u003c/sql\u003e\n```\n* 效果:简单一个pivot代替了复杂的sql，而且不用考虑不同数据库的实现差异\n\n\u003ctable\u003e\n\u003cthead\u003e\n\t\u003ctr\u003e\n\t\u003cth rowspan=\"2\"\u003e品类\u003c/th\u003e\n\t\u003cth colspan=\"3\"\u003e2019年3月\u003c/th\u003e\n\t\u003cth colspan=\"3\"\u003e2019年4月\u003c/th\u003e\n\t\u003cth colspan=\"3\"\u003e2019年5月\u003c/th\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t    \u003cth\u003e笔数\u003c/th\u003e\u003cth\u003e数量\u003c/th\u003e\u003cth\u003e总金额\u003c/th\u003e\n\t    \u003cth\u003e笔数\u003c/th\u003e\u003cth\u003e数量\u003c/th\u003e\u003cth\u003e总金额\u003c/th\u003e\n\t    \u003cth\u003e笔数\u003c/th\u003e\u003cth\u003e数量\u003c/th\u003e\u003cth\u003e总金额\u003c/th\u003e\n\t\u003c/tr\u003e\n\t\u003c/thead\u003e\n\t\u003ctbody\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003e香蕉\u003c/td\u003e\n\t\t\u003ctd\u003e13\u003c/td\u003e\n\t\t\u003ctd\u003e2300\u003c/td\u003e\n\t\t\u003ctd\u003e2700\u003c/td\u003e\n\t\t\u003ctd\u003e12\u003c/td\u003e\n\t\t\u003ctd\u003e2400\u003c/td\u003e\n\t\t\u003ctd\u003e2700\u003c/td\u003e\n\t\t\u003ctd\u003e10\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\u003ctd\u003e苹果\u003c/td\u003e\n\t\t\u003ctd\u003e13\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e2500\u003c/td\u003e\n\t\t\u003ctd\u003e11\u003c/td\u003e\n\t\t\u003ctd\u003e1900\u003c/td\u003e\n\t\t\u003ctd\u003e2600\u003c/td\u003e\n\t\t\u003ctd\u003e12\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e2400\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003c/tbody\u003e\n\u003c/table\u003e\n\n# 3. 感受sqltoy之美--分组汇总\n* 还是上面的苹果销售表格\n```xml\n\u003c!-- 演示分组汇总 --\u003e\n\u003csql id=\"group_summary_case\"\u003e\n\t\u003cvalue\u003e\n\t\t\u003c![CDATA[\n\t\tselect t.fruit_name,t.order_month,t.sale_count,t.sale_quantity,t.total_amt \n\t\tfrom sqltoy_fruit_order t\n\t\torder by t.fruit_name ,t.order_month\n\t\t]]\u003e\n\t\u003c/value\u003e\n\t\u003c!-- reverse 是否反向 --\u003e\t\n\t\u003csummary sum-columns=\"sale_count,sale_quantity,total_amt\" reverse=\"true\"\u003e\n\t\t\u003c!-- 层级顺序保持从高到低 --\u003e\n\t\t\u003cglobal sum-label=\"总计\" label-column=\"fruit_name\" /\u003e\n\t\t\u003cgroup group-column=\"fruit_name\" sum-label=\"小计\" label-column=\"fruit_name\" /\u003e\n\t\u003c/summary\u003e\n\u003c/sql\u003e\n```\n* 效果\n\n品类|销售月份|销售笔数|销售数量(吨)|销售金额(万元)\n----|-------|-------|----------|------------\n总计|       |   71  |    12600 |14900\n小计|       |  36  | 5900   | 7500\n苹果|2019年5月|12 | 2000|2400\n苹果|2019年4月|11 | 1900|2600\n苹果|2019年3月|13 | 2000|2500\n小计|       | 35  | 6700|7400\n香蕉|2019年5月|10 | 2000|2000\n香蕉|2019年4月|12 | 2400|2700\n香蕉|2019年3月|13 | 2300|2700\n\n# 4. 感受sqltoy之美--环比计算\n* 演示先行转列再环比计算\n```xml\n\u003c!-- 列与列环比演示 --\u003e\n\u003csql id=\"cols_relative_case\"\u003e\n\t\u003cvalue\u003e\n\t\u003c![CDATA[\n\t\tselect t.fruit_name,t.order_month,t.sale_count,t.sale_amt,t.total_amt \n\t\tfrom sqltoy_fruit_order t\n\t\torder by t.fruit_name ,t.order_month\n\t]]\u003e\n\t\u003c/value\u003e\n\t\u003c!-- 数据旋转,行转列,将order_month 按列显示，每个月份下面有三个指标 --\u003e\n\t\u003cpivot start-column=\"sale_count\" end-column=\"total_amt\"\tgroup-columns=\"fruit_name\" category-columns=\"order_month\" /\u003e\n\t\u003c!-- 列与列之间进行环比计算 --\u003e\n\t\u003ccols-chain-relative group-size=\"3\" relative-indexs=\"1,2\" start-column=\"1\" format=\"#.00%\" /\u003e\n\u003c/sql\u003e\n```\n* 效果\n\n\u003ctable\u003e\n\u003cthead\u003e\n\t\u003ctr\u003e\n\t\u003cth rowspan=\"2\" nowrap=\"nowrap\"\u003e品类\u003c/th\u003e\n\t\u003cth colspan=\"5\"\u003e2019年3月\u003c/th\u003e\n\t\u003cth colspan=\"5\"\u003e2019年4月\u003c/th\u003e\n\t\u003cth colspan=\"5\"\u003e2019年5月\u003c/th\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t    \u003cth nowrap=\"nowrap\"\u003e笔数\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e数量\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e总金额\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\n\t    \u003cth nowrap=\"nowrap\"\u003e笔数\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e数量\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e总金额\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\n\t    \u003cth nowrap=\"nowrap\"\u003e笔数\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e数量\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e总金额\u003c/th\u003e\u003cth nowrap=\"nowrap\"\u003e比上月\u003c/th\u003e\n\t\u003c/tr\u003e\n\t\u003c/thead\u003e\n\t\u003ctbody\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003e香蕉\u003c/td\u003e\n\t\t\u003ctd\u003e13\u003c/td\u003e\n\t\t\u003ctd\u003e2300\u003c/td\u003e\n\t\t\u003ctd\u003e\u003c/td\u003e\n\t\t\u003ctd\u003e2700\u003c/td\u003e\n\t\t\u003ctd\u003e\u003c/td\u003e\n\t\t\u003ctd\u003e12\u003c/td\u003e\n\t\t\u003ctd\u003e2400\u003c/td\u003e\n\t\t\u003ctd\u003e4.30%\u003c/td\u003e\n\t\t\u003ctd\u003e2700\u003c/td\u003e\n\t\t\u003ctd\u003e0.00%\u003c/td\u003e\n\t\t\u003ctd\u003e10\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e-16.70%\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e-26.00%\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\t\u003ctr\u003e\n\t\t\u003ctd\u003e苹果\u003c/td\u003e\n\t\t\u003ctd\u003e13\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e\u003c/td\u003e\n\t\t\u003ctd\u003e2500\u003c/td\u003e\n\t\t\u003ctd\u003e\u003c/td\u003e\n\t\t\u003ctd\u003e11\u003c/td\u003e\n\t\t\u003ctd\u003e1900\u003c/td\u003e\n\t\t\u003ctd\u003e-5.10%\u003c/td\u003e\n\t\t\u003ctd\u003e2600\u003c/td\u003e\n\t\t\u003ctd\u003e4.00%\u003c/td\u003e\n\t\t\u003ctd\u003e12\u003c/td\u003e\n\t\t\u003ctd\u003e2000\u003c/td\u003e\n\t\t\u003ctd\u003e5.20%\u003c/td\u003e\n\t\t\u003ctd\u003e2400\u003c/td\u003e\n\t\t\u003ctd\u003e-7.70%\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003c/tbody\u003e\n\u003c/table\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagframe%2Fsqltoy-online-doc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagframe%2Fsqltoy-online-doc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagframe%2Fsqltoy-online-doc/lists"}