1. Format time SQL statements
In this case, I did a random two tables, and the actual is not very consistent, just want to explain the wording of the SQL statement.
Example 1 is in table format as follows:
Requirements: Query out this table, but need to make time field format for YYYY-MM-DD, such as: 2013-08-13
SQL notation:
SELECT U.id,u.userid,u.timetype,date_format (Time, '%y-%m-%d ') as Time,secondid from ' User ' u
Run Result:
2. Multi-Table query (three-table query)
Example two or three table structure is as follows:
Requirements: Query out the main table, requiring that username and secondname be displayed in the main table
SQL notation:
SELECT u.id,n. ' Name ', u.timetype,u.time,s. ' Name ' from ' User ' U, ' name ' N, ' second '
WHERE u.userid=n.id and U.secondi D=s.id
Run Result:
3.when then judgment statement
Example three table structure is as follows:
Requirements: Query on the table, if the TimeType field value of 2 o'clock, display the second day of the month, if the TimeType field value is 4 o'clock, showing the fourth day of the month
SQL notation:
SELECT U.id,u.userid, (case when u.timetype=2 THEN ' The second day of the month ' when U.timetype=4 THEN ' the fourth day of the Month ') as TimeType, U.time,u.second Id from ' User ' u
Run Result:
The above is a small set to introduce the SQL Judgment statement usage and multiple table query, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!