Hi this is my select sql query and its result :
SELECT line,machine_type, COUNT(*) as linewise FROM dr_scan GROUP BY machine_type,line ORDER BY dr_scan
.line
ASC
line | machine_type | linewise |
---|---|---|
1 | Button Attach | 4 |
1 | Double Needle | 1 |
1 | Flatlock | 1 |
1 | Single Needle | 1 |
5 | Button Attach | 2 |
5 | Flatlock | 1 |
5 | Double Needle | 1 |
I want to make this table as below
line | machine_type | linewise |
---|---|---|
1 | Button Attach | 4 |
Double Needle | 1 | |
Flatlock | 1 | |
Single Needle | 1 | |
5 | Button Attach | 2 |
Flatlock | 1 | |
Double Needle | 1 |
2
Answers
use lag to get the previous line sort by line and put it in a case statement such that if the value of lag is equal to line than display blank.
output:
You can replace the
SELECT
forline
by the following, usingrow_number() = 1