Created
November 22, 2022 15:17
-
-
Save fakruboss/df3b31cae22ea1c190ab586f87348a47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- create | |
CREATE TABLE TRANSACTION ( | |
id INTEGER NOT NULL, | |
TRANS VARCHAR(3) NOT NULL, | |
CODE INTEGER NOT NULL | |
); | |
-- insert | |
INSERT INTO TRANSACTION VALUES (1001, 'TE', 9000); | |
INSERT INTO TRANSACTION VALUES (1002, 'TE', 9000); | |
INSERT INTO TRANSACTION VALUES (1002, 'CC', 8999); | |
INSERT INTO TRANSACTION VALUES (1003, 'TE', 9000); | |
INSERT INTO TRANSACTION VALUES (1003, 'CC', 8999); | |
INSERT INTO TRANSACTION VALUES (1003, 'CAN', 8998); | |
INSERT INTO TRANSACTION VALUES (1004, 'TE', 9000); | |
INSERT INTO TRANSACTION VALUES (1004, 'CAN', 8999); | |
INSERT INTO TRANSACTION VALUES (1004, 'CC', 8998); | |
INSERT INTO TRANSACTION VALUES (1004, 'CAN', 8997); | |
select * from transaction; | |
-- fetch | |
-- select * from transaction where code = (SELECT min(code) FROM TRANSACTION group by id order by id) and trans = 'CAN' order by id; | |
-- select * from transaction where | |
-- SELECT id, min(code) FROM TRANSACTION group by id order by id; | |
Select a.* from (SELECT id, min(code) as code FROM TRANSACTION group by id) as a left join transaction as b on a.id=b.id and a.code=b.code where b.trans='CAN' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment