175 - Combine Two Tables

本文提供了一个SQL左连接查询的实例,展示了如何从Person表中获取每个人的详细信息,即使某些记录在Address表中没有匹配项也能显示完整人员名单。

Table: Person

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.

Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

FirstName, LastName, City, State

Subscribe to see which companies asked this question

思路分析:

left join

SELECT Person.FirstName, Person.LastName, Address.City, Address.State
FROM Person LEFT JOIN Address 
ON Person.PersonId = Address.PersonId;


帮我讲解一下这个stata代码 use infmrt,clear regress infmort lpcinc lphysic lpopul if year==1990 graph twoway (scatter infmort physic) if year==1990 tab physic DC regress infmort lpcinc lphysic lpopul if year==1990 & DC==0 /* -------------------------------------------------------------------------------- -- Part 1: Outputting Summary Statistics Tables -------------------------------------------------------------------------------- */ // --- 1.1: Load Data and Quick Look --- // We use Stata's built-in dataset about cars from 1978. sysuse auto, clear // The most basic command to see summary stats in the Stata window. summarize price mpg weight length foreign // --- 1.2: Export to Word using estpost and esttab --- // This is the standard method for creating a publication-quality table. // Step 1: Use 'estpost summarize' to calculate and store the statistics. estpost summarize price mpg weight length foreign // Step 2: Use 'esttab' to format and export the stored results to a Word file (.rtf). esttab using "summary_statistics.rtf", replace /// cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0))") /// title("Table 1: Summary Statistics for Auto Data") /// label nonumber /* -------------------------------------------------------------------------------- -- Part 2: Outputting Basic Regression Tables -------------------------------------------------------------------------------- */ // --- 2.1: Run and Store a Series of Models --- // We will run two models and compare them side-by-side in one table. // Model 1: A simple regression of price on mileage (mpg). regress price mpg, vce(robust) estimates store model1 // Store the results with the name 'model1' // Model 2: A multiple regression, adding weight and car type (foreign). // 'i.foreign' tells Stata to treat 'foreign' as a categorical variable. regress price mpg weight i.foreign, vce(robust) estimates store model2 // Store the results with the name 'model2' // --- 2.2: Combine and Export Models to Word with esttab --- // This command takes the two stored models and creates a single table. esttab model1 model2 using "regression_table.rtf", replace /// b(3) se /* Show coefficients to 3 decimals and standard errors in parentheses. */ /// star(* 0.10 ** 0.05 *** 0.01) /* Define significance stars. */ /// label /* Use variable labels instead of names. */ /// title("Table 2: Regression of Price on Car Characteristics") /// mtitles("Model 1" "Model 2") /* Custom titles for each model column. */ /// stats(N r2_a, fmt(0 3) labels("Observations" "Adj. R-squared")) /* Add N and Adj. R2 to the bottom. */
10-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值