写了一个好复杂的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)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 仓库管理实战课程(9)-开发往来单...(04.02)
- 仓库管理实战课程(8)-商品信息功...(04.01)
- 仓库管理实战课程(7)-链接表(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)
- 仓库管理实战课程(4)-建表操作(03.22)
- 仓库管理实战课程(3)-需求设计说...(03.19)
- 仓库管理实战课程(2)-软件背景和...(03.18)
- 仓库管理实战课程(1)-讲师介绍(03.16)