⑴ 在sql语句实现查询一张表中的同一个属性的不同字段的所有数据
oracle的话有个wmsys.wm_concat函数可以实现
select dosname,wmsys.wm_concat(doswork) from work group by dosname;
⑵ 在SQL表中如何一起查询两个列(同一个表中)
select * from tab1
union all
select * from tab2
前提2个表数据相同
或者左右外内链接查询 都一样
lefe join
right join
full join
⑶ sql从同一表里查询多条不同条件的数据
试试:
select
a_id,
a_title,
a_name
from
A
where
a_id=10
union
all
select
*
from
(
select
top
1
a_id,
a_title,
a_name
from
A
where
a_id<10
order
by
a_id
desc)
union
all
select
top
1
a_id,
a_title,
a_name
from
A
where
a_id>10
⑷ SQL 把不同列的号码汇总代码怎么写
这个不是汇总,就是字段合并
只是你的SQL是什么数据库(有几十个常用数据库,它们都支持SQL语言的,但字串合并方法不同的),若是SQLServer(注意,SQL与SQLserver是不同的概念)
可用
select 员工姓名,手机号码+'*'+电话号码 可联系号码 from 你的表
⑸ sql语句,查出同一表中同一列不同类型的数据同时查出。
select * from tab where C='33' or C='34';
or是或者,其一匹配就会显示,所以33和34都会显示
and是而且,也就是两个条件必须同时满足
⑹ 同一张表的不同列怎么用sql将查询出来的值和在一起
两种方法。
一。
select * from A
union
select * from B
二。
select
(case when M then else 0 end 1 ),
(case when N then else 0 end 1 )
from A,B
⑺ sql语句如何查询一个表中某一列的不同数据
select * from 表名称 where "工装(字段名)=工装名,辅料(字段名)=辅料,站位(字段名)=站位"
⑻ sql里查询一个字段里的记录的多个类的汇总(几个字段按不同分类的汇总)
--技术要点:行转列
--以下提供SQL SERVER语句
--创建测试环境
create table tab
(
machine int,
sernum varchar(10),
area varchar(2),
PF varchar(1)
)
--制造数据
insert into tab select 462,'16205R3E','AT','P'
insert into tab select 462,'16203H0N','AT','F'
insert into tab select 316,'1620A7WP','AT','S'
insert into tab select 316,'16206CCC','AT','S'
--1. 静态行转列(所谓静态,是指的PF列只有P,F,S这三个值,或者值是固定的某几个值)
select machine,
max(case pf when 'P' then num else 0 end) as P,
max(case pf when 'F' then num else 0 end) as F,
max(case pf when 'S' then num else 0 end) as S
from
(select machine,pf,count(1) as num from tab group by machine,pf
)tb
group by machine
/* 结果集
machine P F S
----------- ----------- ----------- -----------
316 0 0 2
462 1 1 0
(2 row(s) affected)
*/
--2. 动态行转列(相对于静态的概念)
declare @sql varchar(8000)
set @sql = 'select machine as ' + 'machine'
select @sql = @sql + ' , max(case pf when ''' + pf + ''' then num else 0 end) [' + pf + ']'
from (select distinct pf from tab) as a
set @sql = @sql + ' from (select machine,pf,count(1) as num from tab group by machine,pf
)tb group by machine'
exec(@sql)
/* 结果集
machine F P S
----------- ----------- ----------- -----------
316 0 0 2
462 1 1 0
(2 row(s) affected)
*/
--删除环境
drop table tab
⑼ 如何将SQL中同一个表中的两列记录合并查询
使用union。
select column1 from table union select column2 from table
⑽ 在SQL里面怎么把同一个表中的列相同的汇总 另外一列平均一下
你好!
select
sum(a),avg(b)
from
表
a是汇总字段
b是平均字段
如有疑问,请追问。