1、创建测试表,
create table test_person(id int, RMB int)
2、插入测试数据
insert into test_person values(1,180)
insert into test_person values(2,170)
insert into test_person values(3,290)
insert into test_person values(4,160)
insert into test_person values(5,299)
insert into test_person values(6,266)
insert into test_person values(7,155)
3、查询表中所有记录,select t.* from test_person t,
4、编写sql,汇总每个vip类型的用户数,
select vip_type, count(distinct id)
from (select case when RMB>100 and RMB<200 then 'VIP1' when RMB>200 then 'VIP2' end as vip_type, id
from test_person) t
group by vip_type
1、首先打开SQLyogEnt软件,打开SQLyogEnt的Query窗口,之后的sql语句都会在这里执行。
2、书写sql:select now() 查询出当前的时间:2018-06-08 13:32:22;now函数为mysql的当前日期函数。
3、书写sql:select date_format(now(),'%Y-%m-%d')查询出的时间格式为:2018-06-08;%Y和%y的区别则是:前者查询出完整2018,后者则是查询简写的18。
4、书写sql:select curdate()查询出当前日期2018-06-08,不带时分秒。
5、书写sql:select curtime()查询出当前时间13:40:11,不带年月日。
6、最后书写sql:select dayofweek(now());查询出一个数字,代表着星期;星期的排列方式为:星期日:1;星期一:2;...以此类推。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)