我最初在sql上有以下查询:
SELECT PROJECT_TYPE.PROJECT_TYPE_NAME, PROJECT.PROJECT_NAME, STATUS_TYPE.STATUS_TYPE_NAME,
COUNT(*) AS Tasks
FROM TASK
INNER JOIN PROJECT ON PROJECT.PROJECT_ID = TASK.PROJECT_ID
AND PROJECT.POURCENTAGE < 100 /* the following ANDs filters out inactive projects */
AND PROJECT.PROJECT_TYPE < 6
AND PROJECT.PROJECT_STATUS_ID < 3
INNER JOIN PROJECT_TYPE ON PROJECT.PROJECT_TYPE = PROJECT_TYPE.PROJECT_TYPE_ID
INNER JOIN STATUS_TYPE ON TASK.STATUS_TYPE_ID = STATUS_TYPE.STATUS_TYPE_ID
INNER JOIN PRIORITY_TYPE ON TASK.PRIORITY_TYPE_ID = PRIORITY_TYPE.PRIORITY_TYPE_ID
AND NOT PRIORITY_TYPE.PRIORITY_TYPE_NAME = 'Hold'
AND STATUS_TYPE.STATUS_TYPE_NAME IN ('To do','In Progress', 'To Verify') /* only include projects in these 3 statuses */
GROUP BY PROJECT_TYPE.PROJECT_TYPE_NAME, PROJECT.PROJECT_NAME, STATUS_TYPE.STATUS_TYPE_NAME
order by 2, case status_type_name /* orders by status */
when 'To do' then 1
when 'In Progress' then 2
when 'To Verify' then 3
else 4
end
正确显示某个状态为such的任务计数。但是,我想替换
project.project_name
在另一个名为
的表中列出的较短描述的表project.project_desc
,看起来像this。我试图通过用project.project_desc替换所有project.project_name并添加
来实现这一点。AND PROJECT.PROJECT_DESC IS NOT NULL
在第一个内部联接下。但是,这会导致以下错误
SQL错误(306):text,ntext和image数据类型不能 比较或排序,除非使用IS NULL或LIKE运算符。
我现在不确定这有什么问题,所有的空值都应该被滤除,所以我很困惑为什么查询的运行方式不同于它之前做过,只是阅读一个不同的表。我无权编辑数据库,因此必须通过查询实现这些更改。
答案 0 :(得分:0)
FWIW,我发现这更容易阅读...
SELECT pt.project_type_name
, p.project_name
, st.status_type_name
, COUNT(*) tasks
FROM task t
JOIN project p
ON p.project_id = t.project_id
JOIN project_type pt
ON pt.project_type_id = p.project_type
JOIN status_type st
ON st.status_type_id = t.status_type_id
JOIN priority_type xt
ON xt.priority_type_id = task.priority_type_id
WHERE p.pourcentage < 100
AND p.project_type < 6
AND p.project_status_id < 3
AND xt.priority_type_name != 'hold'
AND st.status_type_name IN('to do','in progress', 'to verify')
GROUP
BY pt.project_type_name
, p.project_name
, st.status_type_name
ORDER
BY p.project_name
, FIELD(status_type_name,'to do','in progress','to verify')