Giter Club home page Giter Club logo

Comments (2)

jrlegrand avatar jrlegrand commented on August 20, 2024

I think this works... putting here for @Bridg109 to review...

SELECT
	substance.productid
	, substance.rn AS line
	, substance.token AS substancename
	, strength.token AS active_numerator_strength
	, unit.token AS active_ingred_unit
FROM (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.substancename, '; ')) arr(token)
) substance
LEFT JOIN (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.active_numerator_strength, '; ')) arr(token)
) strength ON substance.productid = strength.productid AND substance.rn = strength.rn
LEFT JOIN (
	SELECT DISTINCT
		prod.productid
		, ROW_NUMBER() OVER (PARTITION BY prod.productid) AS rn
		, arr.token
	FROM datasource.fda_ndc_product prod
	, UNNEST(string_to_array(prod.active_ingred_unit, '; ')) arr(token)
) unit ON substance.productid = unit.productid AND substance.rn = unit.rn;

from sagerx.

Bridg109 avatar Bridg109 commented on August 20, 2024

You can unnest() multiple arrays in parellel

image

from sagerx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.