sql 的查询问题 - MS-SQL Server / 疑难问题
表t1
列1 列2
a 2
b 1
c 3
我希望能根据列2的值来决定最后的显示
a 2
a 2
b 1
c 3
c 3
c 3
有没有什么好的办法。能通过select直接解决的
借助master..spt_values
用sql2005的with 递归
SQL code:
select k.*
from kof k join master..spt_values s
on k.col2>=s.number
where s.type='p' and s.number between 1 and (select MAX(col2) from kof)
order by col1
/*
col1 col2
---------- -----------
a 2
a 2
b 1
c 3
c 3
c 3
*/
SQL code:
select k.*
from kof k join master..spt_values s
on k.col2>=s.number
where s.type='p' and s.number>0
order by col1
/*
col1 col2
---------- -----------
a 2
a 2
b 1
c 3
c 3
c 3
*/
这样也可以
SQL code:
if not object_id('tb') is null
drop table tb
Go
Create table tb([列1] nvarchar(1),[列2] int)
Insert tb
select N'a',2 union all
select N'b',1 union all
select N'c',3
Go
Select a.*
from tb a ,master..spt_values b
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
求个vb中的sql语句的写法,次sql语句的用法是分页程序
我写的如下:其中A是用来接收每页显示的记录的条数,B是用来接收显示的当前的页面.
sqltext="select top A * from log where id not in(select top ( ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......