好长时间没有用SQL了...还停留在学生时代的水平... 转: 昨天遇到个面试题:查询一个表里面某个字段值相同的数据记录,好久没有写过这种,还真的花了点时间才写出来.如表g_carddetail,有 g_no g_name g_id g_state 这个字段,现在要求查询出存在g_id相同大于等于2的数据记录:select * from g_carddetail a where exists(select g_id from g_carddetail where g_id = a.g_id gr
SELECT * FROM roster WHERE roster.`name` >'zzzzzzzzzz' //查询roster表中name值为中文的 SELECT * FROM roster WHERE roster.`name` >'zzzzzzzzzz' AND roster.`name` LIKE '张%生' //查询roster表中name值为汉字且第一个字是‘张’第三个字是‘生’的
sql 查询某字段为空 select * from 表名 where 字段名 is null sql 查询某字段不为空 select * from 表名 where 字段名 is not null sql查询字段1为空且字段2不为空的数据 select * from 表名 where 字段名1 is null and 字段名2 is not null
方法一sql="select * from table where id<>null " or sql="select * from table where len(id)>1" 方法二"select 字段名序列 from talbe where 字段 is not null" 由于 null 不是一个值,而是一个状态
一.包含中文字符 select * from 表名 where 列名 like '%[吖-座]%' 二.包含英文字符 select * from 表名 where 列名 like '%[a-z]%' 三.包含纯数字 select * from 表名 where 列名 like '%[0-9]%' 上面的正则表达式,只能用like选出该字段中含有中文/英文/数字的人,那如果需求是选出姓名全部是中文的人,要如何做? sqlserver中有函数len,以及datalength 可将字段名强制类型转换成
) set @TableName = 'Agency' -- 表名 declare @querySql nvarchar(max) set @querySql = 'select ' ) declare My_Cursor cursor for(select name from syscolumns where id = (select max(id) from sysobjects where xtype = 'u' and name = '' + @TableName + '' ) ) op