您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

一个数据格式有关问题,高手来帮帮忙,多谢了

2024/5/7 1:21:23发布8次查看
一个数据格式问题,在线等,高手来帮帮忙,谢谢了
表1:
  id groupname attribute op value
  1 abc download := 151-250
  2 abc upload := 50-150
  3 efg download := 152-250
  4 efg upload := 50-150
怎么将上表中的数据转换成下面的格式
  id groupname download upload
  1 abc 151-250 50-150
  2 efg 152-250 50-150
sql:
select a.groupname,a.value as upload,b.value as download from radgroupreply a left join radgroupreply b on a.groupname=b.groupname where a.attribute='upload' and b.attribute='download' and a.groupname in ('abc','efg')
这种方法可以实现,但是感觉效率有点低,有没有更好的办法?
用临时表是不是比上面的方法效率要好点,如果用临时表,怎么将数据插入到临时表中,如果直接create然后执行以上sql,这样就没意义了,有没有什么好办法进行插入呢?
因为这张表数据比较大,考虑到效率问题,想找到一个更好的解决办法,请各位高手帮帮忙,给点思路,不胜感激!
在线等,急!!!!!
------解决方案--------------------
用存诸过程创建临时表
------解决方案--------------------
你这是求交叉表,有现成的存储过程可供参考。搜索“交叉表”就可找到
------解决方案--------------------
行列转换……
sql codeset @id=;select (@id:=@id+1) as id, groupname, group_concat(if(attribute='download', `value`, '') separator '') as download, group_concat(if(attribute='upload', `value`, '') separator '') as upload from 表名 group by groupname

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录