Please simplify these SQL instructions by outlining only the essential steps. Include table names and column names wrapped in backticks, and make sure to specify any derived columns and sorting instructions clearly. Add any tips or hints that might help answer the problem statment or discover the sollution. Indicate whenever a query can be used multiple times if there are multiple Exercises to complete. Put the tips and hints at the top. Here are the instructions:
Last active
July 21, 2024 16:50
-
-
Save lundeen-bryan/139c2505e74be80c1d04976badc43f56 to your computer and use it in GitHub Desktop.
SQLsnippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define the destination directory | |
destination="$HOME/Documents" | |
# Check if destination directory exists; create it if it doesn't | |
if [ ! -d "$destination" ]; then | |
mkdir -p "$destination" | |
fi | |
# Find and copy files with the specific name pattern | |
find . -maxdepth 1 -type f -name '*Benevidez, Robert*' -exec cp {} "$destination" \; | |
echo "Files with 'Benevidez, Robert' in the filename have been copied successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Write a gpt prompt": { | |
"description": "Engineers a 5-part gpt prompt", | |
"prefix": "gpt-prompt", | |
"body": [ | |
"Take on the persona of ${1:expert persona}.", | |
"${2:verb action}.", | |
"${3:optional length and output format}.", | |
"${4:tone of voice}.", | |
"${5:target audience}." | |
] | |
}, | |
"ChatGPT Context or Primer": { | |
"description": "Insert choices that can be used in context", | |
"prefix": "gpt-context", | |
"body": [ | |
"${1|Industry,Data,Focus or questions,Topic or Theme,Constraints or Requirements,Outline or Structure,Key Points or Themes,Original Text,Editing Instructions,Context or Background Information|}" | |
] | |
}, | |
"Remove Pre-Text & Post-Text from Answer": { | |
"body": "Return only the main response. Remove pre-text and post-text.", | |
"description": "Removes the pre-text and post-text.", | |
"prefix": "gpt-dump-pre-text" | |
}, | |
"Explain to a 5th grader": { | |
"body": "Write at a ${1:5th} grade level. ${2:Use clear and simple language, even when explaining complex topics. Bias toward short sentences. Avoid jargon and acronyms.}${0}", | |
"description": "Write in a style that is easy for a 5th grader to understand.", | |
"prefix": "gpt-dumb-down" | |
}, | |
"Conversational-Relatable Writing Style": { | |
"body": "Write in a conversational, relatable style as if you were explaining something to a friend. Use natural language and phrasing that a real person would use in everyday conversations.", | |
"description": "Gives answer in a conversational, relatable writing style.", | |
"prefix": "gpt-relatable-style" | |
}, | |
"Format Using Markdown": { | |
"body": "Format your response using markdown. Use headings, subheadings, bullet points, and bold to organize the information.", | |
"description": "Return answer in markdown with subheadings, bulletpoints, bold, etc.", | |
"prefix": "gpt-markdown-answer" | |
}, | |
"Punchy Brief Writing Style": { | |
"body": "[Voice and style guide: Use sentence fragments and figurative language. Write as a master of brevity would. Frequently use short, pithy sentences that pack a punch.]", | |
"description": "Return text in a punchy breif writing style.", | |
"prefix": "gpt-punchy" | |
}, | |
"Persuasive Writing Style": { | |
"body": "Use a persuasive tone, making use of rhetorical questions, and storytelling to engage readers. Use metaphors, analogies and other literary devices to make points more relatable and memorable. Write in a way that is both informative and entertaining.", | |
"description": "Write in a persuasive style using rhetorical questions, metaphors, analogies, etc.", | |
"prefix": "gpt-persuasive" | |
}, | |
"Clarity Snippet": { | |
"body": "Use simple language to convey complex ideas so that they are clear and easy to understand. Break down complex concepts into easy-to-understand frameworks and models. Provide actionable and practical takeaways.", | |
"description": "Write complex things in simple language, break down complex topics.", | |
"prefix": "gpt-clarity" | |
}, | |
"Formal academic style": { | |
"description": "Write in a formal/academic style with sophisticated vocab", | |
"prefix": "gpt-formal", | |
"body": [ | |
"Voice and style guide: Use a formal and academic tone paired ", | |
"with sophisticated vocabulary and grammar. Provide a thorough ", | |
"and in-depth analysis of the subject matter. Explain complex ", | |
"scientific concepts in a clear and accessible way. Use examples", | |
"from a variety of fields, such as psychology and cognitive science.", | |
"Present counter-arguments and dissenting opinions in a balanced", | |
"and objective way." | |
] | |
}, | |
"Emulate a person": { | |
"body": "Emulate ${1:Ernest Hemingway's} writing style.", | |
"description": "Emulate a particular famous person's writing style.", | |
"prefix": "gpt-emulate" | |
}, | |
"Learn about": { | |
"description": "Allows you to ask for a topic to learn quiz-based", | |
"prefix": "gpt-quiz-old", | |
"body": [ | |
"[topic] = ${1:topic}", | |
"[text] = ${2:text}", | |
"I want to learn about the following is the [topic].", | |
"Just respond with \"...\" if you have read the [text]", | |
"1. Ask about a [topic] with/without context.", | |
"2. What should I start learning about from [topic]?", | |
"3. Can you give me a multiple choice quiz about [topic], one question at a time, and don't show the answer:", | |
"4. Give me a hint?", | |
"5. Show your answer.", | |
"6. Next Quiz please." | |
] | |
}, | |
"Take on the Persona of...": { | |
"body": "I would like an expert ${1:persona} perspective and opinion on ${2:topic}. ", | |
"description": "take on the persona of x", | |
"prefix": "gpt-persona" | |
}, | |
"Write Function": { | |
"description": "This will ask ChatGPT to write a function", | |
"prefix": "gpt-function", | |
"body": [ | |
"[language] = ${1:language}", | |
"[function_name] = ${2:function_name}", | |
"[context_object] = ${3:Microsoft Word}", | |
"[purpose] = ${4:purpose}", | |
"\nI want you to write a function for [context_object] in [language] for a 64-bit Windows 10 Operating System.", | |
"\n1. The purpose of this function is [purpose].", | |
"2. The name of the function should be [function_name]", | |
"3. On the next line after the name of the function, put a Numpy style docstring that uses [language] comment syntax for the following sections: Name, Description, Preconditions (including any references, APIs or libraries that need to be selected), Parameters, Returns, Example, Notes.", | |
"4. Declare all variables on the next line after the docstring.", | |
"5. All variables should be named using snake case.", | |
"6. Wrap any lines that are more than 72 characters.", | |
"7. As questions to clarify requirements before writing the function.", | |
"8. Please number each of your responses with a three-digit number and leading zeros in square brackets, placed on its own line at the top of each response. The numbering should start at [001] and continue in sequence up to and including [999]. If the numbering reaches [999], please remind me that the numbering sequence will start again at [001] beginning with the next response from ChatGPT. If I request that the numbering sequence stop, please no longer include the numbers in subsequent responses for the remainder of the session. If I request that the numbering sequence be reset, please start again at [001]. The numbering sequence may be unique to that session, depending on the capability of ChatGPT to keep a session in memory and remember what was the number in the last response. See [example] below.", | |
"\n[example] =", | |
"---start of {example}---", | |
"User: Can you tell me more about atmospheric rivers?", | |
"ChatGPT: [001] Atmospheric rivers (ARs) are long and narrow corridors of…", | |
"User: Thanks for explaining that. How do atmospheric rivers impact weather patterns?", | |
"ChatGPT: [002] When an atmospheric river makes landfall, it can result in significant…", | |
"---end of {example}---", | |
"${0}" | |
] | |
}, | |
"Next Number": { | |
"description": "Will ask ChatGPT to number the next response", | |
"prefix": "gpt-next", | |
"body": [ | |
"Number your response [${1:${TM_SELECTED_TEXT}}] at the top followed by your answer on the next line.", | |
"$0" | |
] | |
}, | |
"continue_line": { | |
"description": "prompts ChatGPT to continue from a line with string", | |
"prefix": "gpt-continue", | |
"body": [ | |
"CONTINUE_LINE =${1:text from last line}", | |
"Please continue from the line that says CONTINUE_LINE and place the text in a Markdown codeblock. When all code has been completed, please write \"Refactoring finished.\" outside of the Markdown codeblock." | |
] | |
}, | |
"generate-quiz": { | |
"description": "generate a quiz based on a topic with inputs", | |
"prefix": "gpt-quiz", | |
"body": [ | |
"[USER] = ${1:user}", | |
"[DOMAIN] = ${2:domain}", | |
"[TOPIC] = ${3:topic}", | |
"[SUBTOPIC] = ${4:subtopic}", | |
"[NUMBER OF QUESTIONS] = ${5:5}", | |
"[NUMBER OF CHOICES] = ${6:4}", | |
"\nPlease create a quiz on the subject of [DOMAIN] [TOPIC] with [NUMBER OF QUESTIONS] questions and [NUMBER OF CHOICES] outcomes and show the results. Quiz me specifically on the subject of [SUBTOPIC].", | |
"\nUse the following example for creating the quiz:", | |
"```", | |
"[USER]:", | |
"Please create a quiz on the subject of [DOMAIN] [TOPIC] with [NUMBER OF QUESTIONS] questions and [NUMBER OF CHOICES] outcomes and show the results. Quiz me specifically on the subject of [SUBTOPIC]. And place the quiz questions inside a Markdown codeblock.", | |
"[DOMAIN] = Python", | |
"[TOPIC] = set function", | |
"[SUBTOPIC] = using \"len\", \"add\", and \"update\" methods.", | |
"[NUMBER OF QUESTIONS] = 5", | |
"[NUMBER OF CHOICES] = 4", | |
"\n[BOT]:", | |
"Here is a quiz on the subject of the Python ", | |
" function:", | |
"\n```", | |
"1. What does the ", | |
" method do in a set in Python?", | |
"a) It returns the number of elements in a set", | |
"b) It adds an element to a set", | |
"c) It removes an element from a set", | |
"d) It updates the elements in a set", | |
"\n2. What does the ", | |
" method do in a set in Python?", | |
"a) It returns the number of elements in a set", | |
"b) It adds an element to a set", | |
"c) It removes an element from a set", | |
"d) It updates the elements in a set", | |
"\n3. What does the ", | |
" method do in a set in Python?", | |
"a) It returns the number of elements in a set", | |
"b) It adds an element to a set", | |
"c) It removes an element from a set", | |
"d) It updates the elements in a set", | |
"\n4. How do you add multiple elements to a set at once using the ", | |
" method in Python?", | |
"a) By passing a list of elements as an argument", | |
"", | |
"c) By passing a tuple of elements as an argument", | |
"d) By passing a dictionary of elements as an argument", | |
"\n5. How do you find the union of two sets in Python?", | |
"a) By using the ", | |
" method", | |
"b) By using the ", | |
" method", | |
"c) By using the ", | |
" method", | |
"d) By using the union method or the ", | |
" operator", | |
"```", | |
"\nHere are the correct answers:", | |
"1. a", | |
"2. b", | |
"3. d", | |
"4. a", | |
"5. d", | |
"\nplease let me know when you're ready to start the quiz.", | |
"```" | |
] | |
}, | |
"rate a prompt": { | |
"description": "let ChatGPT rate your prompt and give suggestions for improvement", | |
"prefix": "gpt-rate", | |
"body": [ | |
"Can you rate a prompt using the following ChatGPT grading rubric for grading user prompts?", | |
"", | |
"| Criteria | Description | Maximum Points | Rating | Letter Grade |", | |
"| -------- | -----------| --------------| ------ | ------------ |", | |
"| Clarity | The prompt is easy to understand and concise. | 15 | | |", | |
"| Relevance | The prompt is appropriate to the context or topic at hand. | 10 | | |", | |
"| Completeness | The prompt provides all the necessary information for a meaningful response. | 15 | | |", | |
"| Specificity | The prompt is specific enough to elicit a detailed and accurate response. | 15 | | |", | |
"| Grammar | The prompt is free of grammatical errors and typos. | 10 | | |", | |
"| Contextual awareness | The prompt takes into account the current conversation or previous responses. | 15 | | |", | |
"| Uniqueness | The prompt is original and not a duplicate of previous prompts. | 5 | | |", | |
"| Sensitivity | The prompt shows sensitivity towards potentially sensitive topics or groups. | 10 | | |", | |
"| Domain knowledge | The prompt shows basic domain knowledge on the topic at hand. | 5 | | |", | |
"| Total | | 100 | | |", | |
"", | |
"The letter grade in the last column is based on the following letter grade rubric:", | |
"", | |
"| Letter Grade | Point Range | Description |", | |
"| ------------ | ----------- | ----------- |", | |
"| A+ | 97-100 | Excellent, outstanding performance |", | |
"| A | 93-96 | Very good, above-average performance |", | |
"| A- | 90-92 | Good, solid performance |", | |
"| B+ | 87-89 | Above average, satisfactory performance |", | |
"| B | 83-86 | Average, satisfactory performance |", | |
"| B- | 80-82 | Below average, but passing performance |", | |
"| C+ | 77-79 | Fair, minimally acceptable performance |", | |
"| C | 73-76 | Poor, barely passing performance |", | |
"| C- | 70-72 | Very poor, unsatisfactory performance |", | |
"| D+ | 67-69 | Barely passing, but below minimum performance |", | |
"| D | 63-66 | Failing, very poor performance |", | |
"| D- | 60-62 | Failing, extremely poor performance |", | |
"| F | 0-59 | Failing, no credit earned |", | |
"", | |
"The point ranges are based on a distribution of scores and are aligned with the maximum points available in the ChatGPT grading rubric. The descriptions provide a general sense of the quality of performance associated with each letter grade." | |
] | |
}, | |
"README.md Generator Prompt": { | |
"prefix": "gpt-readmePrompt", | |
"body": [ | |
"Note: see the md file Guide to gpt-readmePrompt Fields", | |
"ChatGPT, can you help me write a README.md for a GitHub Data Analysis project called '${1:projectName}'?", | |
"This is a ${2:projectStatus|Concept/Idea,Planning/Design,Development/Alpha,Beta,Release Candidate,Production/Stable,Maintenance,Deprecated,Archived|} project developed in Jupyter Notebook using ${3:programmingLanguages}.", | |
"The project provides ${4:projectDescription}.", | |
"The data used in this project is sourced from ${5:dataSources}.", | |
"The file structure of the project is as follows: ${6:fileStructure}.", | |
"For setup, ${7:setupInstructions}.", | |
"Usage instructions for the project are as follows: ${8:usageInstructions}.", | |
"The project ${9:isAcceptingContributions|is, is not|} currently accepting contributions. ${10:additionalContributionDetails}", | |
"The project is licensed under the ${11:license|MIT License,Apache License 2.0,GNU General Public License (GPL),GNU Lesser General Public License (LGPL),Mozilla Public License 2.0,BSD Licenses,Creative Commons Licenses,Unlicense,No License|}.", | |
"For more information, they can contact me at ${12:contactInformation}.", | |
"The project has been developed with help from ${13:creditsAndAcknowledgments}.", | |
"The key findings of the data analysis are as follows: ${14:keyFindings}.", | |
"For reproducibility, the versions of the software used are as follows: ${15:softwareVersions}." | |
], | |
"description": "Generate a prompt for ChatGPT to create a README.md file" | |
}, | |
"comment_block": { | |
"prefix": "comment-block", | |
"body": [ | |
"<!--" | |
"===========================================" | |
"= ${1:Section comment block} =" | |
"===========================================" | |
"-->" | |
"" | |
"" | |
"<!-- ======= End of ${1} ======= -->" | |
] | |
"description": "creates a comment block in markdown" | |
}, | |
"Insert Image": { | |
"prefix": "b'imgtag", // Trigger text for the snippet | |
"body": [ | |
"<img src="${1:image_url}" width="800" height="500">" | |
], | |
"description": "Inserts an HTML image tag with specified dimensions" | |
} | |
"Observations and Steps": { | |
"prefix": "obs-steps", | |
"body": [ | |
"### Observations", | |
"- Target Table: ${1:table}", | |
"- Key Column: ${2:column}", | |
"- Involved Tables: ${3:table1,table2}", | |
"- Relevant Columns: ${4:column1,column2}", | |
"- Single Column Operation: ${5:YES|NO|}", | |
"- __Keywords__", | |
"- ORDER BY: ${6:YES|NO|}", | |
"- Aggregation Functions: ${7|None, SUM, AVG, MIN, MAX, COUNT|}", | |
"- Grouping: ${8|None, Group by|} ${9:column}", | |
"- Query Approach: ${10|Subquery, CTE, Correlated query|}", | |
"- Window Functions: ${11|None, ROW_NUMBER, RANK, DENSE_RANK, LEAD, LAG, Running SUM, Running AVG|}", | |
"- ", | |
"\n### Steps", | |
"- Querying strategy based on: ${10}.", | |
"- Window function if any: ${11}.", | |
"1. Start with ${1} and include ${2}.", | |
"2. join string: ${12:table1,table2}." | |
], | |
"description": "Generates a template for analyzing SQL problem statements" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Tips":{ | |
"prefix": "b'sqltips", | |
"body": [ | |
"--Sweaty(SELECT) Feet(FROM) Will(WHERE) Give(GROUP BY) Horrible(HAVING) Oder(ORDER BY)", | |
"--SELECT", | |
"--FROM", | |
"--WHERE", | |
"--GROUP BY", | |
"--HAVING", | |
"--ORDER BY", | |
"--", | |
"----Limitations of CTEs", | |
"--1. CTEs can only be used in the current query scope, meaning they cannot be referenced after the final SELECT", | |
"--2. This can be a problem if you need to reuse your virtual tables multi times for diff purposes", | |
"--3. cannot be referenced individually, making degugging more difficult", | |
"--4. certain optimization techniques are not available to CTEs", | |
"--SQL Join Types PDF" | |
], | |
"description": "Puts tips in comments" | |
}, | |
"Find datatype in column":{ | |
"prefix": "b'find_datatype", | |
"body": [ | |
"SELECT table_schema, table_name, collumn_name, data_type, collation_name", | |
"FROM INFORMATION_SCHEMA.COLUMNS", | |
"WHERE 1=WHERE 1=1", | |
"AND TABLE_SCHEMA = [${1:schema-name}] AND TABLE_NAME = [${2:table-name}];", | |
"--If the collation_name has CI in it then it is case insensitive" | |
], | |
"description": "inserts method to find data type of column" | |
}, | |
"Find Column By Name":{ | |
"prefix": "b'find_column", | |
"body": [ | |
"SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE 1=1 AND COLUMN_NAME LIKE '%${1:column_name}%' ORDER BY TABLE_NAME", | |
], | |
"description": "asks for column name and will find it in any db table" | |
}, | |
"Find Table by Name":{ | |
"prefix": "b'find_table", | |
"body": [ | |
"SELECT [Table Names] = [name] FROM SYS.TABLES" | |
], | |
"description": "asks for table name to search for word in table name." | |
}, | |
"Find Schema by Name":{ | |
"prefix": "b'find_schema", | |
"body": [ | |
"SELECT ${1|SCHEMA_NAME, SCHEMA_ID, SCHEMA_OWNER, SCHEMA_DESCRIPTION|}", | |
"FROM INFORMATION_SCHEMA.SCHEMATA", | |
"WHERE 1=1 AND SCHEMA_NAME LIKE '%${2:schema_name}%' ORDER BY SCHEMA_NAME" | |
], | |
"description": "snippet to find schema by name" | |
}, | |
"Setup SQL Query": { | |
"prefix": "b'Setup_sql", | |
"body": [ | |
"USE [${2:database_name}]", | |
"GO\n", | |
"--/* ${8:ref-number} ", | |
"SELECT", | |
"$4.${6:column} AS ${7:alias}", | |
"FROM", | |
" ${3:schema}.${4:table} AS ${5:table_alias}", | |
"WHERE 1=1", | |
";", | |
"--*/", | |
"\n\n", | |
"$BLOCK_COMMENT_START", | |
"\tFilename: ...: $TM_FILENAME", | |
"\tDate ........: $CURRENT_DATE-$CURRENT_MONTH_NAME_SHORT-$CURRENT_YEAR", | |
"\tTime ........: $CURRENT_HOUR:$CURRENT_MINUTE", | |
"\tDesc ........: ${1:description}", | |
"\tNotes........:", | |
"\t\t1. ", | |
"$BLOCK_COMMENT_END", | |
"\nGO" | |
], | |
"description": "Creates a SQL query with a comment block" | |
}, | |
"Add new Select statement":{ | |
"prefix": "b'select", | |
"body": [ | |
"--/* ${6:ref-number} ", | |
"SELECT", | |
"$3.${4:column} AS ${5:alias}", | |
"FROM", | |
" ${1:schema}.${2:table} AS ${3:table_alias}", | |
"WHERE 1=1", | |
";", | |
"--*/", | |
"\n" | |
], | |
"description": "Adds Select Statement without comments or source" | |
}, | |
"Select Count One-Line":{ | |
"prefix": "b'count", | |
"body": [ | |
"SELECT COUNT(*) FROM ${1:schema}.${2:table}", | |
], | |
"description": "Insert a one-line SELECT" | |
}, | |
"Select all One-Line":{ | |
"prefix": "b'star", | |
"body": [ | |
"SELECT * FROM ${1:schema}.${2:table}" | |
], | |
"description": "Insert a one-line SELECT all columns" | |
}, | |
"Select all One-Line":{ | |
"prefix": "b'ss-simple-select", | |
"body": [ | |
"SELECT ${2:column} FROM ${1:table}", | |
"${0}" | |
], | |
"description": "Insert a one-line SELECT statement" | |
}, | |
"Where in subquery":{ | |
"prefix": "b'where-in-subquery", | |
"body": [ | |
" WHERE ${1:column} ${2:IN|=|NOT IN|}", | |
" (SELECT ${1} FROM ${3:table}", | |
" ${0}", | |
" )" | |
], | |
"description": "Insert a one-line SELECT statement" | |
}, | |
"Select all One-Line-more":{ | |
"prefix": "b'ssm-simple-select-more", | |
"body": [ | |
"WHERE 1=1", | |
"GROUP BY ${1:column}", | |
"HAVING 1=1", | |
"ORDER BY ${2:column} ${3:ASC|DESC}", | |
], | |
"description": "Insert a one-line SELECT all columns" | |
}, | |
"Add Join":{ | |
"prefix": "b'join", | |
"body": [ | |
"${1|INNER,LEFT OUTER,FULL OUTER,RIGHT OUTER|} JOIN", | |
"${2:table} AS ${3:table_alias}", | |
"ON", | |
" ${4:alias1}.${5:table1} = $3.$5" | |
], | |
"description": "Inserts a new join" | |
}, | |
"Insert a simple derived column subquery":{ | |
"prefix": "b'sub1-derived-column", | |
"body": [ | |
", (", | |
"SELECT ${5:COUNT(*)}", | |
"FROM ${1:schema}.${2:table} AS ${3:innerAlias}", | |
") AS ${4:derivedColumn}", | |
], | |
"description": "Inserts a subquery, for single value column" | |
}, | |
"Create a correlated subquery": { | |
"prefix": "b'correlated-sub", | |
"body": [ | |
"SELECT ${4}.${6:column}", | |
"FROM ${3:outer_table} AS ${4:outer_alias}", | |
"WHERE EXISTS (", | |
"SELECT *", | |
"FROM ${1:inner_table} AS ${2:innerAlias}", | |
"WHERE ${4}.${5:joinColumn} = ${2}.${5}", | |
")" | |
], | |
"description": "Inserts a correlated subquery with a WHERE clause" | |
}, | |
"Create subquery in select": { | |
"prefix": "b'sub3-correlated-simpler", | |
"body": [ | |
"(", | |
"SELECT *", | |
"FROM ${1}", | |
"WHERE ${2:table} = ${3:filterTable}", | |
") AS ${4:derivedColumn}" | |
], | |
"description": "Inserts a correlated subquery with a WHERE clause" | |
}, | |
"Simple subquery in join":{ | |
"prefix": "b'sub4-in-join", | |
"body": [ | |
"${1|INNER,LEFT OUTER,FULL OUTER,RIGHT OUTER|} JOIN", | |
"(", | |
"SELECT ${3:column} FROM ${2:table}", | |
") AS ${4:derivedColumn}", | |
"USING(${5:column})", | |
"${0}" | |
], | |
"description": "Inserts a subquery in the join clause" | |
}, | |
"Create subquery in select": { | |
"prefix": "b'sub5-scalar", | |
"body": [ | |
"WHERE (", | |
"SELECT ${1|SUM,AVG,COUNT,MIN,MAX|}(${2:column})", | |
"FROM ${2}", | |
"WHERE ${2:newTable}.${3:column} = ${4:filterTable}.${3}", | |
") ${5|<,>,=|} ${6:derivedValue}" | |
], | |
"description": "Inserts a scalar subquery, to use as filter" | |
}, | |
"Cut current query and insert as inner":{ | |
"prefix": "b'sub6-paste-as-inner", | |
"body": [ | |
"SELECT", | |
" *", | |
"FROM (", | |
"$CLIPBOARD", | |
") AS ${1:derivedColumn}", | |
"WHERE ${2:filter} = ${3:value}", | |
"\n" | |
], | |
"description": "Inserts a subquery, to use as filter" | |
}, | |
"Create correlated subquery in select": { | |
"prefix": "b'sub7-correlated", | |
"body": [ | |
",(", | |
"SELECT *", | |
"FROM ${1:inner_table} AS ${2:inner_alias}", | |
"WHERE ${2}.${3:table} = ${3:outer_alias}.${3}", | |
") AS ${4:derivedColumn}" | |
] | |
} | |
"Create scalar subquery": { | |
"prefix": "b'sub-scalar", | |
"body": [ | |
"SELECT ${1|SUM,AVG,COUNT,MIN,MAX|}(${2:column}) AS ${3:derivedColumn}", | |
"FROM ${4:table}" | |
], | |
"description": "Inserts a scalar subquery that returns a single value based on specified conditions" | |
}, | |
"Pivot":{ | |
"prefix": "b'pivot_single", | |
"body": [ | |
"\n", | |
"--/*", | |
"SELECT [${9}]", | |
"\t,[${10}]", | |
"\tFROM (SELECT [${4:source tbl column 1}]", | |
"\t\t\t, [${5:source tbl column 2}]", | |
"\t\tFROM [${1:source schema}].[${2:source tbl}]) AS ${3:alias}", | |
"\t\tPIVOT(${6|SUM,AVG,MAX,MIN|}([${7:aggregate column}])", | |
"\t\tFOR [${8:column contains headers}]", | |
"\t\tIN([${9:pivot column 1}], [${10:pivot column 2}])) AS ${11:alias}", | |
"ORDER BY 1", | |
"--*/", | |
"\n" | |
] | |
}, | |
"Case Statement": { | |
"prefix": "b'case_setup", | |
"body": [ | |
"CASE", | |
"\tWHEN ${1:first_when}", | |
"\t\tTHEN ${2:then_this}", | |
"\tELSE ${3:else_this}", | |
"END AS [${4:first_case}]" | |
], | |
"description": "Inserts Case-When-Else Statement" | |
}, | |
"When Statement": { | |
"prefix": "b_when", | |
"body": [ | |
"WHEN ${1:when_statement}", | |
"\tTHEN ${2:then_statement}" | |
], | |
"description": "Inserts when-then statement" | |
}, | |
"Insert CTE": { | |
"prefix": "b'cte_sql", | |
"body": [ | |
"--/*", | |
"WITH", | |
"Step1 AS (", | |
" -- This CTE step extracts necessary columns from a specified table", | |
" SELECT ${3:column1}, ${4:column2}, ...", | |
" FROM ${1:schema}.${2:table}", | |
" WHERE ${5:condition} -- Optional: specify conditions", | |
"),", | |
"Step2 AS (", | |
" -- This CTE step processes data from Step1", | |
" SELECT ${6:agg_func}(${3:column1}) AS ${7:alias1}, ${4:column2}", | |
" FROM Step1", | |
" GROUP BY ${4:column2} -- Optional: Adjust grouping as necessary", | |
"),", | |
"-- Final SELECT to retrieve data from the last CTE step", | |
"SELECT", | |
" ${7:alias1}, ${4:column2}", | |
"FROM Step1 AS A", | |
"JOIN Step2 AS B -- Adjust join type and conditions based on requirements", | |
"ON A.${8:matching_column} = B.${8:matching_column}", | |
"ORDER BY ${9:order_column} -- Replace '1' with specific column name or alias", | |
"--*/" | |
], | |
"description": "Inserts a structured Common Table Expression (CTE) for SQL queries in VSCode." | |
}, | |
"Insert Date Series":{ | |
"prefix": "b'date_series", | |
"body": [ | |
"WITH", | |
"[DateSeries] AS (SELECT CAST('${1:starting date mm-dd-yyyy}' AS DATE) AS [${3:column_name}]", | |
"UNION ALL", | |
"SELECT DATEADD(DAY, 1, [$3])", | |
"FROM [DateSeries]", | |
"WHERE 1=1", | |
"AND [$3] < CAST('${2:end date mm-dd-yyyy}' AS DATE))", | |
"SELECT [$3]", | |
"FROM [DateSeries]", | |
"OPTION(MAXRECURSION 365)" | |
], | |
"description": "Inserts dates in a series" | |
}, | |
"Insert Number Series":{ | |
"prefix": "b'number_series", | |
"body": [ | |
"WITH", | |
"[NumberSeries] AS (SELECT 1 AS [MyNumber]", | |
"UNION ALL", | |
"SELECT [MyNumber] + 1", | |
"FROM [NumberSeries]", | |
"WHERE 1=1", | |
"AND [MyNumber] < ${1:max_number})", | |
"SELECT [MyNumber]", | |
"FROM [NumberSeries]", | |
"OPTION(MAXRECURSION $1)" | |
], | |
"description": "Inserts numbers in a series" | |
}, | |
"sql-codeblock": { | |
"prefix": "b'codeblock", | |
"body": "--/*\r\n\r\n--*/", | |
"description": "creates a sql codeblock" | |
}, | |
"count_only": { | |
"prefix": "b'count-only", | |
"body": "COUNT(${1:object}) AS ${2:alias}", | |
"description": "just adds a count function" | |
}, | |
"Window Function": { | |
"prefix": "b'winfunction", | |
"body": [ | |
"${1|ROW_NUMBER,RANK,DENSE_RANK,NTILE,LEAD,LAG,FIRST_VALUE,LAST_VALUE,PERCENT_RANK|}() OVER (", | |
"\tPARTITION BY ${2:partition_column} ORDER BY ${3:order_column} ${4|ASC,DESC|}", | |
"\tROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING", | |
") AS ${5:column_alias}" | |
], | |
"description": "Inserts a window function" | |
}, | |
"create id column": { | |
"prefix": "b'create-id-column", | |
"body": "${1:id} INT UNSIGNED AUTO_INCREMENT PRIMARY KEY", | |
"description": "Adds an id column to a table" | |
}, | |
"join one line": { | |
"prefix": "b1'join", | |
"body": "INNER JOIN ${1:table} USING(${2:column})", | |
"description": "single line inner join statement using" | |
}, | |
"Insert Image": { | |
"prefix": "b'imgtag", // Trigger text for the snippet | |
"body": [ | |
"<img src="${1:image_url}" width="800" height="500">" | |
], | |
"description": "Inserts an HTML image tag with specified dimensions" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment