У меня есть следующий запрос, который дает мне общее состояние проекта. Мне было интересно, есть ли лучший способ написать тот же запрос.
пример схемы для таблицы:
CREATE TABLE `test_status`
(
`test_id` int
(11) NOT NULL,
`group_id` int
(11) NOT NULL,
`sub_test_id` int
(11) NOT NULL,
`project_id` int
(11) NOT NULL,
`collection_status` varchar
(20) DEFAULT NULL,
`labeling_status` varchar
(20) DEFAULT NULL,
`upload_status` varchar
(20) DEFAULT NULL,
`upload_date` date DEFAULT NULL,
`disk_number` int
(11) DEFAULT NULL,
`subject_id` varchar
(10) DEFAULT NULL,
`collection_id` varchar
(25) DEFAULT NULL,
`assigned_to` int
(11) DEFAULT NULL,
`assigned_on` date DEFAULT NULL,
`turned_in_date` date DEFAULT NULL,
PRIMARY KEY
(`test_id`,`group_id`,`sub_test_id`,`project_id`));
Мой запрос:
select
(select count(*)
from test_status
where project_id = 7 and collection_status = 'COLLECTED') as collected,
(select count(*)
from test_status
where project_id = 7 and collection_status = 'SCHEDULED') as scheduled,
(select count(*)
from test_status
where project_id = 7 and collection_status = 'CORRUPTED') as corrupted,
(select count(*)
from test_status
where project_id = 7 and collection_status is NULL) as 'not collected',
(select count(*)
from test_status
where project_id = 7 and ((labeling_status = 'GOOD' and (upload_status != 'UPLOADED' or upload_status != 'QUEUED')) or (labeling_status = 'Labeled'))) as 'Labeled',
(select count(*)
from test_status
where project_id = 7 and (labeling_status = 'RAW') or (labeling_status = 'ASSIGNED') ) as 'to be labeled',
(select count(*)
from test_status
where project_id = 7 and labeling_status = 'RE-LABEL') as 'Re-label',
(select count(*)
from test_status
where project_id = 7 and (upload_status = 'UPLOADED' or upload_status = 'QUEUED')) as 'Uploaded',
(select count(*)
from test_status
where project_id = 7 and labeling_status = 'GOOD' and upload_status is null) as 'ready to be uploaded';