用UNION ALL查询不会用html编写

时间:2019-12-27 01:30:46

标签: html postgresql

我有一个查询,我想在HTML文件中写入所有语句都使用UNION,但是它只执行列并在其中写入0 0。 我该如何通过? 我的查询:

/usr/bin/psql -h localhost -U etaxi_prod_due etaxi_prod_due --html -c "with summary as (select count(id) as \"Summary\" from archived_order 
where data like '%"pmi":2568%' 
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary\" from archived_order 
where data like '%"pmi":2569%' 
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary\" from archived_order 
where data like '%"pmi":2570%'
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary\" from archived_order
where data like '%"pmn":"CHILD_SEAT"%'
and finished between current_date - interval '1 day' and current_date
), app as 

(select count(id) as \"Etaximo\" from archived_order
where data like '%"pmn":"CHILD_SEAT"%'
and finished between current_date - interval '1 day' and current_date), oper as

(select count(id) as \"Operator\" from archived_order 
where data like '%"pmi":2568%' 
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Operator\" from archived_order 
where data like '%"pmi":2569%' 
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Operator\" from archived_order 
where data like '%"pmi":2570%'
and finished between current_date - interval '1 day' and current_date), sumcompl as 

(select count(id) as \"Summary Completed\" from archived_order 
where data like '%"pmi":2568%' and completed is true
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary Completed\" from archived_order 
where data like '%"pmi":2569%' and completed is true 
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary Completed\" from archived_order 
where data like '%"pmi":2570%' and completed is true
and finished between current_date - interval '1 day' and current_date

UNION ALL

select count(id) as \"Summary Completed\" from archived_order
where data like '%"pmn":"CHILD_SEAT"%' and completed is true
and finished between current_date - interval '1 day' and current_date
), result1 as (
select 
sum(\"Summary\") as \"Created\"
from summary
), result2 as 
(select 
sum(\"Summary Completed\") as \"Done\"
from sumcompl
), result3 as (select
sum(\"Operator\") as \"Operator\"
from oper
), result4 as (select
sum(\"Etaximo\") as \"Etaximo\"
from app 
)
select result1.\"Created\", result2.\"Done\", result3.\"Operator\", result4.\"Etaximo\" from result1, result2, result3, result4 order by result1.\"Created\", result2.\"Done\", result3.\"Operator\", result4.\"Etaximo\";">>/home/www/etaxi-prod-due/tmp/shara.html

我尝试做一些GROUP BYORDER BY,但没有帮助,我还尝试做一些封装操作,使它看起来完全没有UNIONS。但这也行不通。

此查询在html文件中的输出如下所示:

<table border="1">
  <tr>
    <th align="center">Created</th>
    <th align="center">Completed</th>
    <th align="center">Operator</th>
    <th align="center">Etaximo</th>
  </tr>
  <tr valign="top">
    <td align="right">0</td>
    <td align="right">0</td>
    <td align="right">0</td>
    <td align="right">0</td>
  </tr>
</table>
<p>(1 row)<br />
</p>

但是应该是这样

<table border="1">
  <tr>
    <th align="center">Created</th>
    <th align="center">Completed</th>
    <th align="center">Operator</th>
    <th align="center">Etaximo</th>
  </tr>
  <tr valign="top">
    <td align="right">193</td>
    <td align="right">152</td>
    <td align="right">161</td>
    <td align="right">32</td>
  </tr>
</table>
<p>(1 row)<br />
</p>

0 个答案:

没有答案