2017-03-02 47 views
0

我需要帮助。 我想这样从SQL中选择数据。总计是count(*) * 7500的结果。从sql中选择数据并得到多个结果

| fullname | count(*) | total | 
+==========+==========+=======+ 
| angelis | 3  | 22500 | 
| freed | 2  | 14000 | 
| debora | 4  | 28500 | 

我用这样的查询

select fullname, count(*) as jml 
from pms_occupancy 
where month(date)='02' 
group by fullname 

,它显示了下面的代码

enter image description here

+0

什么是你正面临着与您的查询问题的输出? – Sinstein

+0

您可以发送样本表结构.. –

+0

您正在使用哪些DBMS? Postgres的?甲骨文? –

回答

0

使用找到SQL SERVER您所需的输出:

样品表结构

================= 
ID | Country 
================= 
1 | C1 
2 | C2 
3 | C3 
4 | C4 
================= 

所需的查询:

declare @result_string varchar(max)='' 
;WITH CTE_TABLE 
AS 
(
SELECT ID,Country FROM dbo.tblCountry 
) 
select @[email protected]_string+'<tr><td>'+(cast(ID as varchar(100))+'</td><td>'+Country+'</td></tr>') from (
SELECT * FROM CTE_TABLE 
UNION 
SELECT COUNT(*) ID,'Total' Country FROM CTE_TABLE 
)a 

select '<table>'[email protected]_string+'</table>' 

查询

<table> 
<tr><td>1</td><td>C1</td></tr> 
<tr><td>2</td><td>C2</td></tr> 
<tr><td>3</td><td>C3</td></tr> 
<tr><td>4</td><td>C4</td></tr> 
<tr><td>4</td><td>Total</td></tr> 
</table> 
相关问题