2017-03-02 96 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> 
相關問題