sql1="select a,b,c from table where flag=1 order by id desc"sql2="select a,b,c from table where flag=2 order by id desc"想实现,首先显示第一个记录集的内容,然后再显示第二个记录集的内容,全部内容还需要分页。不知道在asp页面里面怎样实现?
select a,b,c from [table] where flag in(1,2) order by flag,id desc
其实flag只是为了表示一个查询条件,实际上的查询条件复杂的多,并且查询条件是不一样的。
谢谢,其实flag只是为了表示一个查询条件,实际上的查询条件复杂的多,并且查询条件是不一样的。
那就 union吧select * from table where ... union all select * from table where ....
那就在查询结果中增加一个flag值来排序,外面再嵌套查询,方法同上select a,b,c from( select flag=1,a,b,c from talbe where xxx =? union all select flag=2,a,b,c from table where yyy=? ) t order by flag,id desc
select a,b,c from table where flag=1 or flag=2 order by flag,id desc
from [table]
where flag in(1,2)
order by flag,id desc
union all
select * from table where ....
那就在查询结果中增加一个flag值来排序,外面再嵌套查询,方法同上select a,b,c
from(
select flag=1,a,b,c from talbe where xxx =?
union all
select flag=2,a,b,c from table where yyy=?
) t
order by flag,id desc
想在产品页面显示产品的时候,首先显示收费会员的产品,然后再显示其他产品。就是这么一个结果。表结构:
表一:ProTable (产品表)
字段:pro_id,pro_name,pro_cont 产品id,产品名称,产品内容。
表二:UserTable (会员表)
字段:U_id,U_name,U_flag 会员id,会员名称,会员标识U_flag=0为免费,U_flag=1为收费。在产品页面显示的产品列表中,首先显示收费会员发布的产品,然后再显示免费会员发布的产品。
忘记了写对应的字段。
本人是用asp作的一个会员系统,能发布产品。会员分为收费会员和免费会员。
想在产品页面显示产品的时候,首先显示收费会员的产品,然后再显示其他产品。就是这么一个结果。 表结构:
表一:ProTable (产品表)
字段:pro_id,pro_name,pro_cont,hy_id 产品id,产品名称,产品内容,会员id,hy_id=U_id。
表二:UserTable (会员表)
字段:U_id,U_name,U_flag 会员id,会员名称,会员标识U_flag=0为免费,U_flag=1为收费。 在产品页面显示的产品列表中,首先显示收费会员发布的产品,然后再显示免费会员发布的产品。
CREATE TABLE ProTable(
pro_id INT,
pro_name VARCHAR(500),
pro_cont VARCHAR(MAX),
hy_id VARCHAR(10)
)
GOCREATE TABLE UserTable(
U_id VARCHAR(10),
U_name VARCHAR(50),
U_flag INT
)
GOINSERT ProTable VALUES(1, '笔记本', '笔记本', 'xiaoluo')
INSERT ProTable VALUES(2, '钢笔', '钢笔', 'xiaoluo')
INSERT ProTable VALUES(3, '铅笔盒', '铅笔盒', 'xiaochen')INSERT UserTable VALUES('xiaoluo', 'xiaoluo', 0)
INSERT UserTable VALUES('xiaochen', 'xiaochen', 1)
SELECT * FROM ProTable a JOIN UserTable b ON a.hy_id = b.U_id ORDER BY U_flag DESC
pro_id pro_name pro_cont hy_id U_id U_name U_flag
----------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ---------- -------------------------------------------------- -----------
3 铅笔盒 铅笔盒 xiaochen xiaochen xiaochen 1
1 笔记本 笔记本 xiaoluo xiaoluo xiaoluo 0
2 钢笔 钢笔 xiaoluo xiaoluo xiaoluo 0(3 row(s) affected)