Skip to content

Tag: sql

How to count NULL in COUNT(column) query?

I have the following table that I’m trying to find the total count for each unique name element. The problem is, other: 1 and other: Null are supposed to be different elements, but my query is grouping them together. The issue I’m running into is that null is not being counted as a row. But when I…

Find duplicate data in last 1 hour

I am looking for a SQL script to find the data which has more than 2 entries in last 1 hour. I have a table having user_id & event_time. I want a way to find out if the user_id has more than 1 entries in last 1 hour. I have tried below till now: Create temp table to put all

how to divide each row by the sum of those rows?

I have a table CREDITS with these columns: DAY_OPERATIONAL TOTAL_LOAN CREDITS_PERCENT I should multiply each row’s TOTAL_LOAN and CREDITS_PERCENT then divide to SUM(TOTAL_LOAN) in that DAY_OPERATIONAL. My code is not working. How can I achieve this? How do I need to use group by properly? Answer This is…

How do I convert this to mongodb aggregate query?

SELECT prop_type , count(prop_type) As no_of_properties from prop_type JOIN prop_for_rent USING (prop_type) GROUP BY prop_type; prop_type and prop_for_rent are both tables. Then “prop_type” used for the JOIN and GROUP BY is an attribute name in both. The expected result is for the query to count t…