请教SQL语句
请高手指教下面的SQL语句应该如何写:
数据表Table1中 有字段1,字段2 数据值如下:
字段1 字段2
C 1
C 1
A 1
A 1
A 0
B 1
B 0
如何得到
字段1 字段2
C 1
A 0
B 0
也就是说如果字段2某个值是零,那么就的出 字段2为零
SQL code:
select * from Table1 a where 字段2=(select min(字段2) from Table1 where a.字段1=字段1)
SQL code:
select distinct 字段1,字段2=case when exists(select 1 from table1 where 字段1=a.字段1 and 字段2=0) then 0 else 1 end
from table1 a
SQL code:
--> 测试数据: [Table1]
if object_id('[Table1]') is not null drop table [Table1]
create table [Table1] (字段1 varchar(1),字段2 int)
insert into [Table1]
select 'C',1 union all
select 'C',1 union all
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
场景如下:
客户把备份好的数据库,发给我,我在本机还原后,运行写好的存储过程,比较快,并且在实施那边运行同样比较快。但是当实施在客户那边运行的时候速度就非常的慢,时间超出了程序的时间限制。远程在客户那 ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
我是在toad中输入下段sql
declare
TYPE test_rec IS record(
code varchar(10),
name varchar(30)
);
v_book test_rec;
......