goo blog サービス終了のお知らせ 

こんにちは、ねこです。

自称プログラマのおばちゃんのブログです。いろいろあるよねぇ~。

MCSA SQL Server3/datetimeフィールドを『デザイン』から自動的に現在時刻にセットする方法

2020-02-10 23:47:50 | 空手

【datetimeフィールドを『デザイン』から自動的に現在時刻にセットする方法】

【手順】

1.SQL Management Studioを開始する。

2.データベースを選び、テーブル名の上で右クリックして『デザイン』を開ける。

3.すでに必要箇所のデータタイプ『datetime』がある場合はそれを選択する。ない場合は先にコラムを作成してデータタイプを『datetime』に設定する。

4.『getdate()』を『Column Properties』->『Default Value or Binding』に下記のように設定する。

注意:エディターですでに値を入力している場合はエラーが出る可能性があります。その場合は一度閉じてからリフレッシュするか、最悪でももう一度テーブルを作り直すかすれば動きます。


MCSA SQL Server 2016 /70-762/TableのWithNocheck/CascadeとExtended Event

2019-12-09 13:52:27 | 空手

本日まで、『CBT Nuggets』を『9. Implementing Indexes』のラボまでを網羅。ねむぅーい。

そして、今から『Examtopics』を始めます。

どんな問題があるのかわからないので、どんどん解いていって間違えたものをこちらにメモっときます。

1.

You must modify the ProductReview Table to meet the following requirements:
The table must reference the ProductID column in the Product table

次の要件を満たすために、ProductReviewテーブルを変更する必要があります。
テーブルは、ProductテーブルのProductID列を参照する必要があります。


✑ Existing records in the ProductReview table must not be validated with the Product table.ProductReviewテーブルの既存のレコードは、Productテーブルで検証しないでください。
✑ Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.ProductReviewテーブルによってレコードが参照されている場合、Productテーブルのレコードを削除できないようにする必要があります。
✑ Changes to records in the Product table must propagate to the ProductReview table.Productテーブルのレコードへの変更は、ProductReviewテーブルに反映される必要があります。

(Google翻訳使い始めました。めっちゃ楽やん。

(うぅ~ん、この辺もう読まんでもいいよ。)You also have the following database tables: Order, ProductTypes, and SalesHistory, The transact-SQL statements for these tables are not available.
You must modify the Orders table to meet the following requirements:
✑ Create new rows in the table without granting INSERT permissions to the table.
✑ Notify the sales person who places an order whether or not the order was completed.
You must add the following constraints to the SalesHistory table:
✑ a constraint on the SaleID column that allows the field to be used as a record identifier
✑ a constant that uses the ProductID column to reference the Product column of the ProductTypes table
✑ a constraint on the CategoryID column that allows one row with a null value in the column
✑ a constraint that limits the SalePrice column to values greater than four
Finance department users must be able to retrieve data from the SalesHistory table for sales persons where the value of the SalesYTD column is above a certain threshold.
You plan to create a memory-optimized table named SalesOrder. The table must meet the following requirements:
✑ The table must hold 10 million unique sales orders.
✑ The table must use checkpoints to minimize I/O operations and must not use transaction logging.
✑ Data loss is acceptable.
Performance for queries against the SalesOrder table that use Where clauses with exact equality operations must be optimized.
You need to enable referential integrity for the ProductReview table.
How should you complete the relevant Transact-SQL statement? To answer? select the appropriate Transact-SQL segments in the answer area.

ProductReviewテーブルの参照整合性を有効にする必要があります。
関連するTransact-SQLステートメントをどのように完成させる必要がありますか? 答える? 回答領域で適切なTransact-SQLセグメントを選択します。


Hot Area:

こりゃ、全部読んでも仕方ない手の問題ですね。なので、青字で書いてある部分のみを読み始めます。「ProductReview」を聞いてます。

<答え>

ALTER TABLE dbo.ProductReview WITH NOCHECK
ADD CONSTRAINT FK_productReview_Product FOREIGN KEY (ProductID)
REFERENCES Product (productID) ON DELETE NO ACTION ON UPDATE CASCADE

WITH NOCHECK

We should use WITH NOCHECK as existing records in the ProductReview table must not be validated with the Product table.

「✑ Existing records in the ProductReview table must not be validated with the Product table.」より、「Product table」によってチェックされたらいけないとありますね。だから答えは「WITH NOCHECK」

ON DELETE NO ACTION ON DELETE NO CASCADE
Deletes should not be allowed, so we use ON DELETE NO ACTION.

「✑ Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.」もし、値が「ProductReview table」によって参照されている場合、「Product table」からは削除できないとあります。だから「 ON DELETE NO ACTION」が答えの前半。でもどうやったら「参照」されているのかという部分が抜け落ちてるような気がする。それに「UPDATE」じゃなくって「DELETE」になってるよ。。。

Updates should be allowed, so we use ON DELETE NO CASCADE

「✑ Changes to records in the Product table must propagate(伝える) to the ProductReview table.」より「Product table」の変更は「ProductReview table」に反映されるとあり、その点において更新はされることとあります。だから答えは『ON DELETE NO CASCADE』

NO ACTION: the Database Engine raises an error, and the update action on the row in the parent table is rolled back.データベースエンジンがエラーを出し、親テーブルの更新された内容はロールバックされる。

 

CASCADE: corresponding rows are updated in the referencing table when that row is updated in the parent table.親テーブルでの更新は子テーブルに反映される。


Note:

ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT }
Specifies what action happens to rows in the table that is altered, if those rows have a referential relationship and the referenced row is deleted from the parent table. それらの行に参照関係があり、参照された行が親テーブルから削除された場合、変更されたテーブル内の行に何が起こるかを指定します。
ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT }
Specifies what action happens to rows in the table altered when those rows have a referential relationship and the referenced row is updated in the parent table.それらの行に参照関係があり、参照された行が親テーブルで更新されたときに、変更されたテーブル内の行に何が起こるかを指定します。

The default is NO ACTION.

デフォルトはNO ACTIONです。

 

Note:

You must modify the ProductReview Table to meet the following requirements:以下の内容に沿って「ProductReview Table」を完成させること
1. The table must reference the ProductID column in the Product table「Product table」の「ProductID 」コラムを参照させる。
2. Existing records in the ProductReview table must not be validated with the Product table.現在ある「ProductReview table」の値は「Product table」と一緒にチェックされないこと。
3. Deleting records in the Product table must not be allowed if records are referenced by the ProductReview table.「Product table」の削除は「ProductReview table」に参照された値がある以上、行われない。
4. Changes to records in the Product table must propagate to the ProductReview table.「Product table」の変更は「ProductReview table」に反映されるとあり、その点において更新はされること。

https://msdn.microsoft.com/en-us/library/ms190273.aspx

https://msdn.microsoft.com/en-us/library/ms188066.aspx

 


2.

You are experiencing performance issues with the database server.
You need to evaluate schema locking issues, plan cache memory pressure points, and backup I/O problems.
What should you create?

データベースサーバーでパフォーマンスの問題が発生しています。
スキーマロックの問題を評価し、キャッシュメモリのプレッシャーポイントを計画し、I / Oのバックアップの問題を解決する必要があります。
何を作成する必要がありますか?

  • A. a System Monitor report
  • B. a sys.dm_tran_database_transaction dynamic management view query
  • C. an Extended Events session that uses Query Editor
  • D. a Microsoft SQL Profiler trace
<答え>C
Extended Events: considered as "the best way" by the SQL Server purists. You can configure Extended Events to find Locking Issues in SQL Server.一番推奨されているそうな。
 
こちらにとってもよい「Extended Events」の設定をする方法を載せたサイトがあるので、ねこみたく英語読むの嫌な人でもイメージだけでも見てやってください。とってもわかりやすいです。
create new extended event session
 

 

 

あぁ、年のせいかすぐ眠くなる。


Microsoft MCSA SQL Server 2016 (70-761)むぼーな挑戦15/FULL JOIN,CROSS JOIN,UNION, UNION ALL

2019-11-22 16:18:48 | 空手

ねこは思います。データベース開発なんかやってる人は頭が良いのでしょう、ねこのように「絵で描かなわからへぇーんっ」ていう人は少ないんじゃないでしょうか。

【FULL JOIN】

SQL FULL OUTER JOIN

 

【CROSS JOIN】

SQL Server CROSS JOIN example

 

【UNION】【UNION ALL】

 SQL Union All operator

あぁ、なんてわかりやすいんだ。。。

ではでは。


Netlify, Gatsbyのお勉強4➡LMこんどはGatsbyCMSにチャレンジだ。

2019-11-08 09:05:38 | 空手

今朝の9:00です。息子も学校に送ってお茶も沸いたし、旦那さんは会議中。今から一時間、みっちりと勉強します。

目標は、自宅で今のフリーランス以外にもお仕事できるようになること。

では本日のお題【LMこんどはGatsbyCMSにチャレンジだ。】です。

1.今回はCMShttps://nekonya.netlify.com/にLMを使ったイメージファイルを挿入します。

まずはこちらを確認して。。。https://blog.goo.ne.jp/beerneko/e/62a9cd078af31daebaa3142c61e1e170

$ netlify login

Already logged in via netlify config on your machine

Run netlify status for account details

あれ?すでにログインしてるって出てきた。前回はウェブサイトまでいってAuthorizeをクリックしてNetlify CLIでつなげてやらなければならなかたのに。。。

へんだ。。。

前回と同じようにアップデートしろってかいてあったので、そうします。

Update available 2.20.1 → 2.20.2
Run npm i -g netlify-cli to update

Success! Netlify CLI has been installed!

Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.

Next steps:

netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site

と出てきました。

 

2.netlify init

$ netlify init
? What would you like to do? ⇄ Connect this directory to an existing Netlify site

(すでにNetlifyにGitと連携してるサイトがありますから。)

netlify link will connect this folder to a site on Netlify

? How do you want to link this folder to a site? Use current git remote origin (https://github.com/beerneko/nekonya)

(Gitのnekonyaに全部ありますね。前回よりGitのLFSにあげたものは勝手にNetlifyのLMにアップロードされることに感激したことを思い出した。)

Looking for sites connected to 'https://github.com/beerneko/nekonya'...


Directory Linked

Admin url: https://app.netlify.com/sites/nekonya

Site url: https://nekonya.netlify.com

Site id saved to D:\webcms5\nekonya\.netlify\state.json

(ローカルとつながって成功してますね。)

 You can now run other `netlify` cli commands in this directory

Success
This site "nekonya" is configured to automatically deploy via https://github.com/beerneko/nekonya

 

3.ではGitLFSを確認します。

git lfs

High Level commandとLow Level commandの両方がでてきました。なんだか一度もつかわれてないっぽい。

そして、exampleとしてこんな感じに出てきました。

Examples
--------

To get started with Git LFS, the following commands can be used.

1. Setup Git LFS on your system. You only have to do this once per
repository per machine:

git lfs install

2. Choose the type of files you want to track, for examples all ISO
images, with git lfs track:

git lfs track "*.iso"

3. The above stores this information in gitattributes(5) files, so
that file need to be added to the repository:

git add .gitattributes

3. Commit, push and work with the files normally:

git add file.iso
git commit -m "Add disk image"
git push

でもなぁ、一度確認してみます。

git lfs track

...うんともすんとも言わねぇ。。。

4..lfsconfig fileをチェックします。

[lfs]
url = https://xxxx-xxxxxx-xxxxxxx.netlify.com/.netlify/large-media

なんか入ってますね。おっ、そうか。

まだトラックしてやってなかった。

その前にNetlifyのコンソールサイトからLMのサイトを確認して何も入ってないか確認しなきゃね。前回失敗してたから、一応ね。

。。。おぅ?

入ってる。。。


img/blackkimono.jpgがきちんとはいってたぞぉーっ!

ってことはこれも時間差なのか???時間がかかってたことをねこは勘違いして失敗ときめつけていたのか???

早速トラックしてつかってみるぞ。

5.CMSのコンパイルエラーについて。

gatsby develop

でローカルをブラウズして確認しながらblackkimono.jpgをつかってみる。

。。。どこにイメージファイルがあるんだろう。。。「home-jumbotron.jpg」をサーチしてみよう。

src/pages/index.mdにあった。なんかイメージファイル全部ここで宣言してるっぽいですね。おぅ?全ページのコンテンツ内容はここかぁっ!

イメージファイルを変えてやって。。。保存と。

あれ?!

TypeError: Cannot read property 'childImageSharp' of null
IndexPageTemplate
> 1 | import React from 'react'  2 | import PropTypes from 'prop-types'  3 | import { Link, graphql } from 'gatsby'  4 | 
 
では、もう一度元に戻してやるために、CTL+Zで元に戻して、保存と。
あれっ!?
まだエラーがでる@O@;
gitには変更が何もない状態で元に戻ってるはずなのに!!!あれぇ~っ!
まだgatsby developは走ってるよね。。。
では、消してみてgatsby buildやってみよう。
To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

なんやそれ!

じゃ、gatsby clean そしてもう一度gatsby build.

$ gatsby clean
info Deleting .cache, public
info Successfully deleted directories

あれっ?エラー消えてる。なんか、かってにキャッシュためてたんだね。だからgitに残らんのか。なんやそれ!

。。。そしてなんか消されてる。CSS???じゃぁ、変更なしのgitはいったい?

gatsby-plugin-purgecss:
Previous CSS Size: 190.75 KB
New CSS Size: 19.86 KB (-89.59%)
Removed ~170.90 KB of CSS

では、gatsby developでローカルブラウズして。

パッパカパーンっ!

元に戻った。でもわからん。

とにかく、変更後のエラー解除で元の状態に戻す手順は以下の通り。

① gitを変更前の状態に戻す

② CTL+Cでgatsby developを解除

③ gatsby cleanでキャッシュなどなど掃除

④ gatsby buildでコンパイルしなおす

⑤ gatsby developでサイト確認

 

6.CMSイメージファイルの変更

では、今回きちんと調べてからCMSのイメージファイルを変更したいと思います。

 ...
 
なるほど。
わかりました。
きちんと全てチュートリアルをやればわかることなんですが、どのチュートリアルも大事や基本的なことがすべて同じ熱量でかかれてるんで見落としたり、辛抱が足りなかったりと、意外なほど基本的なことで行詰まるものですね。
 
『WordPressなどと同様、ADMINへ行かずとも内容は変えられるし、ランディングページなんかもかえれます。』
ただし、react.jsかgatsbyが関係しているのかは勉強不足でわかりませんが、変更後には必ず『gatsby clean/gatsby build』してやる必要があるということです。ねこはこれらの全てを『gatsby develop』がやってくれると思ってました。
 
なので、イメージを直す場合、たとえばNetlifyのLMへ紐づけてやりたい場合は、ADMINからはアップロードできないのでこの方法でしてやらんとあかんわけですな。
 
では、最初から新しいイメージファイルをつかってやってみましょう。

7.新しい画像をLFSで組み込んでLMへ格納する。

$ git lfs track "beerneko.jpg"

$ git lfs track
Listing tracked patterns
beerneko.jpg (.gitattributes)
Listing excluded patterns

いかん、もっとよい写真をさがさな。

$ git lfs track "gysen.jpg"

さぁ、そろそろアップロードしましょか。
$ git add .
$ git commit -m "Added new img files for learning CMS for LM"
$ git status
NetlifyのLMサイトをチェックしてと。
 
$ git push
 
。。。LMが変わってない。。。
githubはきちんと

version https://git-lfs.github.com/spec/v1
oid sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
size 345609

ってなってる。これは正しい。

なんでサイトに反映されないのかなあ。。。

これも時間差なんだろうか。

今からググります。もうすでに、お昼食べたら1時前になってます。

$ netlify login
Already logged in via netlify config on your machine

Run netlify status for account details

To see all available commands run: netlify help


yurik@DESKTOP-159BVP1 MINGW64 /d/webcms5/nekonya (master)
$ netlify status
──────────────────────┐
Current Netlify User 
──────────────────────┘
Email: beerneko@yahoo.com
Github: beerneko
Teams:
beerneko's team: Collaborator
────────────────────┐
Netlify Site Info 
────────────────────┘
Current site: nekonya
Netlify TOML: X:\webcms5\nekonya\netlify.toml
Admin URL: https://app.netlify.com/sites/nekonya
Site URL: https://nekonya.netlify.com
Site Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

一度ログアウトして、適当に変更箇所作ってもう一度ログイン、そしてgit pushしてみます。

そして忘れてはならないのは、Netlifyのサイトをブラウズしていたら消すことです。

netlify logout

netlify login

おや?今度はきちんとサイトへ連れて行ってくれました。AuthorizeをクリックしてNetlify CLIでつなげてと。

やっぱりいかん。。。そうかっ!Netlifyのサイトでログあるかな?前回で「git pushしたらそのままデプロイしてくれます」を学んだよね。

...ログありました。

そして、エラーはっきりしました。問題児はgatsbyでした。

1:35:02 PM: error Input file contains unsupported image format
1:35:02 PM: Failed to process image /opt/build/repo/static/img/gysen.jpg Input file contains unsupported image format
1:35:02 PM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
1:35:02 PM:
1:35:02 PM: Error:Input file contains unsupported image format
1:35:02 PM:
1:35:02 PM: npm
1:35:02 PM: ERR! code ELIFECYCLE
1:35:02 PM: npm ERR!
1:35:02 PM: errno 1
1:35:02 PM: npm ERR!
1:35:02 PM: gatsby-starter-netlify-cms@1.1.3 build:app: `npm run clean && gatsby build`
1:35:02 PM: npm ERR! Exit status 1

https://github.com/gatsbyjs/gatsby/issues/12438

はよゆうてんか。

Hi folks! I work at Netlify and while I didn't create this feature I do know the answer here: large media images are ONLY available at serve time, not build time. Even fetching them with a git lfs pull will be super challenging since we drop git access permissions before you can run that command as part of your build pipeline. There are no plans at this time to provide those assets for use during build.

サーバタイムではLMがつかえるけど、ビルドタイムではつかえない?じゃぁ、どうやってイメージファイルをLMへあげるのさ!?

わからん。。。

wakaran...

https://docs.netlify.com/large-media/requirements-and-limitations/#limitations

Files tracked with Large Media are uploaded directly to the Netlify Large Media storage service on push, completely bypassing the site build. This saves build time, but also means that the files are not available to tools that process asset files during the build, such as Hugo's image processing or the gatsby-image plugin. Depending on your needs, you may be able to replace this functionality with Netlify's image transformation service.

ということは、先にトラックしてLFSでプッシュしてやってから、またIMGタグをプッシュしろってことかな?

 

よし、もう3時だ。金曜日だ。。。いまから必死のパッチでやったるど。

①.gitattributesからトラックを全部消す。

②コードをもとの状態に戻す。マスターで直でやってたから、もう大変。

③gatsby clean/gatsby buildで元に戻ったか確認

④新しく入れたイメージ全部消す

⑤もう一度名前変えてイメージ(gyosen.jpg)をstatic/imgに挿入

⑥git lfs track "gyosen.jpg"

⑦netlify login

git add .

git commit -m "the last commit for LFS for today"

git lfs push origin master

git push

⑨netlifyサイトビルドログ確認

こえぇ。。。

うんともすんとも言いやがらねぇ。。

ぉおっ????

3:20:37 PM: gatsby-plugin-purgecss: Only processing /opt/build/repo/src/components/all.sass
3:20:55 PM: success Building production JavaScript and CSS bundles — 117.881
3:20:55 PM: success Rewriting compilation hashes — 0.095
3:20:57 PM: success run page queries — 1.359 — 20/20 15.29 queries/second
3:20:58 PM: success Generating image thumbnails — 38/38 - 2.987 s
3:20:58 PM:
3:20:58 PM: gatsby-plugin-purgecss:
3:20:58 PM: Previous CSS Size: 190.75 KB
3:20:58 PM: New CSS Size: 19.86 KB (-89.59%)
3:20:58 PM: Removed ~170.90 KB of CSS

 

LMに入ったぁ~っ!!!!

⑩では調子のって、使ってみませう。。。

(src/pages/index.md)

image/img/gyosen.jpg

⑪ローカルチェックOK

git add .

git commit -m "Successfully added LFS image file into LM"

git push

 

ほんと、もう少しわかりやすくしておくれよ。。。

その1.LMにファイルを入れるときにはnetlify loginがローカルからなされていること

その2.Git pushは新しいファイルを先にトラックしてやり、netlifyのLMサーバに先にアップロードしておいてから使うこと

その3.(本当はここに「ほらね、怖くない。できた。うふっ💛」と書きたかったが、やっぱりデプロイで同じエラー。。。やっぱり、Netlifyのせいじゃなくって、Gatsbyですな。)

 

結論

本日の成果は、CMSのgitリポでもLMへイメージファイルをアップロードできることが分かった。

次回はこれを無事にgatsbyに組んでデプロイできるようにすること。

とりあえず、今だれかにきいてます。

https://github.com/gatsbyjs/gatsby/issues/19384

 

今日は全然T-SQLの勉強できてないから、30分だけでも必死でやるぞ。

その前に、キッチンあらわな。結局9時から4までこれしかしてない。。。かなしい。。。


Microsoft MCSA SQL Server 2016 (70-761) むぼーな挑戦 9 恥を承知で本日の間違えたところ投稿

2019-11-06 14:30:21 | 空手

もしも、これを読んでくれる人が英語嫌いだったら、ごめんさなさい。これはあくまでもビールねこの勉強ノートです。ビールねこは日本語も英語も不得手です。。。およよ。

#77

https://www.briefmenow.org/microsoft/solution-you-run-the-following-transact-sql-statement-13/

 
You must insert the following data into the Customer table:
 
You need to ensure that both records are inserted or neither record is inserted.
Solution: You run the following Transact-SQL statement:
『VALUES』のたびに『INSERT INTO』を繰り返さなといけないと思ってました。とほほ。
<答え>YES
 
 
#75
Sales.Customers
Application.Cities
Sales.CustomerCategories
The company’s development team is designing a customer directory application. The application must list
customers by the area code of their phone number. The area code is defined as the first three characters of the
phone number.
The main page of the application will be based on an indexed view that contains the area and phone number
for all customers.
You need to return the area code from the PhoneNumber field.
Solution: You run the following Transact-SQL statement:
インデックス付きVIEWの配下にするには『Schemabinding』をつかえ、ってかいてあるけど、

SELECT @areaCode=LEFT(@phoneNumber,3)としたら『Schemabinding』なしでできるそうな。

<答え>NO *note:TVF can not be used in Indexed View, this is the reason

#74

これも『TOP 1』でリターンを一つにしてないから『NO』

#70

Produces a warning if the credit limit parameter is greater than 7,000
Propagates all unexpected errors to the calling process

<答え>

#68

これわかる人いますか?

Task level is defined using the following rules:

You need to determine the task level for each task in the hierarchy.
Which five Transact-SQL segments should you use to develop the solution? To answer, move the appropriate
Transact-SQL segments from the list of Transact-SQL segments to the answer area and arrange them in the
correct order.
Select and Place:

<答え>どうやらこれが答えらしいですが、ちょっと信じられません。。。

#64

You have the following Transact-SQL query:SELECT
City.CityID,
City.CityName,
TranslateName(Nearby.CityName) AS NearbyCity
FROM Cities AS City
CROSS APPLY NearbyCities(City.CityID) AS Nearby
What type of functions are used in the query? To answer, select the appropriate options in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

<答え>Scalar, Table-Vlaued

なんてこった。。。よく読めばわかる問題でした。

SELECT
City.CityID,
City.CityName,
TranslateName(Nearby.CityName) AS NearbyCity ⇐シングルバリューなので、スカラー値
FROM Cities AS City
CROSS APPLY NearbyCities(City.CityID) AS Nearby ⇐『APPLY』をつかっているのでもちろん『Talbe-ValuedFunction』、テーブルで返す値なので、Talbe-Valuedですな。してやられました。

#62

SIMULATION
You work for an organization that monitors seismic activity around volcanos. You have a table named
GroundSensors. The table stored data collected from seismic sensors. It includes the columns describes in the
following table:

The database also contains a scalar value function named NearestMountain that returns the name of the mountain that is nearest to the sensor.You need to create a query that shows the average of the normalized readings from the sensors for each mountain.

The query must meet the following requirements:
Include the average normalized readings and nearest mountain name.
Exclude sensors for which no normalized reading exists.
Exclude those sensors with value of zero for tremor.

Construct the query using the following guidelines:
Use one part names to reference tables, columns and functions.
Do not use parentheses unless required.
Do not use aliases for column names and table names.
Do not surround object names with square brackets.

もうね、ここまでくればちゃんと読まなあかんなぁ。。。めっちゃ『nearest mountain name』探してて、「なぃ~っ」ってね。

<答え>

SELECT Average(NormalizedReading), NearestMountain(SensorID)
FROM GroundSensors
GROUP BY NearestMountain(SensorID)
WHERE TREMOR IS NOT 0 AND NormalizedReading IS NOT NULL

<ねこの間違った答え>

Select ①AVG(NormalizedReading) ②as AverageOfNomalizedReading, NearestMountain(SensorID) ②as NearestMountain
from GroundSensors
where ③Tremor <> 0 and NormallizedReading IS NOT NULL
④Group By NormalizedReading, SensorId

①AVGはつかえません。
②エリアスをつかえといってません。
③これはこのままでもいいのかなぁ。。。テスト中にシンタックスのチェックができたはず。
④GroupByでは『NearestMountain(SensorID)』のスカラー値の返り値でグループ化してやらないといけない。それに、『Average』はグループ化されたものの集計・平均値だから、ここでは『スカラー値の返り値』がグループ化によって基となって平均値を出さなければならない。
 
#57
You need to create a query that lists all complaints from the Complaints table, and the name of the person
handling the complaints if a person is assigned. The ComplaintID must be displayed first, followed by the
person name.
Construct the query using the following guidelines:Use two-part column names.
Use one-part table names.
 
<答え>
SELECT Complaints.ComlaintID, Persons.Name
FROM Persons
JOIN Contacts
ON Persons.PersonID=Contacts.PersonID
JOIN Complaints
ON Contacts.ComplaintID=Complaints.ComplaintID
 
<ねこの答え>間違っているとは限らない!!!
SELECT Complaints.ComplaintID, Persons.Name
FROM Complaints
LEFT OUTER JOIN Contacts ON Complaints.ComplaintID = Contacts.ComplaintID
LEFT OUTER JOIN Persons ON Contacts.PersonID = Persons.PersonID
なぜなら、『all complaints from the Complaints table』って書いてあったから。
Peterさんいわく、『「すべてのcomplaints 」って書いてあるから、これがベーステーブルになってFROMで呼ばれる。(そして「もしも」Personが任命されていれば名前を出すように。)そしてもしPersonが任命されてて、名前がNULLだった場合、以下のようにかかなきゃね。』って。
『Answer is wrong!As we have to show all complaints (“You need to create a query that lists “all” complaints from the Complaints table, and the name of the personhandling the complaints “if” a person is assigned.”) the table complaints has to be the base table. And, in case a person is assigned, also the persons name has to be shown but the persons name may be NULL. Hence the statement needs to look like:』って書いてるよ。https://www.briefmenow.org/microsoft/you-need-to-create-a-query-that-lists-all-complaints-fr/
 
 
 さて、明日は全然覚えてない「OUTPUT」のビデオみます。
NetlifyとGatsby、なかなか進まないなぁ。。。