Skip to content

Tag: sql

SQL – sum column for every date

This seemed like a very easy thing to do but I got stuck. I have a query like this: select op.date, count(p.numberofoutstanding) from people p left join outstandingpunches op on p.fullname = op….

Join table with mapping of array in postgres

I want to join two table, with first table contain an array which is primary keys of second table in JSON format Answer demo:db<>fiddle You can use the ANY function: Edit: demo:db<>fiddle If you have jsonb arrays, you can use the @> operator. Note, that this works only if your integer id values…

Consolidate union result

I am selecting email address from two source tables via a union query. Normally, I would leverage union’s behavior of filtering out duplicate values, but in this case, each source table may or may not have a value for each person, and I have to give “priority” to the email address from the f…

Inner Join returned values

I have a query such as, select name from employee inner join task on employee.id = task.employee_id order by name asc Tables look like: employee id name 1 Emily 2 Sam 3 AI 4 Joe 5 …

fetch records based on mysql alias using having clause

i am having bibles table where user read 3 bible chapters every day. My query works fine as from this answer . i have two columns in table id, chapter_name i.e below :- and after that i used below query Its giving me blow output :- what i want when user requests for date 24 feb 2020 it must come