【发布时间】:2018-11-03 13:45:04
【问题描述】:
我在数据库中有两个表来存储客户基本信息(姓名、位置、电话号码)和另一个表来存储与客户相关的交易(date_sub、profile_sub、isPaid、date_exp、client_id),我有一个 html 表要查看客户基本信息和交易(如果可用),我的问题是我无法同时从表 internetClient 和 internetclientDetails 中选择客户信息,因为只有当客户端在明细表中有 trans 时才会产生查询。两个表字段如下:
internetClient
--------------------------------------------------------
id full_name location phone_number
-------------------------------------------------------
4 Joe Amine beirut 03776132
5 Mariam zoue beirut 03556133
和
internetclientdetails
--------------------------------------------------------------------------
incdid icid date_sub date_exp isPaid sub_price
----------------------------------------------------------------------------
6 4 2018-01-01 2018-01-30 0 2000
7 5 2017-01-01 2017-01-30 0 1000
8 4 2018-03-01 2018-03-30 1 50000
9 5 2018-05-01 2019-05-30 1 90000
// incdid > internetClientDetailsId
// icid> internetClientId
如果客户端有trans in orderdetails,查询应该返回如下值:
client_id full_name date_sub date_exp isPaid sub_price
-------------------------------------------------------------------------------------
4 Joe Amine 2018-03-01 2018-03-30 1 50000
5 Mariam zoue 2018-05-01 2019-05-30 1 90000
否则,如果客户端在 internetOrederDetails
中没有 id --------------------------------------------------------
icid full_name location phone_number
-------------------------------------------------------
4 Joe Amine beirut 03776132
5 Mariam zoue beirut 0355613
提前致谢
【问题讨论】:
-
你只想
INNER JOIN两张表吗?还是分别返回它们,但在与数据库的一次事务中返回? -
只需加入并在哪里可以得到。
-
@MatBailie 我想要的是获取最新订阅日期以及 sub_price 和其他详细信息的客户基本信息。我更新了问题以显示所需的结果
-
什么版本的mySQL?可能会使用分析函数
-
Nope 8.0 does 但是我们可以使用派生表来模拟它。
标签: mysql sql database select join