1. Format time SQL statements
In this example, I casually made two tables, and the actual is not very consistent, just want to explain the wording of the SQL statement.
Example 1 table format is as follows:
Requirements: Query out the table, but you need to make the time field in the format of YYYY-MM-DD, for example: 2013-08-13
SQL notation:
SELECT U.id,u.userid,u.timetype,date_format (Time, '%y-%m-%d ') as Time,secondid from ' User ' u
Operation Result:
2. Multi-Table query (three-table query)
Example two or three table structure is as follows:
Requirements: Querying out the main table, requiring the display of username and secondname in the main table
SQL notation:
SELECT u.id,n. ' Name ', u.timetype,u.time,s ' name ' from ' User ' U, ' name ' N, ' second ' s
WHERE U.userid=n.id and U.secondid=s.id
Operation Result:
3.when then judgment statement
The three-table structure is as follows:
Requirements: Query the table above, if the TimeType field value is 2 o'clock, display the second day of the month, if the TimeType field value is 4 o'clock, display the fourth day of the month
SQL notation:
SELECT U.id,u.userid, (case is u.timetype=2 then ' the next day of the month ' when u.timetype=4 and then ' fourth day of the Month ' END) as TimeType, U.time,u.second Id from ' User ' u
Operation Result:
SQL Judgment statement usage and multiple table queries