1

我正在尝试为一个项目组获取一些图像,但似乎无法让乘法与分配的别名一起使用。我已经尝试了下面的脚本并进行了一些修改,但我尝试过的每件事都行不通。

SELECT s.pid AS 'ID', 
       CONCAT_WS(', ', p.lastname, p.firstname) AS 'Name', 
       CONCAT(s.date, ' ', s.time) AS Serviced, 
       p.institution AS Facility, 
       s.description AS 'description title', 
       (SELECT COUNT(*) 
          FROM series se 
         WHERE se.studyid = s.id) 
          AS numseries, 
       (SELECT COUNT(*) 
          FROM image i 
         WHERE i.seriesid = se.id) 
          AS serimages, 
       numseries * serimages AS 'Number of Images' 
  FROM product p, 
          series se 
       JOIN 
          study s 
       ON s.pid = p.id 
GROUP BY s.id 
ORDER BY Serviced DESC
4

3 回答 3

3

试试这个,我把两个都砸了-

SELECT s.pid AS 'ID', 
       CONCAT_WS(', ', p.lastname, p.firstname) AS 'Name', 
       CONCAT(s.date, ' ', s.time) AS Serviced, 
       p.institution AS Facility, 
       s.description AS 'description title', 
       ((SELECT COUNT(*) 
          FROM series se 
         WHERE se.studyid = s.id) 
          * 
       (SELECT COUNT(*) 
          FROM image i 
         WHERE i.seriesid = se.id) 
          ), 
       AS 'Number of Images' 
  FROM product p, 
          series se 
       JOIN 
          study s 
       ON s.pid = p.id 
GROUP BY s.id 
ORDER BY Serviced DESC
于 2012-12-20T17:01:06.017 回答
1

尝试像这样使用它

SELECT 
    t.ID,
    t.Name,
    t.Serviced,
    t.Facility,
    t.title,
    t.numseries,
    t.serimages,
    t.numseries * t.serimages AS 'Number of Images' 
FROM
    (
    SELECT s.pid AS 'ID', 
           CONCAT_WS(', ', p.lastname, p.firstname) AS 'Name', 
           CONCAT(s.date, ' ', s.time) AS Serviced, 
           p.institution AS Facility, 
           s.description AS 'description title', 
           (SELECT COUNT(*) FROM series se WHERE se.studyid = s.id) AS numseries, 
           (SELECT COUNT(*) FROM image i WHERE i.seriesid = se.id) AS serimages       
    FROM product p, series se 
    JOIN study s ON s.pid = p.id 
    ) as t
GROUP BY t.id 
ORDER BY t.Serviced DESC

另外,您在查询中使用的是 cartisin 产品,我的意思是使用 FROM 和两个表。这会带来很多结果。避免它并始终使用 join 代替。

于 2012-12-20T17:29:35.217 回答
0

试试这个:

Select *, ( numseries * serimages ) as 'Number of Images' 
from (SELECT 
        s.pid AS 'ID', 
        CONCAT_WS(', ', p.lastname, p.firstname) AS 'Name', 
        CONCAT(s.date, ' ', s.time) AS Serviced, 
        p.institution AS Facility, 
        s.description AS 'description title', 
        (SELECT COUNT(*) FROM series se WHERE se.studyid = s.id) AS numseries, 
        (SELECT COUNT(*) FROM image i WHERE i.seriesid = se.id) AS serimages 
    FROM product p, series se 
    INNER JOIN study s ON s.pid = p.id 
    GROUP BY s.id 
    ORDER BY Serviced DESC
) as a;
于 2012-12-20T17:05:35.970 回答