mysql> select * from points where poid='kmin_lee';
+-------+----------+-------+----------+---------------------+
| poidx | poid | point | okresult | po_time |
+-------+----------+-------+----------+---------------------+
| 6 | kmin_lee | 1000 | Y | 2022-07-03 12:44:11 |
| 18 | kmin_lee | 3200 | Y | 2022-07-08 16:41:10 |
| 20 | kmin_lee | 4200 | N | 2022-07-09 11:22:31 |
+-------+----------+-------+----------+---------------------+
3 rows in set (0.00 sec)
mysql> select point from points where poid='kmin_lee' and okresult='Y';
+-------+
| point |
+-------+
| 1000 |
| 3200 |
+-------+
2 rows in set (0.00 sec)
mysql> select sum(point) from points where poid='kmin_lee' and okresult='Y';
+------------+
| sum(point) |
+------------+
| 4200 |
+------------+
1 row in set (0.00 sec)
mysql> select sum(point),(select sum(point) from points where poid='kmin_lee' and okresult='N') as usepoint from points where poid='kmin_lee' and okresult='Y';
+------------+----------+
| sum(point) | usepoint |
+------------+----------+
| 4200 | 4200 |
+------------+----------+
1 row in set (0.00 sec)
728x90
'Database > MySQL' 카테고리의 다른 글
[MSSQL] Microsoft SQL Server Managment Studio 서버 세팅 (0) | 2022.08.01 |
---|---|
[sql] != 와 <> 여러개 데이터 확인 (0) | 2022.07.13 |
[Mysql] 한 필드에 있는 여러 이름을 검색할 때는 in (0) | 2022.07.10 |
[Mysql] group by에서 조건 줄때 사용 하는 Having, count(필드명) 자동 null 값은 카운트 하지 않음 (0) | 2022.07.10 |
[Mysql] 같은 조건으로 gruop by 할 때 우선순위사용 가능한 union (0) | 2022.07.10 |
댓글