㈠ sql如何获取一个表某三个列不一样的数据
SELECTMJBH,CPBH,JOBNOFROMTABGROUPBYMJBH,CPBH,JOBNO;
或者
SELECTDISTINCTMJBH,CPBH,JOBNOFROMT;
㈡ 一条sql语句如何选取出多个不同的运算结果值,内详。
select (select count(*) from table_name where 年龄 between 18 and 30),(select count(*) from table_name where 年龄 between 3000 and 5000) from al;
㈢ SQL按条件取值,根据不同的条件来取不同的结果
select case when DATEPART(hour,采样时间)<9 then 10
when DATEPART(hour,采样时间)>=9 and DATEPART(hour,采样时间)<10 then 11
else 11:30 end as time from table
㈣ sql查询某字段多少种不同值,怎么写
select class from table group by class输出的结果为class123这个结果为class里有哪些不同的数字 select count(class) from table group by class输出结果为class3这个结果为class里有多少种不同的数字(共3种)
㈤ (数据库查询)你好,我想请问一下SQL,怎样从一张表取2种不同条件的列值,让他们并列在同一张表。
使用 join 连接 :
select
k.class,
sum( decode(k.abc,'100003',1,0)),
sum( decode(k.efg,'100004',1,0)),
sum( decode(k.hij,'100005',1,0)),
sum( decode(k.klm,'100006',1,0)),
cc.dept_code,
cc.fenshu份数,
cc.zongshu 项目总数
from
DETAIL k
where k.ggg='100001' and score='0' group by k.class:
join
( select
c.ggg,
c.dept_code,
count(distinct c.aaa) fenshu,
count(c.bbb) zongshu
from
DETAIL c
where c.ggg='100001'group by c.class) cc
on c.ggg =k.ggg
㈥ SQL中怎样取多个值
select 后面跟的是查询内容(字段名),查询一个字段或多个字段,如果只从一个表中查询,比如说a、b、c、d、e同属字母这个字段那就,select zimu from table where....,如果属于不同的字段,那就select 字段1、字段2、... from table1 where ......
㈦ SQL语句 只取不同的数据
select后加上distinct,另再把需要值(不为空或空串)的条件写入where子句
㈧ sql语句要select某字段不重复的数据应该如何写
sql语句要select某字段不重复的数据使用distinct关键字,例如从 Company" 列中仅选取唯一不同的值使用以下SQL:
SELECT DISTINCT Company FROM Order;
题主的问题B、C字段数据都相同,可以使用select distinct A,B from table_name 来实现。
(8)sql如何取不同的值扩展阅读
在表中,可能会包含重复值,有时希望仅仅列出不同(distinct)的值,可以使用关键词 DISTINCT 用于返回唯一不同的值。
语法:
SELECT DISTINCT 列名称 FROM 表名称
用法注意:
1、distinct【查询字段】,必须放在要查询字段的开头,即放在第一个参数;
2、只能在SELECT 语句中使用,不能在 INSERT, DELETE, UPDATE 中使用;
3、DISTINCT 表示对后面的所有参数的拼接取 不重复的记录,即查出的参数拼接每行记录都是唯一的;
4、不能与all同时使用,默认情况下,查询时返回的就是所有的结果。
㈨ sql 怎么取不重复的数据的所有数据
SQL数据重复分几种情况,一种是原数据重复,第二种是粒度重复,第三种是分布重复。
原数据重复的情况,你直接可以distinct掉,例如,学生表当中有两个重复的学号,你想取出不重复的,直接可以写:select
distinct
学号
from
学生表
第二种是查询粒度重复,比如你有一张表是存储区域的,分别为省、市、县三列。而你需要的是只查找不同的省市,则也可以使用distinct:select
distinct
省,市
from
区域
第三种则是分布重复,比如在join
的时候,左右两个表格存在一对多的关系,造成的重复,或者在聚合之后出现了维度重复,则这种相对来说比较麻烦,你需要在子查询中统计或查找出唯一值,然后再去关联,或者是按照一定的数据需求的取数规则,在查询结果后再进行聚合,取到唯一值。
不过不管怎么样,都是要看实际需求是什么样子的。大多可以用子查询和关联联合解决。
㈩ SQL 如何取出每一行字段的值不同的行
先列转行在查询
select* from tablea_3
NO A B C D E F G
a 1 0 0 0 1 0 0
c 0 0 0 0 0 0 0
b 3 2 0 0 1 3 2
declare @s varchar(8000)------------------------------------------先列转行
set @s = 'create table tablea_32 (no varchar(20)'
select @s = @s + ',' + no + ' varchar(10)' from tablea_3
set @s = @s + ')'
exec(@s)
print @s
--借助中间表实现行列转换
declare @name varchar(20)
declare t_cursor cursor for
select name from syscolumns
where id=object_id('tablea_3') and colid > 1 order by colid
open t_cursor
fetch next from t_cursor into @name
while @@fetch_status = 0
begin
exec('select ' + @name + ' as t into tablea_33 from tablea_3')
set @s='insert into tablea_32 select ''' + @name + ''''
select @s = @s + ',''' + rtrim(t) + '''' from tablea_33
exec(@s)
exec('drop table tablea_33')
fetch next from t_cursor into @name
end
close t_cursor
deallocate t_cursor
--查看行列互换处理结果
select * from tablea_32
declare @a int
declare @b int
declare @c char(10)
select @a= min( ascii(no)) from tablea_32
select @b= max( ascii(no)) from tablea_32
while (@a<=@b)
begin
set @c=char(@a)
insert into #A
select distinct a,no
from tablea_32 where no=@c and a<>0
insert into #B
select distinct B,no
from tablea_32 where no=@c and B<>0
insert into #C
select distinct C,no
from tablea_32 where no=@c and C<>0
set @a=@a+1
end
if exists ( select count(distinct A) from #a having count(distinct a)>1)
PRINT 'A'
if exists ( select count(distinct B) from #B having count(distinct B )>1)
print 'B'
if exists ( select count(distinct C) from #C having count(distinct C )>1)
print 'C'