❶ sql语句,结果标题分列显示
方法有很多种,最简单的,就是在前台制好你的表格头,然后从数据库,读取数据。
还有种,对数据库语句编写,和前台html表格处理要求较高。在后台统计好要合并的单元格,然后动态从数据库输出。
==============================================
说简单了,意思都还变了!!
怎么说呢?你要的是合并了单元格的表格头,从数据库出来的,是二维表格数据,是不可能有那样合并了单元格的数据的。怎么很多人要理解,从数据库输出合并了单元格的形式呢?这当然不行。
咱的意思,就是什么。既然数据库出来的是二维表格,无法改变。那就分成两个部分来处理,一个是纯数据,二个是你要个表格头。表格头就在前台处理完成,不从数据库出来。出来的就是纯数据。然后,把这两部分拼凑起来。
不知道能否,搞的明白我的意思呢!怎么说的这么累。还反过来问我,搞得懂行否?
====================
自己看图片,红色的,就是你自己的在前台处理好的,蓝色的就是从数据库出来的。
❷ sql中如何将数据分列
substring(字符串1,开始位,截取位数)
❸ SQL 分列显示
sql 2005;
直接写语句相当于把每个字段找出来
select
(case when num=1 and right(ytd)='01' then ytd end) ,
(case when num=1 and right(ytd)='01' then users end),
(case when num=1 and right(ytd)='01' then IP end),
(case when num=1 and right(ytd)='02' then ytd end) ,
(case when num=1 and right(ytd)='02' then users end),
(case when num=1 and right(ytd)='02' then IP end),
..................................31' ......
(case when num=2 and right(ytd)='01' then ytd end) ,
(case when num=2 and right(ytd)='01' then users end),
(case when num=2 and right(ytd)='01' then IP end),
(case when num=2 and right(ytd)='02' then ytd end) ,
(case when num=2 and right(ytd)='02' then users end),
(case when num=2 and right(ytd)='02' then IP end),
..................................31' ......
from (select *,rank()(order by ytd) as num from [table]) a
或者
select a.ytd,a.users,a.ip,b.ytd,b.users,b.ip.....xx.ytd,xx.users,xx.ip
from
(select *,rank()(order by ytd) as num from [table] where right(ytd)='01') a left join (select *,rank()(order by ytd) as num from [table] where right(ytd)='02') b on a.num=b.num
left join (select *,rank()(order by ytd) as num from [table] where right(ytd)='03') c on a.num=c.num
.....
left join (select *,rank()(order by ytd) as num from [table] where right(ytd)='31') xx on a.num=xx.num
❹ 怎么样在SQL语句中,将两个条件查出的结果分开,或者分先后顺序
可以自己造一个类型,1和2,分表表示两种新闻。
select * from
(select 1 as '新闻类型',* from table1 where title like '%关键词%'
union all
select 2 as '新闻类型',* from table1 where content like '%关键词%' ) a
order by a.id desc
❺ SQL语句怎样使查询同一表同一列多条数据分列显示
declare @sql varchar(8000)
set @sql = 'select 编码,名称'
select @sql = @sql+', max(case [项目序号] when '''+cast(项目序号 as varchar)+''' then 数额 else 0 end ) AS [项目序号'+cast(项目序号 as varchar)+']'
from (select distinct 项目序号 from 表名) as a
set @sql = @sql +' from 表名 group by 编码,名称'
select @sql
exec (@sql)
❻ sql语句将两个查询结果并列输出
如果是2个SQL语句的话。如果列名都一样,使用UNIONALL就可以了。例如select*from表1UNIONALLselect*from表2就可以了。
❼ sql语句怎么样一次性查询多个条件,并分列显示
方法一,分别查询出来,结果再关联
selectfnum1,fnum2from
(selectcount(*)asfnum1from表名wherea=2andb=3)t1,
(selectcount(*)asfnum2from表名wherea=3andb=5)t2
方法二
selectsum(casewhena=2andb=3then1else0end)asfnum1,
sum(casewhena=3andb=5then1else0end)asfnum2
from表名
wherea=2andb=3
ora=3andb=5
有问题请追问
❽ SQL语句怎样使查询同一表同一列多条数据分列显示(在线等)
select编码,名称,sum(金额),sum(数量)from表1groupby编码,名称
❾ sql,2005里,如何将查询的结果分两列显示.
这个比较简单吧
先做一个子查询,把你需要的数据查出来,另外再新加一个字段,比如想第一列显示的固定为1,第二列的固定为2
然后在外面再套一层,case when xx=1 then 查询出来的字段 else '' end as 第一列
同样的方法就得到第二列了。
最后,再根据你想要的键值 group by 一下
❿ sql查询中,如何将某列 分成 两列。
SELECT PAccM33g02,
CASE PAccM33g02
WHEN 0 THEN PAccM33g02 END PAccM33g02_J,
CASE PAccM33g02
WHEN 1 THEN PAccM33g02 END PAccM33g02_C
FROM PAccM3307