This is the follow-up post on my previous post.
In this post, I will try to explain a simple and practical idea of the statement: p -> q.
p -> q means, in simple words, that p implies q or if p then q. Check more details about this here. So what, exactly, is necessary here? And what is sufficient in this context? Behold the following text.
This example, I will give, comes from SQL - the language that we use to write RDBMS queries, to fetch data from databases. If you are familiar with SQL, you skip to next para. Here I give a vague intro. One of the reports that we frequently use on such data is of the kinds where we look for what the data is indicating, in its entirety. Such functions in SQL are called aggregate function. For example, suppose we have bank transaction data in number of records, each record has month (1-12), day(1-31) and amount credited(+) or debited(-) on that day. Now suppose we want to MAXIMUM amount of transaction credited in each month. Then we have a simple query-
SELECT
MAX(amount)
from
bank_transactions
group by
month;
That's it - for each month I have the maximum amount that was credited. Notice - MAX is a aggregate function and the aggregation is done on the basis on month. And suppose if we skip the group by clause - then the query will give the transaction that had maximum credit in all the transactions. So group by clause is not mandatory is we are using aggregate functions. But, we are using group by clause then we need to use some aggregrate function - MAX, AVG, SUM etc since this functions tells SQL - what data must be aggregrated and how it should be aggregrated. So feeling better now. Let's come back to p -> q now.
Now we know two things:
1.
We can use aggregate functions without any group-by
clause.
2.
If we are using group-by clause, then we need to use
some aggregate function.
So can we put this information in terms of p -> q? Surely. Let:p: group-by clause is used
q: aggregate function is present
then p -> q means
“if group-by clause is used then aggregate function is present”
Wow! That was easy, right. Now:
1.
If I see a query where group-by is used, then I am damn
sure that it has to have some aggregate function. That means, aggregate
function must necessarily be present
if the query has a group by clause. So, in this case, p is necessary for q. It
must happen, if q has happened.
Although, there could be another way p
could happen, but what I am sure is, that if q has happened p should follow
too. But if I see an aggregate function(q)
in a query, then I cannot say that there is a group-by clause(p) in it. Hence, for q, p
is not necessary.
2.
Another way to look is – if I see a group-by clause in
a query then, it is sufficient for
me to conclude that there was an aggregate function used. In this sense, p is sufficient for q to happen. Again, there are other
ways for q to happen. But that doesn’t
mean that seeing just aggregate function I can say if there was a group-by
clause involved in it or not. Hence, q is
not sufficient for p.
Hope, you enjoyed this post!
No comments:
Post a Comment