表一:一般消费
id,主键
customer_id,客户id
cash,金额
type,消费类型:零食,公交费....
dt,消费时间表二:日常开支
id,主键
customer_id,客户id
cash,金额
type,消费类型:水电,房租....
dt,缴费时间表二:其它支出
id,主键
customer_id,客户id
cash,金额
type,消费类型:医药看病,保险,上学费用,
dt,缴费时间表三...................很多这样的表,合并查询,结果为:
单个客户的所有支出列表:
select * from table1,table2 where customer_id=单个客户id order by dt时间(例子)最后的结果集像下面一样:id,客户id,消费类型,金额,时间
1,cst_id01,孩子上学,2000元,9月1日
2,cst_id01,看望父母,300元,9月4日 (备注:礼品)
3,cst_id01,房租物业,8000元,9月8日(一年费用)
.............................................................................................这是个例子,表1,表2不能合并,因为有很多客户,方便总共的统计!我用union all 只能查询两个表
三个表就错了......
我的应用是:C#+access,单机WinForm应用
一定要注意,不是web应用哦!
谢谢各位帮忙!我会另开帖子送分的哦
id,主键
customer_id,客户id
cash,金额
type,消费类型:零食,公交费....
dt,消费时间表二:日常开支
id,主键
customer_id,客户id
cash,金额
type,消费类型:水电,房租....
dt,缴费时间表二:其它支出
id,主键
customer_id,客户id
cash,金额
type,消费类型:医药看病,保险,上学费用,
dt,缴费时间表三...................很多这样的表,合并查询,结果为:
单个客户的所有支出列表:
select * from table1,table2 where customer_id=单个客户id order by dt时间(例子)最后的结果集像下面一样:id,客户id,消费类型,金额,时间
1,cst_id01,孩子上学,2000元,9月1日
2,cst_id01,看望父母,300元,9月4日 (备注:礼品)
3,cst_id01,房租物业,8000元,9月8日(一年费用)
.............................................................................................这是个例子,表1,表2不能合并,因为有很多客户,方便总共的统计!我用union all 只能查询两个表
三个表就错了......
我的应用是:C#+access,单机WinForm应用
一定要注意,不是web应用哦!
谢谢各位帮忙!我会另开帖子送分的哦
送分贴
union select * from table2 where customer_id=单个客户id union select * from table3 where customer_id=单个客户id) order dt
这样查询方便一些。
union all
select customer_id,cash,type,dt from table2
union all
select customer_id,cash,type,dt from table3
order by dt
三个表就错了......
提示什么错误信息?select customer_id,cash,type,dt from t1
union all
select customer_id,cash,type,dt from t2
union all
select customer_id,cash,type,dt from t3
order by dt
我也是遇到这个问题啊,三个表就出错了啊???????????
C#中用的access
(select customer_id,cash,type,dt from table1
union all
select customer_id,cash,type,dt from table2)AS T
union allselect customer_id,cash,type,dt from table3order by dt????
到Access的查询分析器下面调试
比较好,哈哈
谢谢各位