ASP关于两表查询产品排序问题,寻高手相助

mxrxhy007 2009-07-09 08:31:09
寻asp高手相助解决问题,不甚感激!
我想达到的效果是:网站有很多的会员。会员数据存在ACCESS的SMT_yp表里, 会员发布的产品存在SMT_cp里,每个会员每天都会发布大量的产品,我现在希望网页能先显示所有会员发布的一条产品然后再按时间发布顺序先后显示全部产品。这两部分要连在一起实现分页,分页我自己能写,我现在希望请教的就是实现产品显示的那句SQL语句。两个表几个关键字段如下:
SMT_cp表:id(自动编号),SMT_yp_id(对应发布产品企业的id号)其他的比如cpname(产品名称)SMT_date(发布时间) SMT_yp表:SMT_id(企业编号)SMT_qyname(企业名称)。
自己搞了很久没解决,希望高手出手相助。要求代码确实能用,不要复制,只需提供SQL语句就可以,其他部分我自己来解决,谢谢!!!O(∩_∩)O

刚注册,如能用以后一定挣分追加上,希望好心人帮助!!请直接给语句,谢谢!!!
...全文
80 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
薪水 2009-07-12
  • 打赏
  • 举报
回复
帮顶
  • 打赏
  • 举报
回复
所有会员剩下的产品正好和上面的语句相反:
select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=a.smt_yp_id) as qyname from smt_cp where id not in(select max(id) from smt_cp group by smt_yp_id)

就只加这一个not

然后把2个语句union all
在一起即可了
  • 打赏
  • 举报
回复
每个会员的最新产品可以用:
select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=a.smt_yp_id) as qyname from smt_cp where id in(select max(id) from smt_cp group by smt_yp_id)
lzp4881 2009-07-12
  • 打赏
  • 举报
回复
select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=a.smt_yp_id) as smt_qyname from smt_cp a where id in (select max(id) from smt_cp group by smt_yp_id)
union all
select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=b.smt_yp_id) as smt_qyname from smt_cp b where id not in (select max(id) from smt_cp group by smt_yp_id)
  • 打赏
  • 举报
回复
你说的那个排序,用SQL不好做啊
select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=smt_yp_id) as qyname,(select dj from smt_yp where smt_id=smt_yp_id) as qydj from smt_cp where id in(select max(id) from smt_cp,smt_yp where smt_cp.smt_yp_id=smt_yp.smt_id group by smt_yp_id order by max(smt_yp.dj) desc) UNION ALL select id,cpname,smt_date,(select smt_qyname from smt_yp where smt_id=smt_yp_id) as qyname,(select dj from smt_yp where smt_id=smt_yp_id) as qydj from smt_cp as a where id not in(select max(id) from smt_cp group by smt_yp_id);

你看,虽然红色部分我改成这个,但是最终效果也没用的
如果单独用红色部分
SELECT max(id), max(smt_yp.dj)
FROM smt_cp, smt_yp
WHERE smt_cp.smt_yp_id=smt_yp.smt_id
GROUP BY smt_yp_id
ORDER BY max(smt_yp.dj) DESC;
这样是没问题的
mxrxhy007 2009-07-12
  • 打赏
  • 举报
回复
借鉴了大家的写法,我将语句写成这样,可是出不来的结果,还是按照id显示全部产品,希望大家帮忙看看
sql="select SMT_cp.*,SMT_yp.* from SMT_cp,SMT_yp where SMT_cp.SMT_id in (select max(SMT_cp.SMT_id) from SMT_cp group by SMT_cp.SMT_yp_id) and (SMT_cp.SMT_cpname like'%"&gjc&"%' or SMT_cp.SMT_cpname like'%"&gjc2&"%')and SMT_cp.SMT_key=1 "&cjsort&"and SMT_cp.SMT_key1=1 "&addsort&" and SMT_cp.SMT_key2=1 "&cpjw&" and SMT_cp.SMT_yp_id=SMT_yp.SMT_id order by SMT_yp.SMT_vip, SMT_yp.SMT_id desc
union all
select SMT_cp.*,SMT_yp.* from SMT_cp,SMT_yp where SMT_cp.SMT_id not in (select max(SMT_cp.SMT_id) from SMT_cp group by SMT_cp.SMT_yp_id) and (SMT_cp.SMT_cpname like'%"&gjc&"%' or SMT_cp.SMT_cpname like'%"&gjc2&"%')and SMT_cp.SMT_key=1 "&cjsort&"and SMT_cp.SMT_key1=1 "&addsort&" and SMT_cp.SMT_key2=1 "&cpjw&" and SMT_cp.SMT_yp_id=SMT_yp.SMT_id order by SMT_yp.SMT_vip, SMT_yp.SMT_id desc"
mxrxhy007 2009-07-12
  • 打赏
  • 举报
回复
优先按SMT_VIP(会员等级,在SMT_yp表中),其次按SMT_ID产品编号进行排序该怎么排呢?谢谢
mxrxhy007 2009-07-12
  • 打赏
  • 举报
回复
谢谢各位高手回答,那要是我要让他按会员等级SMT_vip字段排序该加在哪里呢?
mxrxhy007 2009-07-11
  • 打赏
  • 举报
回复
来个无私奉献的高手帮帮忙吧
mxrxhy007 2009-07-11
  • 打赏
  • 举报
回复
我希望达到的是类似阿里巴巴的产品显示排序效果
先读取每个用户发布的一条产品,显示完了,再显示全部产品,这样不至于一个用户发布了几十条产品,其他用户产品就都排到他的后面去了,最主要的是我要使这两部分读取结果实现一起分页,而不是分开的。分页我能写,关键是SQL语句不知怎么写。请直接给语句,别给思路!

产品表名:SMT_cp 字段:id(自动编号) cpname(产品名称) SMT_date(发布时间) SMT_yp_id(对应厂家表中的厂家id号)

厂家表:SMT_yp 字段:SMT_id(企业编号) SMT_qyname(企业名称)
你好柴九 2009-07-10
  • 打赏
  • 举报
回复
你二表关联查询,要什么效果,
mxrxhy007 2009-07-10
  • 打赏
  • 举报
回复
看来没分真不行

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧