我有一个表“TABLE1”...在该表中我有2列InvoiceNumber和Total
创建创建发票的行
时 InvoiceNumber总
1个5.75
1个5.75
1个5.75
2个3.25
2个3.25
3个9.99
3个9.99
3 9.99
当然,很多其他专栏包含行详细信息......但总列数是发票总额...
我需要得到列总数的SUM,但是在invoicenumber列上选择了DISTINC ...
我希望我的解释现在更好!!! :)
非常坦克我很感激!
老问题......
我有这样的问题...但我不知道如何编写它以使其工作......有人可以帮助我吗?非常坦克,如果我的英语不是很好,那就很抱歉......
SELECT
SUM(1Z1.TotalStx) AS TotSTX,
1Z1.Dept,
1Z1.TrType,
ItemDept.DeptNumber,
ItemDept.VenteEncaisse
FROM
(SELECT DISTINCT 1Z1.InvoiceNumber)
JOIN ItemDept ON ItemDept.DeptNumber = 1Z1.Dept
WHERE Dept <> '0'
AND DateHre >= '2017-11-01'
AND DateHre <= '2017-11-30 23:59:59'
AND ItemDept.VenteEncaisse = '1'
ORDER BY 1Z1.Id;
答案 0 :(得分:0)
如果你想要InvoiceNumber的DISTINCT值,那么你希望得到哪个Dept,TrType等?
让我们看看 new AsyncTask<String, Void, String>()
{
@Override
protected String doInBackground(String... strings) {
String YQL = String.format("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"%s\")",location);
String endpoint = String.format("https://query.yahooapis.com/v1/public/yql?q=%s&format=json", Uri.encode(YQL));
try {
URL url = new URL(endpoint);
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder result = new StringBuilder();
boolean line;
while ((line = reader.readLine()!= null)){
result.append(line);
}
return result.toString();
} catch (Exception e) {
error = e;
}
return null;
}
/**
onPostExecute checks first if there is a service failure, then if city is valid, then it
populates the data from the city and goes to method serviceSuccess and populates the fields with the retrieved data
*/
@Override
protected void onPostExecute(String s) {
if (s == null && error != null){
callback.serviceFailure(error);
return;
}
try {
JSONObject data = new JSONObject(s);
JSONObject queryResults = data.optJSONObject("query");
int count = queryResults.optInt("count");
if (count == 0){
callback.serviceFailure(new LocationWeatherException("No Weather Info Found for" + location));
return;
}
Channel channel = new Channel();
channel.populate(queryResults.optJSONObject("results").optJSONObject("channel"));
callback.serviceSuccess(channel);
} catch (JSONException e) {
callback.serviceFailure(e);
}
}
}.execute(location);
}
。如果它显示SHOW CREATE TABLE 1Z1
,则不存在歧义, PRIMARY KEY(InvoiceNumber)
是不必要的。如果那不是PK,那么你需要弄清楚如何在前进之前处理歧义。
DISTINCT
中有哪个表格?