2011-11-21
1. Calculate the number of years
You figured out how old this person is on your birthday.
Select date_format (from_days (to_days (now ()-to_days (@ dateofbirth), '% y') + 0; |
2. The difference between the two datetime values is obtained.
Assume that dt1 and dt2 are of the datetime type, and their format is 'yyyy-mm-dd hh: mm: ss'. The difference between them is:
Unix_timestamp (dt2)-unix_timestamp (dt1) |
Dividing by 60 is the number of minutes in the difference, dividing by 3600 is the number of hours in the difference, and dividing by 24 is the number of days in the difference.
3. display the value of a column that appears n times
Select ID from TBL group by ID having count (*) = N; |
4. Calculate the working days between two days.
Select count (*) from calendar where D between start and stop and dayofweek (d) not in (1, 7) holiday and = 0; |
5. Search for the primary key in the table
Select K. column_name from information_schema.table_constraints t Join information_schema.key_column_usage K using (constraint_name, table_schema, table_name) Where T. constraint_type = 'Primary key' and T. table_schema = 'db' and T. table_name = tbl' |
6. Check the size of your database.
Select Table_schema as 'db name ', Round (sum (data_length + index_length)/1024/1024, 3) as 'db size (MB )', Round (sum (data_free)/1024/1024, 3) as 'free space (MB )' From information_schema.tables group by table_schema; |