Today I learned
MySQL Query
Select * from table
Limit: Bring only some data.
limit 5 -> find only five values from table.
Distinct : Excluding redundant data is imported.
select distinct(column) from table
select distinct(payment_method) from order
Count : Data can be counted in numbers.
select count(*) from order where payment_method = 'CARD'
Use Distinct and count together
1. select distinct(lastname) from users -> find remove redundant data from column
Group by
select lastname,count(*)
from users
where email = '%gmail.com'
group by lastname
To define GROUP BY in one word:
"showing non-duplicated information"
is.
Looking at the usage example first, (usually used with group functions)
I want to draw a melon chart. (→ Descending order of streaming count by music source)
I want to know the best product among the products sold. (→ Order quantity by product in descending order)
Show the number of comments on the free bulletin board list. (→ number of comments per post)
I would like to know the number of real estate listings by region. (→ Number of listings by region)
-SELECT week, MIN(likes) from checkins c group by week
-SELECT week, MAX(likes) from checkins c group by week
-SELECT week, round(AVG(likes),2) from checkins c group by week
-SELECT week, SUM(likes) from checkins c group by week
Order by
ORDER BY is a SQL statement to sort data by a specified column. If 'ORDER BY column name' is used, the result is output by sorting the column in ascending order.
default = asc
reverse = desc
select payment_method ,COUNT(*) from orders o
where course_title = "웹개발 종합반"
group by payment_method
order by COUNT(*)