社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  DATABASE

MySQL连接和订购

NVG • 5 年前 • 234 次点击  

我有三个表,列相同,但数据不同(存款、取款、转账)

如果不存在,则创建表 withdrawals ( id int(11) 空自动增量, user varchar(12)默认为空, amount double(12,2)默认为空, date 时间戳空默认值 当前时间戳, time varchar(50)默认为空, type varchar(50)默认为空, status varchar(1)默认值“0”, notes 主键 ( 身份证件 ))引擎=myisam默认值 charset=latin1 auto_increment=1;

我希望将所有3个表合并为1个表,并按所有日期对其排序,并且仅当user=$user'时才显示行

Example if table 1 has this data
id  user    amount  date        time    type            status          notes
2   vveer   142.00  2010-04-01 03:05:01 PayPal              2          deposit
3   test11  116.00  2010-04-01 10:33:23 PayPal              2          deposit

Example if table 2 has this data
id  user    amount  date        time    type            status          notes
3   vveer   142.00  2009-04-01 03:05:01 PayPal              2          withdraw
7   test11  112.00  2010-04-12 10:33:23 PayPal              2          withdraw

Example if table 3 has this data
id  user    amount  date        time    type            status          notes
5   test11  133.00  2010-03-01 10:33:23 PayPal              2          transfer
7   test11  123.00  2010-02-01 10:33:23 PayPal              2          transfer

I want to show all data for user test11 ordered by dates(is like putting all the dates together and ordering by 1 date column ) .
3   test11  112.00  2010-04-12 10:33:23 PayPal              2          withdraw
7   test11  116.00  2010-04-01 10:33:23 PayPal              2          deposit
5   test11  133.00  2010-03-01 10:33:23 PayPal              2          transfer
5   test11  123.00  2010-02-01 10:33:23 PayPal              2          transfer
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/31751
 
234 次点击  
文章 [ 1 ]  |  最新文章 5 年前
MikeTheReader
Reply   •   1 楼
MikeTheReader    13 年前

如果我理解你的问题,这个例子就是工会运营商的设计目的。见 http://www.w3schools.com/sql/sql_union.asp 更多信息。