写了一个好复杂的SQL查询语句
时 间:2007-11-24 09:08:07
作 者:jimcloudy ID:35 城市:福州
摘 要:这是在asp+sql2000中使用的查询语句,在其它地方可以参考着用。
主要掌握
1、SUM(CASE WHEN datediff(d, Sdate, getdate()) <= 365 THEN Snum ELSE 0 END) AS mystar
2、SUBSTRING(table1.house_name, 1, CHARINDEX('(', table1.house_name + '(') - 1)
3、GROUP BY 、HAVING
4、多表联合查询
正 文:
Select table1.id, table1.house_name,
table1.house_type, table1.house_area,
table1.house_bk, table1.house_address,
table1.house_bh, table1.house_hx,
table1.house_w, table1.house_mj,
table1.house_zc, table1.house_dd,
table1.lp_road, table1.house_floor,
table1.house_jgtime, table1.house_zx,
table1.house_cx, table1.house_zjjy,
table1.house_username, table1.house_userid,
table1.cs_list, table1.house_money,
table1.house_adddate, table1.contact_man,
table1.shenf, table1.contact_tel,
table1.house_pass, table1.house_top,
table1.house_bak01, loupanpic.pic_first, [user].username,
[user].name, [user].sex, [user].sj, [user].myblogid,
[user].myphoto, [user].myslogan, SUM(user_star.Snum) AS mynum,
SUM(CASE WHEN datediff(d, Sdate, getdate()) <= 365 THEN Snum ELSE 0 END) AS mystar
FROM table1
LEFT OUTER JOIN [user] ON table1.house_userid = [user].id
LEFT OUTER JOIN loupanpic ON SUBSTRING(table1.house_name, 1, CHARINDEX('(', table1.house_name + '(') - 1)
= loupanpic.loupanName AND loupanpic.lb = 1
LEFT OUTER JOIN user_star ON [user].id = user_star.user_id AND [user].name = user_star.user_name
GROUP BY table1.id, table1.house_name,
table1.house_type, table1.house_area,
table1.house_bk, table1.house_address,
table1.house_bh, table1.house_hx,
table1.house_w, table1.house_mj,
table1.house_zc, table1.house_dd,
table1.lp_road, table1.house_floor,
table1.house_jgtime, table1.house_zx,
table1.house_cx, table1.house_zjjy,
table1.house_username, table1.house_userid,
table1.cs_list, table1.house_money,
table1.house_adddate, table1.contact_man,
table1.shenf, table1.contact_tel,
table1.house_pass, table1.house_top,
table1.house_bak01, loupanpic.pic_first, [user].username,
[user].name, [user].sex, [user].sj, [user].myblogid,
[user].myphoto, [user].myslogan
HAVING (table1.cs_list = 0) AND (table1.house_pass = 0) AND (table1.house_top = 1)
orDER BY table1.house_username
说明:
这是在asp+sql2000中使用的查询语句,在其它地方可以参考着用。
主要掌握
1、SUM(CASE WHEN datediff(d, Sdate, getdate()) <= 365 THEN Snum ELSE 0 END) AS mystar
2、SUBSTRING(table1.house_name, 1, CHARINDEX('(', table1.house_name + '(') - 1)
3、GROUP BY 、HAVING
4、多表联合查询
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)