读书人

select 用法小结

发布时间: 2012-08-22 09:50:34 作者: rapoo

select 用法总结

1.查看mysql内置函数

select now();

2.查看存储过程变量

select @a;

?

mysql > SELECT 'Hello World' into @x; mysql > SELECT @x; +-------------+ |   @x        | +-------------+ | Hello World | +-------------+ mysql > SET @y='Goodbye Cruel World'; mysql > SELECT @y; +---------------------+ |     @y              | +---------------------+ | Goodbye Cruel World | +---------------------+ mysql > SET @z=1+2+3; mysql > SELECT @z; +------+ | @z   | +------+ |  6   | +------+?

注意:

①用户变量名一般以@开头

②滥用用户变量会导致程序难以理解及管理

?

2.添加标识字段和初值

select 1 flag;


3.通过动态标识来选择

select * from user where true;? 返回所有

select * from user where false; 返回空

实战? 根据用户是否有所有project权限来取出所有project

select * from project where (select is_all_project from user where use_id =13)

读书人网 >其他数据库

热点推荐