易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL判断返回结果

字段1      字段2   字段3
A           B   C
A           B   C
如何用SQL判断返回知道 字段2是否相等 字段3是否相等
记录只有两条
感觉是太容易了,还是太难了?还是没说清楚?

你要这么返回?

having count(distinct 字段1)=1  ?

SQL code:

if exists(select 1 from tb where 字段1='A' and 字段2=字段3)
begin
do sth...
end





SQL code:
select
COL='字段1',flag=case when COUNT(distinct 字段1)=1 then '相等' else '不相等' end
from tb
union
select
COL='字段2',flag=case when COUNT(distinct 字段2)=1 then '相等' else '不相等' end
from tb
union
select
COL='字段3',flag=case when COUNT(distinct 字段3)=1 then '相等' else '不相等' end
from tb


引用
SQL code--> 测试数据: @tbdeclare@tbtable (字段1varchar(1),字段2varchar(1),字段3varchar(1))insertinto@tbselect'A','B','C'unionallselect'A','B','C'select*,id=identity(int,1,1)into #tfrom@tbselectcasewhen a.字段2=b.?-


定!

SQL code



Code highlighting produced by Actipro CodeHighlighter (freeware)
http:/


相关问答:

求一SQL - MS-SQL Server / 基础类

表如下
教室ID 座位数 开始时间 结束时间 2009年1月1日 2009年1月2日 2009年1月3日
  101 50 08:00 08:30 30 40 50  
  101 50 09:00 ......

pl/Sql如何查询字符串包括%

pl/Sql如何查询字符串包括%, 
例如:TABLE a
columnA
'222'
'33%44'
如何查询表a中columnA字段中哪些行包含'%'
谢谢
select * from a
where columna like '%/%%' escape '/'

UP

SELECT * from a ......

如果写递归sql语句 - MS-SQL Server / 应用实例

有两个同样的表结构 
表结构如下:
  id(序号) parentid (父结点序号) name(结点名称)
 表1 记录 1 0 aaa
  2 ......

一条sql查询语句

题目:把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; 
sql语句:
  update SC set score=(SELECT avg(SC_2.score)  
  from SC SC_2  
  WHERE S ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号