# 税務データのクエリ Sigma または Data Pipeline を使用して、税務情報を取得します。 Stripe Tax のデータには、[Payment Links](https://docs.stripe.com/tax/payment-links.md)、[Checkout](https://docs.stripe.com/tax/checkout.md)、[Subscription](https://docs.stripe.com/tax/subscriptions.md)、[Invoice](https://docs.stripe.com/tax/invoicing.md)、[カスタムの実装](https://docs.stripe.com/tax/custom.md)、[プラットフォーム利用](https://docs.stripe.com/tax/connect.md)の連携による自動計算でおおまかな税額を提供するさまざまなコンポーネントが含まれています。税金固有のデータはすべてスキーマの**税金**セクションで利用できます。プライマリーテーブルは `tax_transactions` です。 税金データを詳しく調べたい場合、`tax_transaction_line_items`、`tax_transaction_shipping_costs`、`tax_transaction_jurisdiction_details` など、`tax_transaction` のコンポーネントを表すその他のテーブルも使用することができます。 この図は、税金の自動計算中に作成されるすべてのコンポーネントと、計算をトリガーした元のオブジェクトとの関係を示しています。この例に示されている金額は、補助[通貨](https://docs.stripe.com/currencies.md)単位で表示されています (ドルではなくセントなど)。 (See full diagram at https://docs.stripe.com/stripe-data/query-tax-data) ## 税取引 `tax_transactions` テーブルの各行は 1 つの [tax_transaction](https://docs.stripe.com/api/tax/transactions/object.md) オブジェクトで表されます。Tax transaction は、取引または差戻しに対する見積税額または減額後の税額を記録します。自動税金計算で作成されたすべての税取引について報告することが可能です。 税額のレポートを作成する際には、この表を起点にして作成することをお勧めします。税額を確認するには以下の税金表と結合させる必要がありますが、この表は Invoice や Checkout セッションのような他の製品とデータを結びつけます。 `source_id` と `source_type` を使用して非課税表に結合すると、税取引の作成をトリガーするオブジェクトが返されます。 税取引は、元の Source オブジェクトと 1 対 1 の関係があります。以下の例は、申告対象の税取引と請求書の元のソースのリストを取得しています。これは、[請求データのクエリ](https://docs.stripe.com/stripe-data/query-billing-data.md)で拡張することが可能です。 ```sql select tx.id as tax_transaction_id, tx.posted_at as tax_transaction_posted_at, inv.id as invoice_id, inv.total as invoice_total from tax_transactions tx inner join invoices inv on inv.id = tx.source_id limit 5 ``` | tax_transaction_id | tax_transaction_posted_at | invoice_id | invoice_total | | ------------------- | ------------------------- | ------------------ | ------------- | | tax_orWziM4j7CiRL8J | 2024-06-18 16:40:16 +0000 | in_orWziM4j7CiRL8J | 20.000 | | tax_orWziM4j7CiRL8J | 2021-06-28 00:01:21 +0000 | in_orWziM4j7CiRL8J | 189 | | tax_orWziM4j7CiRL8J | 2024-06-23 23:35:40 +0000 | in_orWziM4j7CiRL8J | 219 | | tax_orWziM4j7CiRL8J | 2024-06-23 23:35:40 +0000 | in_orWziM4j7CiRL8J | 10,475 | | tax_orWziM4j7CiRL8J | 2023-07-23 04:03:06 +0000 | in_orWziM4j7CiRL8J | 200 | ### 税取引のメタデータ 税取引には、[カスタムの実装](https://docs.stripe.com/tax/custom.md)で設定したメタデータが含まれる場合があります。`tax_transactions_metadata` の各行には、1 組のキーと値のペアが返されます。 税取引のメタデータの概要図 (See full diagram at https://docs.stripe.com/stripe-data/query-tax-data) ## 税取引アイテム 税金のラインアイテムと税送料は、税取引の合計金額と税額を構成します。税金のラインアイテムと税送料はそれぞれのテーブルにありますが、どちらも金額と合計税額を構成します。 ### 税金のラインアイテム 税金のラインアイテムは、商品の販売に関係するラインアイテムを表します。`tax_transaction_line_items` の各行は、`tax_transaction` に関連付けられた単一の税金のラインアイテムで表されます。 ### 税送料 税送料は、商品の配送に関係する配送アイテムを表します。`tax_transaction_shipping_costs` の各行は、`tax_transaction` に関連付けられた単一の配送料で表されます。 > これらのテーブルは、各アイテムに基づく概要情報を提供します。1 つの税取引に複数のラインアイテムと 1 つの配送料を設定でき、これらが税取引の金額を構成します。 > > **amount**: ラインアイテムの総額を表します。`tax_behavior` が `inclusive` の場合は税額を含みます。`tax_behavior` が `exclusive` (デフォルト) の場合、税額は除外されます。 > > **amount\_tax**: ラインアイテムの税額を表します。 > > **currency**: `amount` と `amount_tax` を定義する[取引通貨](https://docs.stripe.com/currencies.md)です。異なる種類の通貨を合計すると、予期しない結果が生じます。 税取引アイテムの概要図 (See full diagram at https://docs.stripe.com/stripe-data/query-tax-data) 以下の例では、`tax_transaction` のすべての金額と税額のリストを取得しています。 ```sql with tax_amounts as ( select li.tax_transaction_id, li.id, li.amount, li.amount_tax, li.tax_behavior, li.currency, 'line_item' as item_type from tax_transaction_line_items li union all select sc.tax_transaction_id, sc.id, sc.amount, sc.amount_tax, sc.tax_behavior, sc.currency, 'shipping_cost' as item_type from tax_transaction_shipping_costs sc ) select id, amount, amount_tax, tax_behavior, currency, item_type from tax_amounts where tax_transaction_id = 'tax_d2e5470dC63u' ``` | ID | 金額 | amount_tax | tax_behavior | 通貨 | item_type | | ---------------------- | ----- | ---------- | ------------ | --- | ------------- | | tax_li_orWziM4j7CiRL8J | 3,100 | 0 | 外税 | usd | line_item | | tax_li_orWziM4j7CiRL8J | 1,999 | 190 | 外税 | usd | line_item | | tax_li_orWziM4j7CiRL8J | 3,500 | 304 | 内税 | usd | line_item | | tax_li_orWziM4j7CiRL8J | 4,242 | 242 | 外税 | usd | line_item | | tax_li_orWziM4j7CiRL8J | 799 | 0 | 外税 | usd | shipping_cost | ### 税取引のラインアイテムのメタデータ 税取引のラインアイテムには、[カスタムの実装](https://docs.stripe.com/tax/custom.md)で設定したメタデータが含まれる場合があります。`tax_transaction_line_items_metadata` の各行には、1 組のキーと値のペアが返されます。 税取引のメタデータ (See full diagram at https://docs.stripe.com/stripe-data/query-tax-data) ## 税取引管轄区域情報 `tax_transaction_jurisdiction_details` テーブルの各行は、税取引アイテム (`tax_transaction_line_item` または `tax_transaction_shipping_cost`) を納める管轄区域を表します 。 ### 管轄区域情報について このテーブルは、各管轄区域についての詳細な情報を提供するものです。1 つの税取引アイテムに、税取引アイテムの金額を納める管轄区域を複数設定することができます。 すべての管轄区域にわたって `amount_taxable` または `amount_non_taxable` を合計しても、税取引アイテムの `amount` と等しくなるとは限りません。 **amount\_taxable**: 税取引アイテムの `amount` までの金額であり、課税対象となります。複数の管轄区域で同じ課税額を設定できます。 **amount\_non\_taxable**: 税取引アイテムの `amount` までの金額であり、非課税対象となります。複数の管轄区域で同じ非課税額を設定できます。 **amount\_tax**: 税取引アイテム `amount_tax` の一部です。すべての管轄区域でこれを合計すると、税取引アイテムの `amount_tax` になります。 **currency**: `amount_taxable`、`amount_non_taxable`、`amount_tax` を定義する[取引通貨](https://docs.stripe.com/currencies.md)です。異なる種類の通貨を合計すると、予期しない結果が生じます。 **filing\_currency**: 管轄の税務局が使用し、`filing_amount_taxable`、`filing_amount_non_taxable`、`filing_amount_tax` を定義する[申告通貨](https://docs.stripe.com/currencies.md)です。異なる種類の通貨を合計すると、予期しない結果が生じます。 (See full diagram at https://docs.stripe.com/stripe-data/query-tax-data) 次の例では、税取引アイテムのすべての管轄区域情報を取得しています。 ```sql select jd.amount_taxable, jd.amount_non_taxable, jd.amount_tax, jd.taxability_reason, jd.jurisdiction_level, jd.jurisdiction_name, concat(jd.jurisdiction_country, '-', jd.jurisdiction_state) as jurisdiction_location from tax_transaction_jurisdiction_details jd where li.id = 'tax_li_52d37cdd6f7' ``` | amount_taxable | amount_non_taxable | amount_tax | taxability_reason | jurisdiction_level | jurisdiction_name | jurisdiction_location | | -------------- | ------------------ | ---------- | ------------------ | ------------------ | ----------------------------------------- | --------------------- | | 0 | 1,299 | 0 | not_subject_to_tax | 国 | アメリカ | | | 1,299 | 0 | 77 | standard_rated | 都道府県 | カリフォルニア州 | US-CA | | 1,299 | 0 | 16 | standard_rated | 郡 | サンディエゴ | US-CA | | 1,299 | 0 | 7 | standard_rated | 地区 | 売上税および使用税 (CVVT) | US-CA | | 1,299 | 0 | 7 | standard_rated | 地区 | 売上税および使用税 (CVGT) | US-CA | | 1,299 | 0 | 7 | standard_rated | 地区 | Regional Transportation Commission (SDCT) | US-CA | ## クエリ例 その他の例については、[Sigma サイドバーのクエリテンプレートライブラリの税金セクション](https://dashboard.stripe.com/sigma/queries)をご覧ください。 ### 月別の仮受消費税 この例では、ラインアイテムと送料に課される税額を、月別および[通貨](https://docs.stripe.com/currencies.md)別にまとめています。 ```sql with tax_amounts as ( select li.tax_transaction_id, li.amount, li.amount_tax, li.tax_behavior, li.currency from tax_transaction_line_items li union all select sc.tax_transaction_id, sc.amount, sc.amount_tax, sc.tax_behavior, sc.currency from tax_transaction_shipping_costs sc ), tax_liability as ( select date_format(date_trunc('month', posted_at), '%Y-%m-%d') as month, currency as presentment_currency, sum( ( case when tax_behavior = 'inclusive' then amount - amount_tax else amount end ) ) as total_sales_excluding_tax, sum(amount_tax) as total_tax from tax_amounts ta inner join tax_transactions t on (ta.tax_transaction_id = t.id) group by 1, 2 ) select month, presentment_currency, total_sales_excluding_tax, total_tax from tax_liability order by 1 desc, 2 ``` | カ月 | presentment_currency | total_sales_excluding_tax | total_tax | | ---------- | -------------------- | ------------------------- | --------- | | 2026-05-01 | usd | 286,600 | 43,522 | | 2026-05-01 | eur | 30,898 | 56 | | 2026-04-01 | usd | 79,776 | 2,565 | | 2026-04-01 | eur | 55,434 | 3,954 | ### 税金アイテム別の管轄区域情報 このテンプレートは、前月の税取引の管轄区域の詳細をアイテム別に分け、カスタマイズ可能な[税項目別エクスポート](https://docs.stripe.com/tax/reports.md#itemized-exports)を生成します。テンプレートのコメントをすべてご確認の上、ニーズに合わせたカスタマイズの方法をご覧ください。 ```sql with tax_amounts as ( select li.id, li.source_line_item_id, li.amount, li.amount_tax, li.tax_behavior, li.tax_code, li.currency, li.quantity_decimal from tax_transaction_line_items li union all select sc.id, -- Shipping costs do not have source line item IDs '' as source_line_item_id, sc.amount, sc.amount_tax, sc.tax_behavior, sc.tax_code, sc.currency, -- Shipping costs do not have a quantity '' as quantity_decimal from tax_transaction_shipping_costs sc ) select t.source_id, t.source_type, -- Learn more about currencies at Stripe: https://docs.stripe.com/currencies tx.currency as presentment_currency, t.posted_at, t.tax_date, tx.source_line_item_id as transaction_source_item_id, tx.id as transaction_item_id, tx.amount, tx.amount_tax, tx.tax_behavior, tx.tax_code, tjd.jurisdiction_name, tjd.jurisdiction_level, tjd.jurisdiction_country, tjd.jurisdiction_state, tjd.taxability, tx.quantity_decimal, tjd.tax_type, tjd.amount_tax as jurisdiction_amount_tax, tjd.amount_taxable as jurisdiction_amount_taxable, tjd.amount_non_taxable as jurisdiction_amount_non_taxable, tjd.filing_currency, tjd.filing_amount_tax as jurisdiction_filing_amount_tax, tjd.filing_amount_taxable as jurisdiction_filing_amount_taxable, tjd.filing_amount_non_taxable as jurisdiction_filing_amount_non_taxable, tjd.tax_transaction_item_type, tjd.tax_rate_percentage from tax_transaction_jurisdiction_details tjd inner join tax_transactions t on tjd.tax_transaction_id = t.id inner join tax_amounts tx on TJD.tax_transaction_item_id = tx.id where -- Exclude country level jurisdiction details for the US -- to be consistent with the Tax itemized export. The excluded -- details will always be non-taxable because the US doesn't -- have a country level tax. not ( tjd.jurisdiction_level = 'country' and tjd.jurisdiction_country = 'US' ) -- Adjust this date range to report on a period other than the previous month. and ( t.posted_at >= date_trunc('month', current_date - interval '1' month) and t.posted_at < date_trunc('month', current_date) ) -- Uncomment and adjust to filter results by specific jurisdiction countries. -- and tjd.jurisdiction_country in ('CA') -- Uncomment and adjust to filter results by specific jurisdiction states. -- and tjd.jurisdiction_state in ('AB', 'QC') order by t.posted_at desc, t.source_id, tx.source_line_item_id, tjd.tax_rate_percentage desc, tjd.jurisdiction_level, tjd.jurisdiction_name ``` | source_id | source_type | presentment_currency | posted_at | tax_date | transaction_source_item_id | transaction_item_id | 金額 | amount_tax | tax_behavior | tax_code | jurisdiction_name | jurisdiction_level | … | | ------------------ | ----------- | -------------------- | ---------- | ---------- | -------------------------- | ---------------------- | ------ | ---------- | ------------ | ------------- | ----------------- | ------------------ | - | | in_orWziM4j7CiRL8J | 請求書 | eur | 2026-04-15 | 2026-04-15 | il_orWziM4j7CiRL8J | tax_il_orWziM4j7CiRL8J | -199 | -20 | 外税 | txcd_99999999 | アイルランド | 国 | … | | in_orWziM4j7CiRL8J | 請求書 | usd | 2026-04-15 | 2026-04-15 | il_orWziM4j7CiRL8J | tax_il_orWziM4j7CiRL8J | 10,000 | 1,000 | 外税 | txcd_99999999 | ロードアイランド州 | 都道府県 | … | | in_orWziM4j7CiRL8J | 請求書 | usd | 2026-04-07 | 2026-04-07 | il_orWziM4j7CiRL8J | tax_il_orWziM4j7CiRL8J | 2,999 | 371 | 外税 | txcd_99999999 | 第 17 防火地区 | 地区 | … |