Let's say we have a table team_person as below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+======+===========+
| team |    person |
+======+===========+
|   A  |      John |
+------+-----------+
|   B  |     Smith |
+------+-----------+
|   A  |    Walter |
+------+-----------+
|   A  |     Louis |
+------+-----------+
|   C  | Elizabeth |
+------+-----------+
|   B  |     Wayne |
+------+-----------+
 
 
CREATE TABLE team_person AS SELECT 'A' team, 'John' person
UNION ALL  SELECT 'B' team,  'Smith' person
UNION ALL  SELECT 'A' team,  'Walter' person
UNION ALL  SELECT 'A' team,  'Louis' person
UNION ALL  SELECT 'C' team,  'Elizabeth' person
UNION ALL  SELECT 'B' team,  'Wayne' person;
cs

 

To select the table team_person with additional row_number column, either

1
2
SELECT @row_no := @row_no+1 AS row_number, team, person
FROM team_person, (SELECT @row_no := 0) t;
cs

* rownum 초기화 : (SELECT @row_no := 0) t;

 

OR

1
2
3
SET @row_no := 0;
SELECT  @row_no := @row_no + 1 AS row_number, team, person
FROM team_person;
cs

 

will output the result below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
+============+======+===========+
| row_number | team |    person |
+============+======+===========+
|          1 |   A  |      John |
+------------+------+-----------+
|          2 |   B  |     Smith |
+------------+------+-----------+
|          3 |   A  |    Walter |
+------------+------+-----------+
|          4 |   A  |     Louis |
+------------+------+-----------+
|          5 |   C  | Elizabeth |
+------------+------+-----------+
|          6 |   B  |     Wayne |
+------------+------+-----------+
cs

 

Finally, if we want to get the row_number group by column team

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SELECT @row_no := IF(@prev_val = t.team, @row_no + 11) AS row_number
   ,@prev_val := t.team AS team
   ,t.person  
FROM team_person t,
  (SELECT @row_no := 0) x,
  (SELECT @prev_val := '') y
ORDER BY t.team ASC,t.person DESC; 
 
+============+======+===========+
| row_number | team |    person |
+============+======+===========+
|          1 |   A  |    Walter |
+------------+------+-----------+
|          2 |   A  |     Louis |
+------------+------+-----------+
|          3 |   A  |      John |
+------------+------+-----------+
|          1 |   B  |     Wayne |
+------------+------+-----------+
|          2 |   B  |     Smith |
+------------+------+-----------+
|          1 |   C  | Elizabeth |
+------------+------+-----------+
cs

 

출처 : riptutorial.com/mysql/example/19572/row-number-and-group-by-using-variables-in-select-statement

 

MySQL - Row Number and Group By using variables in Select Statement | mysql Tutorial

mysql documentation: Row Number and Group By using variables in Select Statement

riptutorial.com

developer-jjun.tistory.com/23

 

[MySQL] ROWNUM을 사용하여 번호매기기

MySQL에서 Oracle처럼 ROWNUM 사용법 SET구문을 사용하여 ROWNUM 값을 초기화 후 조회 SET @rownum:=0; SELECT @rownum:=@rownum+1, b.* FROM buyingboard b WHERE절에서 초기화 SELECT @rownum:=@rownum+1, b.*..

developer-jjun.tistory.com

 

 

Posted by 셋부터넷
,

highcharts 작업시 y축 중간라인의 텍스트가 보이지 않는문제 해결

1
2
3
4
5
6
7
Highcharts.wrap(Highcharts.Axis.prototype, 'getPlotLinePath', function(proceed) {
    var path = proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    if (path) {
        path.flat = false;
    }
    return path;
});
cs

 

출처 : stackoverflow.com/questions/52621676/labels-are-not-rendering-for-plotlines-highcharts

 

Labels are not rendering for plotLines highcharts

I'm trying to render plotLines on Highcharts. But somehow I'm not able to render labels on plotLines. Here is the code snippet: var chart = new Highcharts.Chart({ chart: { ren...

stackoverflow.com

 

Posted by 셋부터넷
,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SELECT 
    DATE_FORMAT(m1, '%Y-%m') AS standardDate
FROM(
    SELECT 
        ('2020-01-11' - INTERVAL DAYOFMONTH('2020-01-11')-1 DAY) +INTERVAL m MONTH as m1
    FROM(
        SELECT @rownum:=@rownum+1 as m FROM
        (SELECT 1 union SELECT 2 union SELECT 3 union SELECT 4) t1,
        (SELECT 1 union SELECT 2 union SELECT 3 union SELECT 4) t2,
        (SELECT 1 union SELECT 2 union SELECT 3 union SELECT 4) t3,
        (SELECT 1 union SELECT 2 union SELECT 3 union SELECT 4) t4,
        (SELECT @rownum:=-1) t0
    ) d1
) d2 
WHERE m1 <= '2020-09-30' 
ORDER BY m1
cs

 

참고 : stackoverrun.com/ko/q/4011597

 

mysql에서 두 날짜 사이의 월 목록을 얻는 방법

mysql에서 두 날짜 사이의 월 목록을 가져 왔습니다. For Example:My Input is From date 23-01-2013 To Date 01-04-2014 Output Should be Jan 2013, Feb 2013, March 2013, . . . Jan 2014, Feb 2014, Mar 2014, Apr ...

stackoverrun.com

 

 

Posted by 셋부터넷
,