查詢爲每個NameID選擇單個最佳記錄,按日期分組,按Zoho Reports下的My DataTable。查詢以基於列值選擇單個最佳記錄
----->
ID Name ID Name Others Colmns Date n Time Error Count Best Unique Record for the Date
1 W0026 Hari x ¦ x ¦ 2013,08,30 14:09:18 13
2 W0027 Johnson x ¦ x ¦ 2013,08,30 14:01:44 0 < This Record for Date 30th
3 W0029 Prem x ¦ x ¦ 2013,08,30 14:04:04 2
4 W0038 Philip x ¦ x ¦ 2013,08,30 14:00:20 0 < This Record for Date 30th
5 W0039 Amit x ¦ x ¦ 2013,08,30 14:08:03 6 <Can Select Eihter of record ID's(5 and 10) as Error Count of both ID's is Same, for Date 30th
6 W0026 Hari x ¦ x ¦ 2013,08,30 8:09:18 10 < This Record for Date 30th
7 W0027 Johnson x ¦ x ¦ 2013,08,30 8:01:44 4
8 W0029 Prem x ¦ x ¦ 2013,08,30 8:04:04 0 < This Record for Date 30th
9 W0038 Philip x ¦ x ¦ 2013,08,30 8:00:20 1
10 W0039 Amit x ¦ x ¦ 2013,08,30 8:08:03 6
11 W0026 Hari x ¦ x ¦ 2013,08,29 14:09:18 5 < This Record for Date 29th
12 W0027 Johnson x ¦ x ¦ 2013,08,29 14:01:44 1
13 W0029 Prem x ¦ x ¦ 2013,08,29 14:04:04 1 < Latest or Any one if Error Count is Same (between ID 5 and 10) for Date 29th
14 W0038 Philip x ¦ x ¦ 2013,08,29 14:00:20 0 < This Record for Date 29th
15 W0039 Amit x ¦ x ¦ 2013,08,29 14:08:03 6
16 W0026 Hari x ¦ x ¦ 2013,08,29 8:09:18 8
17 W0027 Johnson x ¦ x ¦ 2013,08,29 8:01:44 0 < This Record for Date 29th
18 W0029 Prem x ¦ x ¦ 2013,08,29 8:04:04 1
19 W0038 Philip x ¦ x ¦ 2013,08,29 8:00:20 1
20 W0039 Amit x ¦ x ¦ 2013,08,29 8:08:03 0 < This Record for Date 29th
-------> 凡在每個工作日期,我得到2條記錄,每名ID。 我需要查詢最佳記錄(完整行)。
最佳記錄是基於最小值(更好的記錄)在「錯誤計數」欄下選擇的,日期和結果按名稱ID排序。如下面的OutPut Table所示。
XXXXX >>>> 輸出查詢預計
ID Name ID Name x ¦ x ¦ Date & Time Error Count Comment
6 W0026 Hari x ¦ x ¦ 2013,08,30 8:09:18 10
2 W0027 Johnson x ¦ x ¦ 2013,08,30 14:01:44 0
8 W0029 Prem x ¦ x ¦ 2013,08,30 8:04:04 0 < BEST in Each Name ID on 30th
4 W0038 Philip x ¦ x ¦ 2013,08,30 14:00:20 0
5 W0039 Amit x ¦ x ¦ 2013,08,30 14:08:03 6
11 W0026 Hari x ¦ x ¦ 2013,08,29 14:09:18 5
17 W0027 Johnson x ¦ x ¦ 2013,08,29 8:01:44 0
13 W0029 Prem x ¦ x ¦ 2013,08,29 14:04:04 1 < BEST in Each Name ID on 29th
14 W0038 Philip x ¦ x ¦ 2013,08,29 14:00:20 0
20 W0039 Amit
x ¦ x ¦ 2013,08,29 8:08:03 0
XXXXXXX >>>
我使用Zoho的報告(講座免費版),百會報表支持多種簡單的SELECT查詢SQL諸如ANSI,Oracle,Microsoft SQL Server,IBM DB2,MySQL,Sybase,PostgreSQL和Informix方言等方言。我們可以執行用這些方言編寫的查詢。
下面是我的查詢,我覺得有更好的方法來查詢,請建議。 (FYI:截至目前zohoReports不支持SELECT查詢FROM子句)
SELECT myTable.* FROM "myTable"
WHERE myTable."ID"= (SELECT T."ID"=myTable."ID"
FROM "myTable" AS T
WHERE T."Error Count" < myTable."Error Count"
ORDER BY myTable."Error Count" DESC
LIMIT 1)
GROUP BY myTable."Name ID", DATE(myTable."Date n Time")
對於上面的查詢我收到錯誤爲「每當一個表的別名定義,請使用各列之前,使用表別名在SELECT查詢中「但我感覺它滿足了。我在這裏受到攻擊,需要你的幫助。
請嘗試改進縮進! –
嗨拉胡爾,我是第一次來這裏,縮進是困難的所以我有圖像,我以前不加載,在這裏你去與鏈接。 1)表和2)輸出:感謝 – Esha