スキップしてメイン コンテンツに移動

投稿

ラベル(sql)が付いた投稿を表示しています

【sql server】距離が近い順にソートするクエリ(sql)

sql serverにはgeographyというカラムがいつの間にできてます。 これを利用すると特定位置から近い順にデータが読み込めます。 DECLARE @InputLatitude FLOAT = 40 . 7128 ; DECLARE @InputLongitude FLOAT = - 74 . 0060 ; SELECT TOP 50 * FROM YourTableName ORDER BY geographyColumn . STDistance (geography:: Point (@InputLatitude, @InputLongitude, 4326 )) ASC ; もしあなたから近いユーザーのリストが欲しい場合このようにクエリを書けばオッケーです。 しかしフィールドは? create table tUser ( uSn bigint identity( 1 , 1 ), uUid nvarchar( 200 ), uLoc geography, uLocText nvarchar( 200 ) ) このようにテーブルを作りました。位置情報はuLocTextに入れ、uLocにはgeography値を入れます。 declare @uLocText nvarchar( 200 ), @uSn bigint set @uLocText = ' 40.7128, -74.0060 ' set @uSn = 1 UPDATE tUser SET uLoc = geography:: Point (CAST( SUBSTRING (@uLocText, 1 , CHARINDEX( ' , ' , @uLocText) - 1 ) AS FLOAT), CAST( SUBSTRING (@uLocText, CHARINDEX( ' , ' , @uLocText) + 1 , LEN(@uLocText)) AS FLOAT), 4326 ) , uLocText = @uLocText where uSn = @uSnこ このように計算して入れたらuLocにはバイナリーコードのように入って目

MySQL basic - Knowledgebase of giip

  Management Connect from shell mysql -u root -h giipdb.mysql.com -p -P 3306 -u  : user -p  : ask password -h  : host -P  : Port show running SQL show processlist; show full processlist \G Cursor https://codeday.me/jp/qa/20190213/271235.html  - jp Binlog(Binary Log) https://www.ritolab.com/entry/98 managing binary log https://www.percona.com/blog/2015/07/30/why-base64-outputdecode-rows-does-not-print-row-events-in-mysql-binary-logs/ Decode binary log Start option Official :  https://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html stop mysqladmin -u root -p shutdown Run from sql file Official :  https://dev.mysql.com/doc/refman/8.0/en/mysql-batch-commands.html Tuning Innodb Check tuning point using mysqltuner You can tune easy by suggestion on mysqltuner $ wget https://github.com/major/MySQLTuner-perl/zipball/master $ unzip master $ cd master $ ./mysqltuner.pl https://corporate.inter-edu.com/developper/1373 innodb storage engine https://enterprisezine.jp/dbonline/detail/3829

ORACLE Useful SQL

String SUBSTR(Substring, left, right) /* if you want using left */ select SUBSTR( ' mystr ' , 1 , 3 ) from dual; -- result : mys /* if you want using right */ select SUBSTR( ' mystr ' , - 3 ) from dual; -- result : str /* if you want using substring */ select SUBSTR( ' mystr ' , 3 , 2 ) from dual; -- result : st replace(sourcetext, findstr, replacestr) select REPLACE( ' mystr ' , ' s ' , ' o ' ) from dual; -- result : myotr Like including  _  character select * from all_tables where table_name like ' TBL \_ % ' ; Math mod select mod( 10 , 7 ) from dual; -- result : 3 Others Find String from Procedure source SELECT * FROM ALL_SOURCE WHERE TEXT LIKE ' %EVENTSTRING% ' ORDER BY TYPE, NAME, LINE ; Japanese Traditional datetime https://www.shift-the-oracle.com/sql/functions/to_date.html SQL > select to_char( SYSDATE , ' EEDL ' , ' NLS_CALENDAR= ' ' JAPANESE IMPER