当我在mySQL上运行以下SQL时
SELECT t1.U_COUNT AS U_COUNT, t2.R_COUNT AS R_COUNT
FROM
(
SELECT SUM(TRP_COUNT) AS U_COUNT
FROM `SAL_TAB`
WHERE CUST='SS' AND TV_POS='VFG'
) t1,
(
SELECT SUM(TRP_COUNT) AS R_COUNT
FROM `SAL_TAB`
WHERE CUST='SS' AND TV_POS='FHT'
) t2;
我得到的输出是
+---------+---------+
| U_COUNT | R_COUNT |
+---------+---------+
| 56 | 67 |
+---------+---------+
我所追求的输出是,
+------------+-------------+
| SALES_TYPE | SALES_COUNT |
+------------+-------------+
| U_COUNT | 56 |
| R_COUNT | 67 |
+------------+-------------+
我花了很多时间试图解决这个问题,但却未能做到。有人可以帮我吗?
答案 0 :(得分:1)
试试这个
var collection = [
{
name:"John",
age:12,
location:"Califonia",
gender:"Male"
},
{
name:"Jane",
age:18,
location:"New york",
gender:"Female"
}
]
function getMaxKeys(collection){
var keys = Object.keys(collection[0]);
var keyWithMaxWidth = keys.reduce(function(prev, current){
if(prev.length > current.length) return prev;
else return current
});
return keyWithMaxWidth;
}
getMaxKeys(collection) //location