
MySQL中中的整数类型int主要有如下几种:
1、tinyint 的范围是-128~127;
2、int的范围是-2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字),存储大小为4个字节;
3、bigint的范围是 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节;
4、smallint unsigned的范围是 –2^15(2^15表示2的15次幂) 到2^15 – 1,即 –32768 到 32767;
5、smallint 的范围是 0 到 2^16 – 1,即 0 到 65535,存储的字节是2个字节。
扩展资料
int类型, 占用字节数为4byte, 学过计算机原理的同学应该知道,字节(byte)并非是计算机存储的最小单位, 还有比字节(byte)更小的单位,也就是位(bit),一个位就代表一个0或1; 8个位组成一个字节;一般字节用大写B来表示byte,位用小写b来表示bit。
计算机存储单位的换算:
1B=8b
1KB=1024B
1MB=1024KB
那么根据int类型允许存储的字节数是4个字节,就能换算出int UNSIGNED(无符号)类型的能存储的最小值为0,最大值为4294967295(即4B=32b,最大值即为32个1组成)。
now()-stime 得到的是minute * 100,这个数值的与分钟的单位换算是100=1分钟,超过60分钟这个数值无效。得到时间差:
select (unix_timestamp(now())-unix_timestamp(stime))/60 from table_name where whew_condition
mysql>select * from timeminus
+----+---------------------+
| id | stime |
+----+---------------------+
| 1 | 2011-09-21 09:30:00 |
| 2 | 2011-09-21 11:30:00 |
| 3 | 2011-09-20 00:00:00 |
+----+---------------------+
3 rows in set (0.02 sec)
# 计算id=1与id=2的时间差(分钟)
mysql>select (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 from (select
* from timeminus where id=2) a inner join (select * from timeminus where id=1) b
+------------------------------------------------------+
| (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 |
+------------------------------------------------------+
| 120.0000 |
+------------------------------------------------------+
1 row in set (0.00 sec)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)