跳到主要內容

新增一筆與某筆資料部分相同 - MySQL

當需要新增一筆,與現有資料庫相似的資料,要如何做呢?

最簡單的想法就是先用Select取出自己要的資料,再用Insert,但是這樣需要兩個動作,而且還必須去截取Select的資料。所以為了能更快速新增相似資料,就寫簡單的SQL範例。

1
2
3
4
INSERT INTO TableName (Name, PhoneNumber, URL)
SELECT Name, PhoneNumber, 'http://chuehnoneinfonote.blogspot.tw/'
  FROM TableName 
 WHERE UID = '7'

TableName就是資料表名稱,跟著後面括號的三個欄位,則是要寫入的欄位名稱。
Select則是要按照順序取得欄位,URL這個欄位,則是為了表現出能夠與原資料不同的地方,所以用了本Blog的網址,當然這裡可以設一個變數去做寫入。

這應該是最基本的Insert與Select複合使用。

留言

這個網誌中的熱門文章

AndroidManifest的小技巧

當在設定推播時,在  AndroidManifest.xml  上需要指定不同application id時該怎麼辦呢?(可能會有xxx.yyy.com.debug與xxx.yyy.com兩個版本) 有個簡單的小技巧可以實現這件事情。 <permission android:name= "${applicationId}.permission.C2D_MESSAGE" android:protectionLevel= "signature" /> <uses-permission android:name= "${applicationId}.permission.C2D_MESSAGE" /> 參考資料: Using build types in Gradle to run same app that uses ContentProvider on one device

What is phpize

What is phpize According to the PHP official document : The phpize command is used to prepare the build environment for a PHP extension. If you need to build such an extension that from github or another code repositories, you can use  build tools to perform the build manually. 

Android 呼叫 zxing QR code scanner

今天弄個簡單的範例是關於執行QR code掃描的部分 這個方法是直接呼叫 Barcode scanner 的方法 首先在 build.gradle 的 dependencies 加上 compile 'com.google.zxing:android-integration:3.2.1' dependencies { ... compile 'com.google.zxing:android-integration:3.2.1' } 呼叫的方式則是在 Activity or Fragment 中加入執行的程式 IntentIntegrator scanner = new IntentIntegrator(mActivity); scanner. initiateScan (); 要如何得到掃描的值呢?只要 override onActivityResult 就可以囉! @Override protected void onActivityResult ( int requestCode, int resultCode, Intent data) { super . onActivityResult (requestCode, resultCode, data); IntentResult scanner = IntentIntegrator. parseActivityResult (requestCode, resultCode, data); if (scanner != null ) { String code = scanner. getContents (); // 掃描得到的字串 String format = scanner. getFormatName (); // 掃描的格式, 如 QR_CODE } } 附上參考的 java doc Class IntentIntegrator Class IntentResult