是否可以在mySQL db query中计算一个项并选择它的值?

SELECT a.id AS item_id,
       b.id AS group_id,
       c.user_id,
       COUNT(c.user_id) AS cnt

最佳答案

不。
您需要使用嵌套查询:

SELECT
   a.id AS item_id,
   b.id AS group_id,
   c.user_id,
   d.cnt
FROM
   tableA a,
   tableB b,
   tableC c,
   (SELECT COUNT(user_id) AS cnt from tableC) as d --nested query

关于mysql - 计算ID并在查询中选择它,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6498273/

10-17 02:44