| |

VerySource

 Forgot password?
 Register
Search
View: 903|Reply: 6

Find a SQL statement

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-8 10:00:01
| Show all posts |Read mode
Table 1
Name ID number

Table 2
Name ID No. Item Name


The total number of items in Table 2 needs to be queried and the name ID number in Table 2 corresponds to the name display in Table 1 after query.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-28 11:15:01
| Show all posts
Paste the data and the results you want to see
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-28 12:45:01
| Show all posts
// Need to query the total number of items in Table 2 and the name ID number in Table 2 corresponds to the name display in Table 1 after query?
There is no clearing.If you are querying the total number of items, there is no Group condition.If you want to display the name corresponding to the name ID, you must have the Group condition.
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 United States

Post time: 2020-5-28 15:00:01
| Show all posts
select A. *, B. quantity from A
left join
(
select name ID number, quantity = sum (quantity) from B group by name ID number
) B on A. Name ID number = B. Name ID number
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-5-28 17:45:01
| Show all posts
select A. name, A. name ID number, SUM (B. quantity) AS 'total', B. item name
FROM Table 1 A, Table 2 B
WHERE A. Name ID number = B. Name ID number
GROUP BY A. Name, A. Name ID number, B. Item name
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-31 20:00:01
| Show all posts
select A. name, A. name ID number, SUM (B. quantity) AS 'total', B. item name
FROM table 1 A inner join table 2 B
on A. Name ID number = B. Name ID number
GROUP BY A. Name, A. Name ID number, B. Item name
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-6 23:30:02
| Show all posts
select A. name, A. name ID number, SUM (B. quantity) AS'total', B. item name
FROM Table 1 A, Table 2 B
WHERE A. Name ID number = B. Name ID number
GROUP BY A. Name, A. Name ID number, B. Item name

that's it!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list