wang603603
2018-01-17 08:55
采纳率: 60%
浏览 3.0k

mysql 保存两个变量相除结果,并同时要显示这两个变量?

SELECT 1 as qq , 2 as ww , qq/ww as percent;

错误提示:
[SQL]

SELECT 1 as qq , 2 as ww , qq/ww as percent;
[Err] 1054 - Unknown column 'qq' in 'field list'

正确该如何写?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • 卡卡的喵 2018-01-17 09:07
    已采纳

    SELECT
    t1.qq,
    t2.ww,
    t1.qq / t2.ww AS percent
    FROM
    (SELECT 1 AS qq) t1,
    (SELECT 2 AS ww) t2

    点赞 打赏 评论
  • 如哥 2018-01-17 09:04

    SELECT 1 as qq , 2 as ww , 1/2 as percent;

    点赞 打赏 评论
  • xl5115105 2018-01-17 09:06

    SET @qq = 1;
    SET @ww = 2;
    SELECT @qq as qq , @ww as ww, @qq/@ww as percent;

    点赞 打赏 评论
  • qq_37970311 2018-01-17 09:19

    SELECT
    t1.qq,
    t2.ww,
    t1.qq / t2.ww AS percent
    FROM
    (SELECT 1 AS qq) t1,
    (SELECT 2 AS ww) t2
    这个正解

    点赞 打赏 评论
  • zhouxixue 2018-01-17 10:06

    SELECT 1 as qq , 2 as ww , 1/2 as percent;

    点赞 打赏 评论
  • weixin_41587540 2018-01-18 03:12

    SELECT 1 as qq , 2 as ww , 1/2 as percent; 是对的

    点赞 打赏 评论
  • 潜江小土著 2018-01-19 05:54

    SELECT 1 as qq , 2 as ww , 1/2 as percent; 是对的,真的可行

    点赞 打赏 评论

相关推荐 更多相似问题