3.Consider the table FLIGHT given below. Write SQL queries for the questions below: a.Display details of all flights starting from Delhi. b.Display details of flights that have more than 4 number of flights operating. c.Display flight codes, starting place, destination, number of flights in descending order of number of flights. d.Display destinations along with flight codes of all the destinations starting with ‘A’.
时间: 2024-03-06 08:49:04 浏览: 146
a. Display details of all flights starting from Delhi:
```
SELECT *
FROM FLIGHT
WHERE StartPlace = 'Delhi';
```
b. Display details of flights that have more than 4 number of flights operating:
```
SELECT *
FROM FLIGHT
WHERE NumOfFlights > 4;
```
c. Display flight codes, starting place, destination, number of flights in descending order of number of flights:
```
SELECT FlightCode, StartPlace, Destination, NumOfFlights
FROM FLIGHT
ORDER BY NumOfFlights DESC;
```
d. Display destinations along with flight codes of all the destinations starting with ‘A’:
```
SELECT FlightCode, Destination
FROM FLIGHT
WHERE Destination LIKE 'A%';
```
相关问题
Problem 4 (Medium): Use the nycflights13 package and the flights and planes tables to answer the following questions: a. What is the oldest plane (specified by the tailnum variable) that flew from New York City airports in 2013? b. How many airplanes that flew from New York City are included in the planes table?
a. To answer this question, we need to join the flights table with the planes table on the tailnum variable and filter for flights that departed in 2013 from New York City airports. Then, we can sort by the year variable in the planes table and select the oldest plane. Here's the code:
```{r}
library(nycflights13)
oldest_plane <- flights %>%
inner_join(planes, by = "tailnum") %>%
filter(origin %in% c("EWR", "JFK", "LGA") & year == 2013) %>%
arrange(year) %>%
select(tailnum, year) %>%
distinct() %>%
slice_head(n = 1)
oldest_plane
```
The output shows that the oldest plane that flew from New York City airports in 2013 is tail number "N201AA" with a manufacturing year of 1956.
```
# A tibble: 1 x 2
tailnum year
<chr> <int>
1 N201AA 1956
```
b. To answer this question, we need to count the number of unique tail numbers in the flights table that departed from New York City airports in 2013 and match them with the planes table. Here's the code:
```{r}
num_planes <- flights %>%
filter(origin %in% c("EWR", "JFK", "LGA") & year == 2013) %>%
distinct(tailnum) %>%
inner_join(planes, by = "tailnum") %>%
summarize(num_planes = n_distinct(tailnum))
num_planes
```
The output shows that there are 404 airplanes that flew from New York City airports in 2013 and are included in the planes table.
```
# A tibble: 1 x 1
num_planes
<int>
1 404
```
for (const Flight& flight : flights)怎么更改可以不用C++11
你可以使用传统的循环来替代范围-based for循环,如下所示:
```cpp
for (std::vector<Flight>::const_iterator it = flights.begin(); it != flights.end(); ++it) {
const Flight& flight = *it;
// 在这里进行你的操作
}
```
这里使用了一个迭代器 `it` 来遍历 `flights` 向量中的每个元素,并将其赋值给 `flight`。你可以在循环体内进行你的操作,就像在范围-based for循环中一样。要注意的是,`const_iterator` 用于确保不会更改 `flights` 中的元素。
阅读全文