V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
shimingzhoudf
V2EX  ›  Python

mysql 查询

  •  
  •   shimingzhoudf · 2020-09-04 15:16:26 +08:00 · 1935 次点击
    这是一个创建于 1302 天前的主题,其中的信息可能已经有所发展或是发生改变。

    A 表有 1,2,3,4 个字段

    我现在查询结果需要是这样

    表名 中文名 1 2 3 4 数据 x x x x x ... ... .. .. .. ..

    其实中文名就是 4 字段的值

    我看别人这样写过: select 4 中文名, * where 表名;

    但我自己用老报语法错误

    10 条回复    2020-09-07 10:38:46 +08:00
    shimingzhoudf
        1
    shimingzhoudf  
    OP
       2020-09-04 15:17:32 +08:00
    语法是这样 select 4 中文名, * from 表名 where 条件;
    qiayue
        2
    qiayue  
       2020-09-04 15:22:09 +08:00
    指定了字段名之后,不能用 * 了吧
    specita
        3
    specita  
       2020-09-04 15:25:49 +08:00
    描述得让人看不懂,建议直接贴 sql 和异常
    shimingzhoudf
        4
    shimingzhoudf  
    OP
       2020-09-04 16:19:54 +08:00
    @specita 这个展示出来没换行
    goodboy95
        5
    goodboy95  
       2020-09-04 16:22:32 +08:00
    命令行的话,你直接 select *,上面应该自带字段名
    程序里面用的话,你 select 出来之后,肯定要自己把字段名拼上去
    twinsdestiny
        6
    twinsdestiny  
       2020-09-04 22:48:19 +08:00
    select 4 中文名,t.* from 表名 t
    加个别名应该可以
    foolgry
        7
    foolgry  
       2020-09-05 19:07:48 +08:00
    *放前面试试
    xsonglive
        8
    xsonglive  
       2020-09-05 22:55:58 +08:00
    用别名可以的.
    shimingzhoudf
        9
    shimingzhoudf  
    OP
       2020-09-07 10:38:07 +08:00
    @twinsdestiny 可以的,感谢
    shimingzhoudf
        10
    shimingzhoudf  
    OP
       2020-09-07 10:38:46 +08:00
    @xsonglive 加个别名能达到我期望要求
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3394 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 335ms · UTC 10:40 · PVG 18:40 · LAX 03:40 · JFK 06:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.