求一 难度型 SQL 语句
我的数据库是垂直设计的,即同一个ID 的属性是在多行的,我想找出满足所有条件的ID
SQL code:
Declare @Attributes Table
(
ID VARCHAR(20),
Name VARCHAR(20),
value VARCHAR(20)
)
INSERT INTO @Attributes VALUES ('1000','color','red')
INSERT INTO @Attributes VALUES ('1001','color','red')
INSERT INTO @Attributes VALUES ('1002','color','red')
INSERT INTO @Attributes VALUES ('1003','color','red')
INSERT INTO @Attributes VALUES ('1004','color','red')
INSERT INTO @Attributes VALUES ('1005','color','red')
INSERT INTO @Attributes VALUES ('1006','color','black')
INSERT INTO @Attributes VALUES ('1000','price','100')
INSERT INTO @Attributes VALUES ('1001','price','1')
INSERT INTO @Attributes VALUES ('1002','price','10')
INSERT INTO @Attributes VALUES ('1003','price','50')
INSERT INTO @Attributes VALUES ('1004','price','20')
INSERT INTO @Attributes VALUES ('1005','price','1000')
INSERT INTO @Attributes VALUES ('1006','price','300')
我现在的做法是对满足条件ID进行计数,当满足条件的ID次数=我要查找的条件数,则取出此ID
SQL code:
SELECT ID
from
(SELECT *
from @Attributes t
WHERE (t.Name='color' AND t.value='red')
OR (t.Name='price' AND ISNUMERIC(t.value)=1 AND CONVERT(INT,t.value)>80)
相关问答:
请问一下,外网两台SQLSERVER实例数据传输,有没有采用数据压缩和加密。压缩比是多少,加密是什么加密算法?相关文档哪里可以找到?谢谢
我也想知道!关注此贴!
关注~~
数据库大牛都哪去了啊?
......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
--drop table #T1
--drop table #T2
create Table #T1(ID int,
QueryID nvarchar(20),
ResultID1 nvarchar(20),
ResultID2 nvarchar(20))
create Table #T2(SortNo int,
QueryID nvarchar(20),
ResultID1 nv ......
<table style="width: 1000px"><tr>
<td style="height: 38px; width: 35px;">
姓名</td>
......
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
&nb ......