Skip to content

filter the result by ‘g / ml’ using SQL

I have the below table from which I need to filter which holds both “g / ml”. The below query gives me result as The expected result is What I can apply in the where clause to get the expected results Answer Just use %g/%ml%. The % can appear in any position in the matching pattern.

Postgres conversion rate

I want to get conversion rate in postgresql. My data look like below: input: id count type converted 1 30 A true 2 20 A false 3 13 B false 4 7 B true As first step, I would like to get a sum of counts for each type with associated count field. I tried with different variations of SUM()

MYSQL Query Age Calculation

This is my MySQL Query to return the age from the date of birth The query is executed. But it returns the age difference is in a negative value. Answer The problem with 2-digit year fixed – all years are treated as 19xx. https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=f356258c99b20d13b0c4e2349b801f18

SQL query for key value table with 1:n relation

I have a table in which I want to store images. Each image has arbitrary properties that I want to store in a key-value table. The table structure looks like this id fk_picture_id key value 1 1 camera iphone 2 1 year 2001 3 1 country Germany 4 2 camera iphone 5 2 year 2020 6 2 country United States

Select distinct very slow

I have a table where I store rows with external ids. Quite often I need to select latest timestamp for given external ids. Now it is a bottleneck for my app Query: Explain: What could I do to make this query faster? Or probably should I use completely different query? UPDATE: Added new query plan as asked @ja…

SQL count by type

I would like to summarize in a table so that I have for each id in each round, the number of tokens “red” and “blue”. What would the SQL query for such table? Here’s the data. The result will display like below: I have been trying the following code: Answer I would suggest this to get to the requested r…