表一:一般消费
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应用哦!
谢谢各位帮忙!我会另开帖子送分的哦

解决方案 »

  1.   

    http://topic.csdn.net/u/20090907/08/9c973423-6327-45a8-95a4-c1abe9db5699.html
    送分贴
      

  2.   

    union,1,2,3表呗。。然后按你想要的结果排序。。
      

  3.   

    select * from (select * from table1 where customer_id=单个客户id 
    union select * from table2 where customer_id=单个客户id union select * from table3 where customer_id=单个客户id) order dt
      

  4.   

    在access中建个视图,合并你所需要的表。
    这样查询方便一些。
      

  5.   

    别人给你写了SQL。。那没有什么意思。。提供一个思路才能学到东西~~~~
      

  6.   

    select customer_id,cash,type,dt from table1
    union all
    select customer_id,cash,type,dt from table2
    union all
    select customer_id,cash,type,dt from table3
    order by dt
      

  7.   

    select * from table1,table2 where table1.customer_id=单个客户id and table1.customer_id = table2.customer_id and table2.customer_id=table3.customer_id order by table1.dt时间
      

  8.   

    http://topic.csdn.net/u/20090907/08/9c973423-6327-45a8-95a4-c1abe9db5699.html
      

  9.   

      http://topic.csdn.net/u/20090907/08/9c973423-6327-45a8-95a4-c1abe9db5699.html
      

  10.   

    我用union all 只能查询两个表 
    三个表就错了......
    提示什么错误信息?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
      

  11.   


    我也是遇到这个问题啊,三个表就出错了啊???????????
    C#中用的access
      

  12.   

    用括号。。把前2个合并表另命名下。。然后继续用union
      

  13.   

    SELECT * FROM 
    (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????
      

  14.   

    原来有个列不一样,要参数
    到Access的查询分析器下面调试
    比较好,哈哈
    谢谢各位