当前位置:首页 » 数据仓库 » 数据库表查询字段值是否有多个
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

数据库表查询字段值是否有多个

发布时间: 2023-08-10 16:56:04

❶ 查询一个数据库表有多少字段的sql

这个要看你用的什么数据库,要用到系统表,不同的数据库系统表不一样。比如MS SQL可以这样写:
select count(*) from syscolumns where id = object_id('表名')
syscolumns 就是系统表

❷ sql中如何查看某一字段值有几个数值

用分组,组内计数就可以了,意思就是根据字段a的取值进行分组,相同的为一组,在用count进行组内计数select a,count(*)from Agroup by a

❸ sql中如何查看某一字段值有几个数值

CREATE proc Full_Search(@string varchar(50))
as
begin

declare @tbname varchar(50)
declare tbroy cursor for select name from sysobjects
where xtype= 'u ' --第一个游标遍历所有的表

open tbroy
fetch next from tbroy into @tbname
while @@fetch_status=0
begin

declare @colname varchar(50)
declare colroy cursor for select name from syscolumns
where id=object_id(@tbname) and xtype in (
select xtype from systypes
where name in ( 'varchar ', 'nvarchar ', 'char ', 'nchar ') --数据类型为字符型的字段
) --第二个游标是第一个游标的嵌套游标,遍历某个表的所有字段

open colroy
fetch next from colroy into @colname
while @@fetch_status=0
begin

declare @sql nvarchar(1000),@j int
select @sql= 'select @i=count(1) from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%'''
exec sp_executesql @sql,N'@i int output',@i=@j output --输出满足条件表的记录数
if @j> 0
BEGIN
select 包含字串的表名=@tbname
--exec( 'select distinct '+@colname+' from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%''')
END
fetch next from colroy into @colname
end

close colroy
deallocate colroy

fetch next from tbroy into @tbname
end
close tbroy
deallocate tbroy
end
go

❹ sql如何根据一个字段的多个值查询

具体方法如下:

假定表名test,列id是数值类型。
用同一个字段的多个值作为条件来查询可以使用in或者or。

具体语句如下:

1、select * from test where id in (1,2,3)

2、select * from test where id = 1 or id =2 or id = 3

显然第一种方法更简便。

PS: 如果如你消息所说,有一个选课表test,学生号id,所选课程名name,那么,检索同时选择了美术、体育、音乐三门课程的学生id的语法如下:

select a.id from test a,test b,test c
where a.id = b.id and b.i
d = c.id and a.name = '美术' and b.name = '体育' and c.name = '音乐';

问题的关键,在于test表通过别名做三次关联查询。

❺ MYSQL查一个字段中 多个值

下面两种情况:
1.返回值:由全体出入参数合并在一起而得到的字符串。只要输入的参数中有null值,就返回null。concat允许只有一个输入参数的情况。
因此,mysql单表多字段模糊查询可以通过下面这个sql查询实现
select
*
from
`magazine`
where
concat(`title`,`tag`,`description`)
like
‘%关键字%’
2.如果这三个字段中有值为null,则返回的也是null,那么这一条记录可能就会被错过,怎么处理呢,我这边使用的是ifnull进行判断,则sql改为:
select
*
from
`magazine`
where
concat(ifnull(`title`,''),ifnull(`tag`,''),ifnull(`description`,''))
like
‘%关键字%’
评论
0
0
0
加载更多