'2019/10'에 해당되는 글 3건

SELECT *  FROM (

     SELECT * FROM TABLE WHERE X = X

          OREDER BY price ASC

)  GROUP BY code ORDER BY ORDER

 

Mysql 에서 가격이 데일리로 들어가 있는경우 낮은 가격을 가져오고 서브쿼리에서 크룹핑하고 순서를 줬다

 

마리아 DB에선 내부쿼리에서 order 불허!!!!!!!!

 

편법 생각하자.....

SELECT *  FROM (

     SELECT * FROM TABLE WHERE X = X

          GROUP BY code , price

)  GROUP BY code ORDER BY  order

 

내부쿼리에 그룹에 두번째 디폴트 낮은 순이니 다시 그룹으로 ㄱㄱ

 

블로그 이미지

스마트전

,

character 한번에 바꾸기

MySQL 2019. 10. 16. 18:36

alter table table_name convert to character set UTF8;

블로그 이미지

스마트전

,

달력 숫자 채우기

MySQL 2019. 10. 16. 18:35

create table t (n int);

 

insert into t values (1);

 

insert into t select * from t; -- 이걸 13번 반복하면 4096행이 생성됨. 10년치 데이터라면 대략 3650일이므로 이정도면 충분

 

create table date_t (d date, ds char(8)); -- 날짜를 저장할 테이블

 

insert into date_t

select d, date_format(d, '%Y%m%d') from (

  select @rnum:=@rnum+1 as rownum, date(adddate('2009-01-01', interval @rnum day)) as d

  from (select @rnum:=-1) r, t

  ) t

where year(d) < 2019;

 

참고로, 날짜는 date 타입에 저장하는 것이 yyyymmdd형식의 문자열로 저장하는 것보다 좋습니다

 

insert into high_block (stay_code , room_code , r_block ,  chk_date )

SELECT 'high01' , '1001' , 0 , date_format(d, '%Y-%m-%d') from (

select @rnum:=@rnum+1 as rownum, date(adddate('2019-01-01', interval @rnum day)) as d

from (select @rnum:=-1) r, t

) t

where year(d) < 2021;

 

 

은근 많이 쓰는거

블로그 이미지

스마트전

,