多字段模糊查询sql like %% 优化与区别
多字段模糊查询sql like %% 优化与区别
http://anforen.5d6d.com/
SELECT *
from [KLims].[dbo].[Task]
where ClientCompany like '%a%' or [Address] like '%a%'
SELECT *
from [KLims].[dbo].[Task]
where ClientCompany + [Address] like '%a%'
但当其中一字段为null时,用第二种会找不到数据。
http://four-corner.appspot.com/
因为当某一字段为null时,拼接的字段整体都为null,要让第二种办法可以使用,可以这样写,将为null的字段,替换为'';
SELECT *
from [KLims].[dbo].[Task]
where isnull(ClientCompany,'') + isnull([Address],'') like '%a%'
这样既可正常执行,又高效。
相关文档:
数据库 有两张表
表1: student
表2:chinese
现在要分别列出 每所学校 语文成绩最高的 学生信息
SQL :
SELECT *
from student
LEFT JOIN chinese ON student.no = chinese.no
WHERE chinese.chengji
IN (
SELECT max( chinese.chengji )
from student
LEFT JOIN chinese ON student.no = chinese.no
GROU ......
如果你使用的是 SQL Server 2008, 当你修改数据结构后,保存时会报下图情况: Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving cha ......
使用SQL Server的朋友們應該都知道SQL Server的資料庫有一個設定叫做定序(Collation),今天我們就來看看定序這東西是什麼,首先我們看一下Wiki上對定序的說明:
Collation is the assembly of written information into a sta ......
已知一个表的结构为:
姓名 科目 成绩
张三 语文 20
张三 数学 30
张三 英语 50
李四 语文 70
李四 数学 60
李四 英语 90
怎样通过select语句把他变成以下结构:
姓名 语文 数学 英语
张三 20 30 50
李四 70 60 90
答:
CREATE TABLE [dbo].[Stu] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[Name] ......