Table Overview:
2 columns
i_trans_to and i_trans_amnt
i_trans_to consists of IDs and i_trans_amnt consists of amount of money the user has deposited in account
user may deposit only these amounts 300,175,75,40,20(so the i_trans_amnt column will contain only these values)
there may be multiple entries for IDS as the user can deposit number of times.
I want a query which will select
1.All users whose total deposited money is greater than 500
2.Of all these users the query must tell about how many types of entries he made(example: 5 entries of Rs.300 and 2 entries of Rs.175)
i was successfull in designing the query except for the constraint that the user must have deposited over rs.500 here's the query
SELECT DISTINCT i_trans_to,
SUM( i_trans_amnt ),
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=300 AND transac.i_trans_to=current.i_trans_to) AS level1,
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=175 AND transac.i_trans_to=current.i_trans_to) AS level2,
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=75 AND transac.i_trans_to=current.i_trans_to) AS level3,
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=40 AND transac.i_trans_to=current.i_trans_to) AS level4,
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=40 AND transac.i_trans_to=current.i_trans_to) AS level5,
(SELECT COUNT(*)
FROM transac
WHERE i_trans_amnt=20 AND transac.i_trans_to=current.i_trans_to) AS level6
FROM transac as current
WHERE SUM( current.i_trans_amnt )>500
GROUP BY i_trans_to
I tried adding at the end of query a where clause in which i wrote SUM(i_trans_amnt)> 500 but this gave me an error.
Any suggestions?