我对WordPress中一些SQL查询有一个问题。该对象是从多个表及其列中获取以下信息。
我需要:<代码>订购时间|日期和时间|名称|电子邮件|部门|总订单|金额
我已经为自己提供了以下视觉帮助:
wp_postmeta 包含:
- 部门 as = billing_field_267
- 电子邮件 as = billing_email
- 名字
- pland> last Name>
= _billing_first_name > wp_wc_order_stats 包含:
- 日期和时间 = date_created
- 订购时间 = billing_field_739
- 量 = ??
- 总订单 = ??
计费字段是meta_keys,所以我只需要它们的价值。
我已经尝试了以下SQL语句以获取我的需求:
SELECT
user.meta_key, user.meta_value
FROM
wp_postmeta AS user, wp_wc_order_stats as order
WHERE
user.meta_key='billing_field_267', user.meta_key='billing_email', user.meta_key='_billing_first_name', user.meta_key='_billing_last_name', user.meta_key='billing_field_739'
AND
order.date_created
它似乎并没有根据需要在正确的直接方面工作。
I have a question regarding some SQL queries in WordPress. The object is getting the following information from multiple tables and their columns.
I need: Ordered Time | Date and Time | Name | Email | Department | Total Orders | Amount
I've scoped out the following as a visual aid for myself: 
wp_postmeta
contains:
- Department as = billing_field_267
- Email as = billing_email
- First Name = _billing_first_name
- Last Name = _billing_last_name
wp_wc_order_stats
contains:
- Date and Time = date_created
- Ordered Time = billing_field_739
- Amount = ??
- Total Orders = ??
The billing fields are meta_keys so I just need their values.
I've tried the following SQL Statement to get what I need:
SELECT
user.meta_key, user.meta_value
FROM
wp_postmeta AS user, wp_wc_order_stats as order
WHERE
user.meta_key='billing_field_267', user.meta_key='billing_email', user.meta_key='_billing_first_name', user.meta_key='_billing_last_name', user.meta_key='billing_field_739'
AND
order.date_created
It doesn't seem to be working as needed some help in the right direct would be apprecaited.
发布评论
评论(1)
您有两个必须与之合作的查询步骤。
查询一个是第一个子问题相当简单。构建客户信息的第二个子查询需要将行转换为列 ,在在这里
因此,假设
总订单
是有问题的订单数(s)和金额
为了成为订单的总价值,以下查询应起作用。You have two steps of query you have to work with.
Query one which is the first sub-query is fairly straight forward. The second subquery which build customers' info requires the conversion of ROWs into COLUMNs in the table which is described in greater detail in here
Thus, assuming
Total Orders
is number of order(s) in question andAmount
to be total value of the order(s), the following query should work.