需求:

数据库存储形式

SQL中行列转换小例一个

ftype 分别对应 盒 箱

需要查询出的格式为:

SQL中行列转换小例一个

SQL语句:

select  a.*,b.counts,b.dw,c.counts ct, c.dw cdw,b.counts||b.dw||c.counts|| c.dw 
from ( select fname from t_test group by fname ) a
join (
select t.fname,count(t.ftype) counts,case t.ftype when '1' then '盒' when '2' then '箱' end as dw from t_test t 
where t.ftype='1'
group by t.fname, t.ftype
) b on  a.fname= b.fname
join (
select t.fname,count(t.ftype) counts,case t.ftype when '1' then '盒' when '2' then '箱' end as dw from t_test t 
where t.ftype='2'
group by t.fname, t.ftype
) c on a.fname = c.fname;

 这个就可以了。。可是还有几个缺陷

主要ftype 类型添加。语句就需要修改 拼接sql语句应该可以实现, 有空再次修改一下

相关文章:

  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-07-07
  • 2021-09-15
  • 2021-09-04
  • 2021-06-16
相关资源
相似解决方案