Welcome to new things

[Technical] [Electronic work] [Gadget] [Game] memo writing

SQL

Memo for a slightly elaborate use of BigQuery (etc.)

I usually use Google BigQuery only for simple aggregate SQL, but there are many other useful functions besides aggregate SQL. However, since I don't use it often and when I do try to use it, I start by looking for a manual, so I'll put tog…

A note on a slightly more elaborate use of BigQuery (scheduled queries)

I usually use Google BigQuery only for simple aggregate SQL, but there are many other useful functions besides aggregate SQL. However, since I don't use it often and when I do try to use it, I start by looking for a manual, so I'm going to…

Notes on a slightly more elaborate use of BigQuery (programming)

I usually use Google BigQuery only for simple aggregate SQL, but there are many other useful functions besides aggregate SQL. However, since I don't use it often and when I do try to use it, I start by looking for a manual, so I'll put tog…

Memo for slightly elaborate usage of BigQuery (table creation and data update)

I usually use Google BigQuery only for simple aggregate SQL, but there are many other useful functions besides aggregate SQL. However, since I don't use it often and when I do try to use it, I start by looking for a manual, so I'll put tog…

Memo on how to use BigQuery in a slightly more elaborate way (views, materialized views, table functions)

I usually use Google BigQuery only for simple aggregate SQL, but there are many other useful functions besides aggregate SQL. However, since I don't use it often and when I do try to use it, I start by looking for a manual, so I'll put tog…

I want to handle JavaScript arrays in SQL.

I usually use SQL, but when I am working with array data in JavaScript, I sometimes wish I could write queries in SQL for JavaScript arrays. On the other hand, C# has a language called LINQ that can process arrays with SQL-like queries. Th…

How to remember SQL window functions (analysis functions)

When I started learning SQL, the window functions (analytic functions) were the most difficult to understand. Although you do not need to use the window function when using a database simply as a place to store and retrieve data, it is a v…

Memo on how to use SQLite with JavaScript

This is a memo on how to use SQLite with JavaScript. We did not elaborate too much, but focused on the minimum necessary functions. I will not go into the usage of SQLite itself, but please refer to this way (direction close to the speaker…

How to add a read-only user to SQL Server (Azure SQL Database)

SQL Server data is read by BI tools to create graphs. In that case, we did not want to use a user with write permission because the data would only be read and various people would create graphs, so we created a read-only user for sharing.…

You should not write queries across databases in Azure SQL Database.

I did not know that SQL Server was the first time to use Azure SQL Database, but in SQL Server, queries across databases can be easily written by specifying the database, as shown below. SELECT * FROM [<db_name>].dbo.test_table However, when I try </db_name>…

How to do monthly/weekly aggregation in SQL Server

To aggregate data by month/week, first find the beginning date of the month/week of the date and GROUP by that beginning date. If the DATE_TRUNC() function can be used to get the head date, such as Google BigQuery, you can aggregate the da…

How to get the last record of a group in SQL

For example, "In a user's event log, I want to extract the last event the user performed." Sometimes you want to retrieve the last record of data divided by groups. The window function can be used to obtain the following WITH tbl AS ( SELE…

Load a MySQL database into BigQuery with schema-less partitioning

BigQuery can handle huge amounts of data, but you don't have to worry about the infrastructure at all (really, at all), and it's fast and cheap, It is tempting to put all your data into BigQuery and process it all with BigQuery. That's why…

How to create a calendar table in SQL Server

I wanted a calendar table in SQL Server (Azure SQL Database), so here is a memo on how to create one. I googled, and it seems to be created by creating a table with "WITH" and then making a recursive call from "UNION ALL" in the table defi…

How to create a calendar table in Google BigQuery

When aggregating data that jumps around by date, you may want a calendar table. You can create a calendar table in Google BigQuery with the following GENERATE_DATE_ARRAY()" creates a calendar array, and "UNNEST()" expands the array to rows…