```def combinationSum2(candidates, target):
res = []
candidates.sort()

def dfs(target, index, path):
if target < 0:
return  # backtracking
if target == 0:
res.append(path)
return  # backtracking
for i in range(index, len(candidates)):
if candidates[i] == candidates[i-1]:
continue
dfs(target-candidates[i], i+1, path+[candidates[i]])

dfs(target, 0, [])
return res```
```def combinationSum2(candidates, target):
res = []
candidates.sort()

def dfs(target, index, path):
if target < 0:
return  # backtracking
if target == 0:
res.append(path)
return
for i in range(index, len(candidates)):
dfs(target-candidates[i], i, path+[candidates[i]])

dfs(target, 0, [])
return res```
```class Solution
{
//Function to return sum of upper and lower triangles of a matrix.
static ArrayList<Integer> sumTriangles(int matrix[][], int n)
{
ArrayList<Integer> list=new ArrayList<>();
int sum1=0;
int sum2=0;
for(int g=0; g<matrix.length; g++){
for(int i=0, j=g; j<matrix.length; i++,j++){
sum1+=matrix[i][j];
}
}
for(int g=0; g<matrix.length; g++){
for(int i=g,j=0; i<matrix.length; i++,j++){
sum2+=matrix[i][j];
}
}
return list;
}
}```
```Use Sum aggregate function with case statement as below, if you want sum of those t.value based on t.clock then do group by on that column so that you will get clock while sum of values.

select sum(case when  i.hostid='223344'   and t.itemid = '0223344' then t.value end) as FirstValue,sum(case when  i.hostid='112233' and t.itemid = '0112233' then t.value end) as SecondValue
from hosts h, items i,history_uint t
where i.hostid=h.hostid and t.itemid=i.itemid
If it is based on t.clock then

select t.clock, sum(case when  i.hostid='223344'   and t.itemid = '0223344' then t.value end) as FirstValue,sum(case when  i.hostid='112233' and t.itemid = '0112233' then t.value end) as SecondValue
from hosts h, items i,history_uint t
where i.hostid=h.hostid and t.itemid=i.itemid
group by t.clock
0

You can try this below logic-

SELECT i.hostid,t.itemid,t.value as OneValues, t.clock as time
FROM hosts h
INNER JOIN items i
ON i.hostid=h.hostid
AND i.hostid IN ('223344','112233')
AND i.itemid IN ('0223344','0112233')
INNER JOIN  history_uint t
ON t.itemid=i.itemid```
star

Thu Mar 10 2022 02:32:24 GMT+0000 (UTC) https://leetcode.com/problems/combination-sum/discuss/429538/General-Backtracking-questions-solutions-in-Python-for-reference-%3A

#python #template #combinations #sum
star

Thu Mar 10 2022 02:31:32 GMT+0000 (UTC) https://leetcode.com/problems/combination-sum/discuss/429538/General-Backtracking-questions-solutions-in-Python-for-reference-%3A

#python #template #combinations #sum
star

Tue Feb 08 2022 08:14:36 GMT+0000 (UTC) https://practice.geeksforgeeks.org/problems/sum-of-upper-and-lower-triangles-1587115621/1/?track=DSASP-Matrix&batchId=190

#java #gfg #geeksforgeeks #2d #array #matrix #practice #sum
star

Wed Apr 01 2020 08:18:27 GMT+0000 (UTC) https://stackoverflow.com/questions/60963447/sql-how-to-sum-select

#sql #sum

#### Save snippets that work with our extensions   