A null value comparison, a merge of two columns, and the column values are replaced by criteria.

Source: Internet
Author: User


Show create TABLE table name-Displays the SQL statement that created the table.

Adds a new column to an existing table.
ALTER TABLE name add column name int null--this line adds an int type to the default nullable column.

Null means: An undefined value.
How do I compare the value of a column to null?
Can be null,is not NULL or <=>

You can compare two NULL values with <=>, null<=>null the result to true instead of undefined.

CREATE TABLE ' T1 ' (

' Col1 ' char (6) Not NULL DEFAULT ' ',

' col3 ' varchar (6) DEFAULT NULL,
`
Createtime ' timestamp not NULL DEFAULT current_timestamp on UPDATE current_timestamp

) Engine=innodb DEFAULT Charset=utf8


Select Concat (col1, ' @ ', createtime) from T1--connects the values of the columns col1 and createtime with @ to display them. (Value @ value)


SELECT DISTINCT col3 from T1--repeated values for the col3 of the array
Select COUNT (Distinct col3) from T1--Ji Lu column col3 The number of duplicate values.


Select *,if (col3 = ' abc ', ' 123 ', col3) from T1--If the value of column col3 equals ABC then 123来 will be used instead
Select *,ifnull (col3, ' 123 ') from T1--If the value of column col3 equals null then 123来 will be used instead

A null value comparison, a merge of two columns, and the column values are replaced by criteria.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.