mysql> create database kgtest;
Query OK, 1 row affected (0.03 sec)
mysql> use kgtest
Database changed
mysql> create table students (`id` int(11) not null, `name` varchar(10) not null);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into students value(1,'tom');
Query OK, 1 row affected (0.03 sec)
mysql> insert into students value(2,'Jerry');
Query OK, 1 row affected (0.00 sec)
mysql> select * from students;
+----+-------+
| id | name |
+----+-------+
| 1 | tom |
| 2 | Jerry |
+----+-------+
2 rows in set (0.00 sec)
mysql> create table student2 (`id` int(11) not null, `name` varchar(10) not null);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into student2 value(1,'tomas');
Query OK, 1 row affected (0.00 sec)
mysql> insert into student2 value(2,'rose');
Query OK, 1 row affected (0.00 sec)
mysql> select * from student2;
+----+-------+
| id | name |
+----+-------+
| 1 | tomas |
| 2 | rose |
+----+-------+
2 rows in set (0.00 sec)
mysql> update students st1,student2 st2 set st1.name = st2.name,st2.name = 'kitarou' where st1.id = st2.id;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> select * from student2;
+----+---------+
| id | name |
+----+---------+
| 1 | kitarou |
| 2 | kitarou |
+----+---------+
2 rows in set (0.00 sec)
mysql> select * from students;
+----+-------+
| id | name |
+----+-------+
| 1 | tomas |
| 2 | rose |
+----+-------+
2 rows in set (0.00 sec)
2012年10月22日月曜日
update複数テーブルmysql
ラベル:
mysql
update条件にjoinが必要、あるいは、複数テーブルを更新するときに使うね、あまりないと思う
2012年10月17日水曜日
vbaでgoogleのマップAPIにアクセスする
ラベル:
google api,
vba
まずは「ツール」→「参照設定」で「Microsoft XML. vX.0」を追加して下さい。
参考URL、ありがとう!
URL1
URL2
Sub httpRequest()
Dim HttpReq As MSXML2.XMLHTTP
Dim DomDoc As MSXML2.DOMDocument
Dim targetURL As String
targetURI = "http://maps.google.co.jp/maps/geo?key=&output=xml&q=" & EncodeURI("大宮市吉野町1-1-2")
'HTTP GET
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
HttpReq.Open "GET", targetURI, False
HttpReq.send (Null)
'XML PARSE
Set DomDoc = CreateObject("MSXML2.DOMDocument")
DomDoc.LoadXML (HttpReq.responseText)
Set HttpReq = Nothing
Set DomDoc = Nothing
End Sub
Function EncodeURI(uri As String) As String
Set sc = CreateObject("ScriptControl")
sc.Language = "JScript"
Set js = sc.CodeObject
EncodeURI = js.encodeURIComponent(uri)
End Function
参考URL、ありがとう!
URL1
URL2
excelをDBにして、wordやpower pointとデータ連携
ラベル:
vba
ツール→参照設定から、Microsoft Activex Data Objects 2.x Libraryを追加しておく
Private Sub openDB()
Dim CN As ADODB.Connection
Dim RS As ADODB.Recordset
Set CN = New ADODB.Connection
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\UserName\My Documents\data.xls;" & _
"Extended Properties='Excel 8.0;HDR=YES'"
Set RS = CN.Execute("select * from [シート名$] where 銘柄名 like '%日本%';")
Do Until RS.EOF
Debug.Print RS.Fields(0); RS.Fields(1); RS.Fields(2)
RS.MoveNext
Loop
End Sub
2012年10月16日火曜日
exclude(エクスクルード)除外のJOIN関係はないですか?
ラベル:
mysql
MySQLではLEFT・RIGHT (OUTER)、INNER JOINはありましたが、除外の関係はないでしょうか?
この図のようにAからBの部分を除外して、緑の部分を取得するクエリーの書き方はありませんか?
Aの中からidがBにも存在するレコードを除去して、Aのレコードを取得
この図のようにAからBの部分を除外して、緑の部分を取得するクエリーの書き方はありませんか?
Aの中からidがBにも存在するレコードを除去して、Aのレコードを取得
select * from table_a A left outer join table_b B on B.id = A.id where B.id IS null
2012年10月7日日曜日
VBAのscripting.dictionaryをPHPのvar_dumpみたいに出力
ラベル:
vba
'定数 値 内容
' vbEmpty 0 Empty値
' vbNull 1 Null値
' vbInteger 2 整数型
' vbLong 3 長整数型
' vbSingle 4 単精度浮動小数点数型
' vbDouble 5 倍精度浮動小数点数型
' vbCurrency 6 通貨型
' vbDate 7 日付型
' vbString 8 文字列型
' vbObject 9 オブジェクト
' vbError 10 エラー値
' vbBoolean 11 ブール型
' vbVariant 12 バリアント型(バリアント型配列にのみ使用)
' vbDataObject13 非OLEオートメーションオブジェクト
' vbDecimal 14 10進数型
' vbByte 17 バイト型
' vbArray 8192配列
Public Sub var_dump(ByVal obj As Scripting.Dictionary)
Dim pi As Variant
Dim strVal As String
Static strTab As String
strTab = strTab + vbTab
For Each pi In obj.Keys
If Not IsObject(obj.Item(pi)) Then
Select Case VarType(obj.Item(pi))
Case vbEmpty
strVal = "(Empty)"
Case vbNull
strVal = "(NULL)"
Case vbInteger
strVal = "(Interge)"
Case vbLong
strVal = "(Long)"
Case vbSingle
strVal = "(Single)"
Case vbDouble
strVal = "(Double)"
Case vbCurrency
strVal = "(Currency)"
Case vbDate
strVal = "(Date)"
Case vbString
strVal = "(String)"
Case vbDecimal
strVal = "(Decimal)"
Case vbByte
strVal = "(Byte)"
Case vbArray
strVal = "(Array)"
End Select
Debug.Print strTab & pi & " -> " & strVal & obj.Item(pi)
Else
If TypeName(obj.Item(pi)) = "Dictionary" Then
var_dump obj.Item(pi)
Else
Debug.Print strTab & pi & " -> " & "(object)" & TypeName(obj.Item(pi))
End If
End If
Next
End Sub
2012年10月4日木曜日
CREATE TABLE SELECTの中にAUTO_INCREMENTのIDを付ける、おまけにCHARACTERをUTF8
ラベル:
mysql
CREATE TABLE SELECTの中にAUTO_INCREMENTのIDを付ける、おまけにCHARACTERをUTF8
create table nek_in_tdb
(
id INT PRIMARY KEY AUTO_INCREMENT
,company_code VARCHAR( 25 ) NOT NULL ←無くでも問題ない
,name_jp VARCHAR(255) NOT NULL ←無くでも問題ない
) CHARACTER SET 'utf8'
select distinct
n.company_code
,n.name_jp
from company_tdb t
inner join company_nik n
on t.search_key = n.name_jp;
登録:
コメント (Atom)
