我有以下查询:
SELECT
<output name="s.No" filter="y" title="School EMIS" data="text" width="50" />,
<output name="s.Name" title="School Name" filter="y" data="text" width="130" />,
<output name="s.Area" title="District" width="80" />,
<output name="m.month" title="Month" width="60" />,
<output name="t.yearid" title="Year" width="40" />,
<output name="y.status" title="Database Status" width="75" />,
<output name="j.name" title="Updated By" width="60" />,
<output name="t.dateupdated" title="Date Updated" width="60" hidden="y" />,
<output name="s.statusid" title="School Submission Status" width="60" hidden="y" />
FROM name s LEFT JOIN submissions t ON s.No = t.No
LEFT JOIN month m ON t.monthid = m.monthid
LEFT JOIN status y ON y.statusid = t.statusid
LEFT JOIN jos_users j ON t.user = j.id
WHERE statusid = <input title="Select Status" name="statusid"
type="query" required="y"width="250" query="SELECT DISTINCT CONCAT(status),statusid
FROM status
WHERE statusid = 1 ORDER BY status" />
AND month = <input title="Select Month" name="monthid" type="query" required="y"
width="250" query="SELECT DISTINCT CONCAT(month),monthid FROM month ORDER BY monthid"
/>
AND year = <input title="Select Year" name="yearid" type="query" required="y"
width="250"
query="SELECT year FROM year ORDER BY Yearid" />
GROUP BY s.No
ORDER BY max(t.dateupdated) DESC
查询工作正常。它按 3 SELECTS 列出所有详细信息。我需要它列出“名称”和“提交”表中的所有数据,列出“提交”表中的选定数据,但显示“名称”表中不存在数据的所有其他记录
有谁知道我怎么能做到这一点?请协助。
下表结构:
`Name` table:
no - int 11 (Primary Key)
name - Varchar 255
area - Varchar 255
`Submissions` table:
userid - int (11)
statusid - int (11)
no - int (11) (Primary Key)
name - varchar (255)
area - varchar (255)
month - int (11)
year - int (11)
dateupdated - datetime (Primary Key)
在过渡期间,下面的查询确实显示了所有记录,但是SELECTS
(过滤器)不起作用
我有以下查询:
SELECT
<output name="s.No" filter="y" title="School EMIS" data="text" width="50" />,
<output name="s.Name" title="School Name" filter="y" data="text" width="130" />,
<output name="s.Area" title="District" width="80" />,
<output name="m.month" title="Month" width="60" />,
<output name="t.yearid" title="Year" width="40" />,
<output name="y.status" title="Database Status" width="75" />,
<output name="j.name" title="Updated By" width="60" />,
<output name="t.dateupdated" title="Date Updated" width="60" hidden="y" />
FROM name s LEFT JOIN submissions t ON s.No = t.No
LEFT JOIN month m ON t.monthid = m.monthid
LEFT JOIN status y ON y.statusid = t.statusid
LEFT JOIN jos_users j ON t.user = j.id
WHERE s.no NOT IN (
SELECT status
FROM status
WHERE statusid = <input title="Select Status" name="statusid"
type="query" required="y"width="250" query="SELECT DISTINCT CONCAT(status),statusid
FROM status
WHERE statusid = 1" />
)
AND s.no NOT IN (
SELECT month
FROM month
WHERE month = <input title="Select Month" name="monthid" type="query" required="y"
width="250" query="SELECT DISTINCT CONCAT(month),monthid FROM month ORDER BY monthid"
/>
)
AND s.no NOT IN (
SELECT year
FROM year
WHERE year = <input title="Select Year" name="yearid" type="query" required="y"
width="250"
query="SELECT year FROM year ORDER BY Yearid" />
)
GROUP BY s.No
ORDER BY max(t.dateupdated) DESC
我已经部分解决了这个问题。我现在可以看到字段。我使用了以下查询,我在“名称”表中创建了额外的 NULL 列来实现这一点:
SELECT
<output name="submissions.user" title="User" width="80" />,
<output name="submissions.statusid" title="Status" width="80" />,
<output name="submissions.no"title="no" width="60" />,
<output name="submissions.Name" title="School Name" width="40" />,
<output name="submissions.area" title="District" width="75" />,
<output name="submissions.monthid" title="Month" width="60" />,
<output name="submissions.yearid" title="Year" width="60" />,
<output name="submissions.dateupdated" title="Date Updated" width="60" />
FROM submissions
RIGHT OUTER JOIN name ON submissions.no = name.no
WHERE submissions.statusid = <input title="Select Status" name="submissions.statusid"
type="query" required="y" width="250" query="SELECT DISTINCT CONCAT(status),statusid
FROM status WHERE statusid = 1 ORDER BY status" />
AND submissions.monthid = <input title="Select Month" name="submissions.monthid"
type="query" required="y" width="250" query="SELECT DISTINCT CONCAT(month),monthid
FROM month ORDER BY monthid" />
AND submissions.yearid = <input title="Select Year" name="submissions.yearid"
type="query" required="y" width="250" query="SELECT year FROM year ORDER BY Yearid" />
UNION
SELECT
<output name="name.user" title="User" width="80" />,
<output name="name.statusid" title="Status" width="80" />,
<output name="name.no" filter="y" title="no" data="text" filtertype="grid" width="50"
/>,
<output name="name.Name" title="School Name" filter="y" data="text" width="130" />,
<output name="name.area" title="District" width="80" />,
<output name="name.monthid" title="Month" width="80" />,
<output name="name.yearid" title="Year" width="80" />,
<output name="name.dateupdated" title="Date Updated" width="80" />
FROM name
LEFT OUTER JOIN submissions ON name.no = submissions.no
我现在唯一要做的就是 GROUP 和 ORDER BY
GROUP BY name.No
ORDER BY max(name.dateupdated) DESC
我将如何将其包含在我的查询中?