我有多个查询,只在一列中生成一个计数(仅一个单元格)。我需要将这些列组合在一起。
假设查询是:
select count (*) from address where city = NULL as citycount;
select count (*) from address where countrycode = 4 as countrycount;
select count (*) from address;
以上查询将返回结果:
citycount
40
countrycount
50
count(*)
400045
我希望以这种方式组合上述查询,以便结果为:
citycount countrycount count(*)
40 50 400045
这意味着列将合并。我有30多个查询。 提前致谢
答案 0 :(得分:2)
将SUM与CASE表达式一起使用:
select
sum(case when city = NULL then 1 else 0 end ) as citycount,
sum(case when countrycode=4 then 1 else 0 end ) as countrycount,
count(*) as countt
from address
答案 1 :(得分:1)
select
(select count (*) from address where city IS NULL) as citycount,
(select count (*) from address where countrycode = 4) as countrycount,
count(*)
from address
答案 2 :(得分:0)
尝试这样的事情......希望有所帮助
module.exports.uploadToAWS = function uploadToAWS(folderName, fileName, fileData) {
var s3 = new AWS.S3({ params: {Bucket: ‘myBucket’} });
var keyName = folderName + "/" + fileName;
var buffer = new Buffer(fileData.replace(/^data:image\/\w+;base64,/, ""),'base64')
var data = {
Key: keyName,
Body: buffer,
ContentEncoding: 'base64',
ContentType: 'image/jpeg'
};
s3.putObject(data, function(err, data) {
if (err) {
console.log(err);
console.log('Error uploading data: ', data);
} else {
console.log('succesfully uploaded the image!');
}
});
}