2

我正在尝试在 MySQL 中构建一个相当复杂的视图并想做一个有条件的,但它似乎总是失败。

我的观点(简化)是

Select entry AS Entry, ,(select count(`poitems`.`entry`) AS `count(poitems.entry)` from `poitems` where (`poitems`.`PurchaseOrder` = `purchaseorder`.`entry`)) AS `TotalEntries`, from purchase orders

这没关系,但我想做的是添加类似

if ((select count(`poitems`.`entry`) = 0),'query.png',NULL) AS Queryflag

或者只是测试 TotalEntries 的值。

帮助表示赞赏!谢谢!

4

1 回答 1

0

我不能 100% 确定purchaseorderpoitems表中的列名,但以下内容应该让您朝着正确的方向前进:

select t.Entry,
case when t.TotalEntries > 0 then 'query.png' else null end as Queryflag
from
(
select po.entry as Entry,
count(*) as TotalEntries
from purchaseorder po
left outer join poitems poi on poi.purchaseorder = po.entry
group by po.entry
) t;
于 2013-05-15T11:12:05.600 回答