A. 求一条筛选数据的sql语句
select
姓名,
(case
when
类别='工资'
then
金额
else
0
end
)
as
工资,
(case
when
类别='工资'
then
0
else
金额end
)
as
奖金
from
表
group
by
姓名
B. Sql筛选语句
declare @tiaojian varchar(1000)
declare @str varchar(1000)
set @tiaojian=' where 1=1 '
if 品牌条件不为空
set @tiaojian = @tiaojian+'and 品牌字段 ='+@品牌
if 品类条件不为空
set @tiaojian = @tiaojian+'and 品类字段 ='+@品类
if 分辨率条件不为空
set @tiaojian = @tiaojian+'and 品牌字段 ='+@分辨率
case
when @价格 ='价格具体值' then ' and 价格字段 between 具体值 and 具体值 '
when @价格 ='价格具体值' then ' and 价格字段 between 具体值 and 具体值 '
else set @tiaojian = @tiaojian +''
@str='select * from 表 + 'tiaojian
exec @str
C. Sql 对数据进行筛选 请问怎么写语句
--DROPTABLEtest
CREATETABLEtest(aINT,bINT,cVARCHAR(10))
INSERTINTOdbo.test
(a,b,c)
SELECT5038,1,'ss030001'
UNIONALL
SELECT
5038,1,'ss030001'
UNIONALL
SELECT
5038,2,''
UNIONALL
SELECT
5038,3,''
UNIONALL
SELECT
5038,2,'444'
UNIONALL
SELECT
5121,1,''
UNIONALL
SELECT
5038,3,'123456'
SELECT*FROMtestWHEREisnull(c,'')<>''
UNIONall
SELECTa,b,c
FROM
(
SELECTROW_NUMBER()OVER(PARTITIONBYaORDERBYa)id,*
FROMtest)t1
WHEREid=1ANDaNOTIN(SELECTaFROMtestWHEREisnull(c,'')<>'')
结果:
5038 1 ss030001
5038 1 ss030001
5038 2 444
5038 3 123456
5121 1
D. 关于筛选的SQL语句
select max(click) as haha from new_datas
haha是自设字段 你可以随便改名字
E. sql筛选语句
疑问:既然你想分组统计N条记录,你的SQL语句统计原则是什么?
以下是分组取前N条数据记录
createtablet_gulp(gidint,userIdvarchar(20),scoreint);
go
insertintot_gulpvalues(1,'A',50);
insertintot_gulpvalues(1,'B',40);
insertintot_gulpvalues(1,'C',60);
insertintot_gulpvalues(2,'D',70);
insertintot_gulpvalues(2,'E',80);
insertintot_gulpvalues(2,'F',90);
go
selectgid,userId,score
fromt_gulpast
wheret.userIdin
(
selecttop2userId
fromt_gulp
wheregid=t.gid
orderbyscoredesc
)
orderbygid,scoredesc
F. 用SQL语句实现数据筛选
--将字段条件筛选建立临时表
selecttop100*
into#temp
fromtable
wherenamenotin("%批发%","不含'%厂")
andregionin("餐饮",..."副食")--填写完每个经营面
--返回数据表,企业数和个体户,这个区分不知道用什么,所以第二个字段还需要改
selectprovince,count(distinctname)asnum_company,
casewhenname="个体户"thencount(distinctname)asnum_indivial
from#temp
G. sql语句筛选
select*from(
select*,row_number()over()seqfrom[表A]
)twhereseq=1
H. 在SQL数据库中,按照英文首字母对数据库中的汉字进行筛选
Create Function RmGetPY(@chn nchar(1))
returns char(1)
as
begin
declare @n int
declare @c char(1)
set @n = 63
select @n = @n +1,@c = case chn when @chn then char(@n) else @c end from(
select top 27 * from (
select chn =
'吖' union all select
'八' union all select
'嚓' union all select
'咑' union all select
'妸' union all select
'发' union all select
'旮' union all select
'铪' union all select
'丌' union all select
'丌' union all select
'咔' union all select
'垃' union all select
'呒' union all select
'拏' union all select
'噢' union all select
'妑' union all select
'七' union all select
'呥' union all select
'仨' union all select
'他' union all select
'屲' union all select
'屲' union all select
'屲' union all select
'夕' union all select
'丫' union all select
'帀' union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
return(@c)
end
go
Create Function GetAllPY(@chn nvarchar(100))
returns varchar(30)
as
begin
declare @i int,@j int,@result varchar(100)
set @result=''
set @i=len(@chn)
set @j=1
while @j<=@i
begin
set @result = @result + dbo.RmGetPY(substring(@chn,@j,1))
set @j=@j+1
end
--将助记码限定在30个字母之内
select @result=(case when len(@result)>30 then left(@result,30) else @result end)
return @result
end
先加这两个函数,然后
select * from table where dbo.GetAllPY(字段) like 'J%'
I. 用sql语句进行筛选
select姓名from表where课程!='A'
J. SQL筛选语句
select count(0) from xs where 恋爱='F'
用的count(0)的原因是你只要记录数。没有必要用*将所有字段都差一次这样可以减轻数据库的负担。使得查询所用的时间更短。在数据少的情况下看不出来。但是一旦数据多了,就很明显了。比如:几万条数据,几十万条数据。