zoukankan      html  css  js  c++  java
  • mysql sql灵活运用

    1.mysq获取表的字段及属性

    SELECT * FROM information_schema.COLUMNS WHERE table_name = 'item_url';

     2.正则表达式

    SELECT i.*,c.brand FROM item_base AS i LEFT JOIN item_base AS c ON i.item_id = c.item_id WHERE c.brand IN ('HSTYLE/韩都衣舍','INMAN/茵曼','OSA','ONLY','裂帛') AND i.item_id NOT REGEXP "yihaodian_[0-9]+"

     SELECT * FROM item_base WHERE item_id REGEXP 'yihaodian_[^_]+_[0-9]+'

    SELECT i.item_id, i.item_name, i.cid, i.last_update_time, u.url, u.image_count, u.local_image_address_list, u.image_urls_list, u.original_class  FROM item_base AS i LEFT JOIN item_url AS u ON IF(i.item_id LIKE 'yihaodian_%_%',u.item_id = CONCAT('yihaodian',SUBSTRING(i.item_id,POSITION('_' IN SUBSTRING(i.item_id,11))+10)),i.item_id = u.item_id) LIMIT 0,10

    3.count(*)返回查询结果数目


    SELECT COUNT(*) FROM item_base WHERE brand IN ('HSTYLE/韩都衣舍','INMAN/茵曼','OSA','ONLY','裂帛') AND item_id REGEXP 'yihaodian_[0-9]+' 

    SELECT COUNT(*) FROM item_attr WHERE item_id REGEXP 'yihaodian_[0-9]+'

    SELECT COUNT(*) FROM item_url WHERE item_id REGEXP 'yihaodian_[0-9]+'

    SELECT * FROM item_base WHERE valid = 1 AND item_id REGEXP 'yihaodian_[^_]+_[0-9]+'
    SELECT * FROM item_attr WHERE item_id REGEXP 'yihaodian_[^_]+_[0-9]+'
    SELECT * FROM item_url WHERE item_id REGEXP 'yihaodian_[^_]+_[0-9]+'
    SELECT * FROM item_url WHERE item_id REGEXP 'yihaodian_[0-9]+'

     DELETE FROM item_attr WHERE item_id REGEXP 'yihaodian_[^_]+_[0-9]+'

     4.sql  in java :

    try {
    String field_list = Arrays.toString(fields);
    String field_listc = Arrays.toString(commentsFields);
    String field_listp = Arrays.toString(priceFields);
    String field_listu = Arrays.toString(urlFields);
    String field_lista = Arrays.toString(attrFields);

    sql = " select " +
    field_list.substring(1, field_list.length() - 1) +
    " , " + field_listc.substring(1, field_listc.length() - 1) +
    " , " + field_listp.substring(1, field_listp.length() - 1) +
    " , " + field_listu.substring(1, field_listu.length() - 1) +
    " , " + field_lista.substring(1, field_lista.length() - 1) +
    " from " + tableName +
    " as i left join " +
    ITEM_COMMENTS_TABLE +
    " as c on IF(i.item_id LIKE 'yihaodian_%_%',c.item_id = CONCAT('yihaodian',SUBSTRING(i.item_id,POSITION('_' IN SUBSTRING(i.item_id,11))+10)),i.item_id = c.item_id) left join " +
    ITEM_PRICE_TABLE +
    " as p on IF(i.item_id LIKE 'yihaodian_%_%',p.item_id = CONCAT('yihaodian',SUBSTRING(i.item_id,POSITION('_' IN SUBSTRING(i.item_id,11))+10)),i.item_id = p.item_id) left join " +
    ITEM_ATTR_TABLE +
    " as a on IF(i.item_id LIKE 'yihaodian_%_%',a.item_id = CONCAT('yihaodian',SUBSTRING(i.item_id,POSITION('_' IN SUBSTRING(i.item_id,11))+10)),i.item_id = a.item_id) left join " +
    ITEM_URL_TABLE +
    " as u on IF(i.item_id LIKE 'yihaodian_%_%',u.item_id = CONCAT('yihaodian',SUBSTRING(i.item_id,POSITION('_' IN SUBSTRING(i.item_id,11))+10)),i.item_id = u.item_id) where i.image_complete>=0" +
    " and i.last_update_time between 'TIME_START' and 'TIME_END' ";
    }

  • 相关阅读:
    TortoiseSVN 命令 (命令行执行工具)(转)
    express blend下载
    js绝对地址图片转换成base64的方法
    js判断是否安装flash player及当前版本 和 检查flash版本是否需要升级
    js实现默认或者触发一个事件选中元素内容的方法
    js实现复制功能,将需要复制的内容放入剪切板上
    前端js上传文件插件
    javascript检测浏览器的缩放状态实现代码 是指浏览器网页内容的百分比缩放(按Ctrl和+号键或者-号键的缩放)
    html5 canvas 画图移动端出现锯齿毛边的解决方法
    jquery实现全选/反选功能
  • 原文地址:https://www.cnblogs.com/DjangoBlog/p/3545554.html
Copyright © 2011-2022 走看看