SQL column
Summary of basic knowledge of SQL database
Summary of advanced knowledge of SQL database
Total text: 956 words Estimated reading time: 3 minutes
Add column
Common added columns include adding custom columns, adding index columns, adding duplicate columns, and you can also add some attribute columns based on existing data, such as character length, first character, etc.
Example
We take the Customers table as an example table, as shown in the following figure
Add custom column
Adding custom columns is generally based on the requirements of the table, and some Excel formulas will be used. After we enter the edit query interface, click Add Columns-Custom Columns to start adding custom columns, as shown in the figure:
We hope to define a list of customer's date of birth through the certificate number in the table. The custom formula is the formula of Power Query, which is similar to the formula in our Excel. The Middle function is used here, which can intercept the string.
Add index column
The so-called index is a column of self-increasing values that the system automatically generates for us, so that we can know the specific data in the first row. You can start from 0 or 1 by default, or you can customize how much to start, and you can also set the increment.
For example, if we want the data to start from 100, we can click Index-Custom...
After clicking OK, we can get an index column starting from 100.
Repeating column
Just copy the selected column.
For example, if we select the first order date and select the copy column, a copied column will be added to the last column.
Format column
This column is mainly added to the end of the table after formatting an existing column.
-
Lowercase: create a new column, change all English characters to lowercase
-
Uppercase: Create a new column and turn all English characters into uppercase
-
Capitalize the first letter: create a new column to capitalize the first letter of each English word
-
Trimming: Create a new column and delete spaces in the selected column value
-
Clear: Create a new column and delete non-printing characters in the selected column value, such as emoticons
- Add prefix: create a new column, add the specified prefix in front of the selected column value, for example, add ¥ before the order amount
Add suffix: create a new column, add the specified suffix after the selected column value
Extract column
-
Length: Create a new column and extract the length of the value in the column
-
First character: create a new column and extract the first character of the value in the column
-
End character: create a new column and extract the end character of the value in the column
-
Range: Create a new column to extract the characters in the specified area
-
The text before the separator: create a new column and extract the text before the specified separator
-
The text after the separator: create a new column and extract the text after the specified separator
- Text between delimiters: Create a new column and extract the text between the specified delimiters
In addition, there are related operations for adding columns to numeric date type columns. Interested friends can try it out one by one. I won't make too many demonstrations here.
annotation
Adding a column is mainly to perform some additional operations on the currently existing columns, so that we can make adjustments without changing the existing columns. The data types involved are also very complete, including common data types such as text, numeric values, and dates, and we need to be proficient in them.