求sql 方法 - MS-SQL Server / 疑难问题
表A
Field A1(Varchar) A2
record 1 1
record 2 1
record 3 1
表B
Field B1(Varchar) B2
record 1,2,5,6 1
要求,查找出 A1表中A1字段的值,在B表B1中,条件A2=B2
SQL code:
select a1 from a where exists(select 1 from b where charindex(','+ltrim(a.a1)+',',','+b1+',')>0 and a.a2=b2)
如何返回
for xml path()
record 这东西是字段内容还是多余的?
select A.* from A , B where A2=B2 and charindex(','+A1+',',','+B1+',')>0
SQL code:
select A1
from 表A a
where exists
(select B1
from 表B b
where b.B2 = a.A2
and charindex(',' + a.A1 + ',', ',' + b.B1 + ',') > 0)
1.exists:用来过滤记录的,相当于条件
2.CHARINDEX函数返回字符或者字符串在另一个字符串中的起始位置。不存在返回 0;
CHARINDEX函数调用方法如下:
CHARINDEX ( expression1 , expression2 [ , start_location ] )
SQL code:
select A1
from 表A a
left join 表B b
on a.A2 = b.B2
where charindex(',' + a.A1 + ',', ',' + b.B1
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
sql的软件在哪里可以下啊!在网上找了蛮多都用不了啊
随便搞一D版吧,
迅雷第一个就可以用
2000,2005都这样
http://119.147.41.16/down?cid=0698C2D64D7D637D90A6D2482298E6717D4F15CD&t=2&fmt=-1 ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......
select o_customer,o_price from orders having o_price >=avg(o_price)
select o_customer,o_price from orders where o_price >=(select avg(o_price) from orders)
我感觉没有区别啊,怎么在mysql会有 ......