xml文件里如何写sql语句实现年龄分组
我做的项目是springboot+mybatis框架,想做一个年龄的分组查询,下面的代码selectt1.p1asnum1,t2.p2asnum2,t3.p3asnum3...
我做的项目是springboot+mybatis框架,想做一个年龄的分组查询,下面的代码
select t1.p1 as num1,t2.p2 as num2,t3.p3 as num3,t4.p4 as num4,t5.p5 as num5 from
(select count(age) as p1 from person where age>=0 and age <=10 ) t1 INNER JOIN
(select count(age) as p2 from person where age>=11 and age <=20 ) t2 INNER JOIN
(select count(age) as p3 from person where age>=21 and age <=30 ) t3 INNER JOIN
(select count(age) as p4 from person where age>=31 and age <=40 ) t4 INNER JOIN
(select count(age) as p5 from person where age>=41 and age <=50 ) t5
在数据库里面做查询是没问题的,但是放到项目的mapper.xml文件里就报错。 展开
select t1.p1 as num1,t2.p2 as num2,t3.p3 as num3,t4.p4 as num4,t5.p5 as num5 from
(select count(age) as p1 from person where age>=0 and age <=10 ) t1 INNER JOIN
(select count(age) as p2 from person where age>=11 and age <=20 ) t2 INNER JOIN
(select count(age) as p3 from person where age>=21 and age <=30 ) t3 INNER JOIN
(select count(age) as p4 from person where age>=31 and age <=40 ) t4 INNER JOIN
(select count(age) as p5 from person where age>=41 and age <=50 ) t5
在数据库里面做查询是没问题的,但是放到项目的mapper.xml文件里就报错。 展开
1个回答
2019-01-22
展开全部
xml 文件中 小于号 < 要用 < 代替吧。
select t1.p1 as num1,t2.p2 as num2,t3.p3 as num3,t4.p4 as num4,t5.p5 as num5 from
(select count(age) as p1 from person where age>=0 and age <11 ) t1 INNER JOIN
(select count(age) as p2 from person where age>=11 and age <21 ) t2 INNER JOIN
(select count(age) as p3 from person where age>=21 and age <31 ) t3 INNER JOIN
(select count(age) as p4 from person where age>=31 and age <41 ) t4 INNER JOIN
(select count(age) as p5 from person where age>=41 and age <51 ) t5
希望能帮到你
追问
谢谢你,改好了,可以用了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询