SQL Common Written Questions

Please indicate the source of the original reprint: http://agilestyle.iteye.com/blog/2392433

 

There is a datasheet DDR

Question: Query the records that appear more than once in T2

SQL Reference

select * from ddr
where t2 in
(
	select t2 from ddr
	group by t2
	having count(t2) > 1
);

 
There are 2 tables in the database, one Customer, field id, name; one Orders, field id, cid (Customer's ID foreign key), revenue, question: Query the sum of the revenue of each Customer


SQL Reference

select sum(revenue), c.name
from orders o LEFT JOIN customer c on o.cid = c.id
GROUP BY cid;


 
 
 


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326116466&siteId=291194637