java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1@464946a0
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:793) at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:814) at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331) at android.widget.ViewFlipper.onDetachedFromWindow(ViewFlipper.java:104) at android.view.View.dispatchDetachedFromWindow(View.java:6033) …….(略刪)
對表格B做統計 SELECT `A_id`, COUNT(`B_id`) as `B_count` FROM `tableB` GROUP BY `A_id`;
得到 A_id B_count 的欄位
對表格B做統計 SELECT `A_id`, COUNT(`C_id`) as `C_count` FROM `tableC` GROUP BY `A_id`;
得到 A_id C_count 的欄位
問題來了
我們有學過JOIN,他們都有A_id 我們如何把他們另外統計的二張表格合起來
還要顯示A表格的其他內容
你要如何做?
————————————————————————–
第一,我可能會想到在JOIN的過程中
不能直接JOIN起來的話
好歹列數也要一致相同吧
所以我改這樣下
SELECT `A_id`, `A_name`, COUNT(`tableB`.`A_id`) as `B_count` FROM `tableA` LEFT JOIN `tableB` ON `tableA`.`A_id`=`tableB`.`A_id` GROUP BY `tableA`.`A_id`;
SELECT `A_id`, `A_name`, COUNT(`tableC`.`A_id`) as `C_count` FROM `tableA` LEFT JOIN `tableC` ON `tableA`.`A_id`=`tableC`.`A_id` GROUP BY `tableA`.`A_id`;
使用LEFT JOIN是因為INNER JOIN是有對到資料才會出現
而LEFT JOIN才會顯示Count是零的狀況
這樣也不盡人意……
————————————————————————–
解答
找好久才找到這個解答
我個人認為其重要性接近死背這個架構
SELECT `A_id`, `A_name`,
(SELECT COUNT(*) FROM `tableB` WHERE `tableB`.`A_id`=`tableA`.`A_id`) AS `B_count`,
(SELECT COUNT(*) FROM `tableC` WHERE `tableC`.`A_id`=`tableA`.`A_id`) AS `C_count`,
FROM `tableA`;
這個架構叫做
關聯子查詢
SQL語句裡面跟外面有產生關聯的
但是光看問題不會馬上想到這個架構
解釋
簡單來說一句SQL語法做了三個動作
從刮號裡面先看好了
裡面有二句SQL語法,看起來像是獨立的但不能跑
會有這個錯誤
#1054 – Unknown column ‘tableA.A_id’ in ‘where clause’
因為他找不到tableA在哪裡
SELECT COUNT(*) FROM `tableB` WHERE `tableB`.`A_id`=`tableA`.`A_id`
這句的意思是計算tableB總共有幾筆
我們有學到在WHERE裡面打上
`tableB`.`A_id`=`tableA`.`A_id`
意思就是要讓表格合併起來 (像是INNER JOIN)
—————————————————-
*TIPS:
WHERE id=id能獨立跑的是這個
SELECT `tableA`.*, `tableB`.* FROM `tableA`, `tableB` WHERE `tableB`.`A_id`=`tableA`.`A_id`
用INNER JOIN 改寫變成
SELECT `tableA`.*, `tableB`.* FROM `tableA`INNER JOIN `tableB` ON `tableB`.`A_id`=`tableA`.`A_id`
—————————————————-
在來就是外面那層
SELECT `A_id`, `A_name`, (……) AS `B_count`, (……) AS `C_count`, FROM `tableA`;
(select count(*) from customerservice B where B.id = A.id and B.Q1=’Excellent’) AS E, (select count(*) from customerservice C where C.id = A.id and C.Q1=’Satisfaction’) AS S, (select count(*) from customerservice D where D.id = A.id and D.Q1=’Poor’) AS P FROM student A
open an Android project under eclipse and call it ‘a’
open the ‘a’ properties and check the ‘Is Library’ check box.
open another Android project and name it ‘b’.
open it’s properties and add ‘a’ as an android library it uses.
open the android plugin preferences and change the build from silent to verbose
clean both projects.
on linux everything is neat, on windows it crashes after the line:’baseFile zd has flavor (null)’ which according to linux should be:’baseFile 0 has flavor ,,,,,,,,,,,hdpi,,,,,,,’ most chances null pointer exception occurs here, the question is why only on windows ?
; ; This section seems to be required for WinUsb driver installation. ; If this section is removed the installer will report an error ; "Required section not found in INF file". ; [ClassInstall32] Addreg = AndroidWinUsbClassReg