출처 : http://www.zetswing.com/bbs/board.php?bo_table=MySQL_LEC&wr_id=50
select * from goods where name like replace(name,' ','') like '%$name%'; (goods table에서 name필드의 공백을 제거하고 변수와 like 비교검색) select count(*) from goods where left(signdate,10) = curdate() (goods table에서 signdate(data타입)의 좌측의 10개문자만 가져와서 오늘 날짜와 비교) select * from goods where from_unixtime(orderdate) between '2003-01-01' and '2004-01-01'; (goods table에서 timestamp형인 날짜형을 실제 날짜와 비교시 from_unixtime()함수로변환해사용) select SUM(if(paymethod='bank',round(payM/exchange),payM)) from trade; (trade테이블에서 paymethod컬럼의 값이 bank이면 round(payM/exchange) 의값들을 아니면 payM의 값들의 합을 출력합니다.) select g.name,count(tg.idx) from goods as g,trade_goods as tg where g.idx=tg.goodsIdx group by g.idx order by 2 desc; (goods와 trade_goods을 조인하여 trade_goods 테이블에서 판매된 상품의 idx별로 그룹지어 2번째 출력컬럼인 count(tg.idx)의 오름차순으로 출력합니다.) select code,count(code) from goods group by code having count(code)>1 (goods table에서 code 별로 그룹지어 count(code)의 갯수가 2개 이상인것만 출력합니다.) select name,count(tradecode) from trade_goods where tradecode='$tradecode' group by tradecode having count(tradecode)>1; (tradecode table에서 $tradecode변수와 tradecode컬럼이 같은 레코드에서 tradecode별로 정렬하고 그룹별갯수가 1개 이상인것만 출력한다.)-(주문서 중복 확인 쿼리)
'DBMS > MySQL' 카테고리의 다른 글
Mysql에서의 null값 고찰 (0) | 2013.07.29 |
---|---|
MYSQL 성능 향상 정리 (0) | 2013.07.29 |
JOIN(조인) 사용하기 (0) | 2013.07.29 |
4.0 추가기능 (0) | 2013.07.29 |
[MySQL] 자동증가값 (0) | 2013.07.29 |