<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Querying the Gravity Form DB</title>
		<link>https://legacy.forums.gravityhelp.com/topic/querying-the-gravity-form-db</link>
		<description>Gravity Support Forums Topic: Querying the Gravity Form DB</description>
		<language>en-US</language>
		<pubDate>Mon, 06 Apr 2026 06:43:40 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/querying-the-gravity-form-db" rel="self" type="application/rss+xml" />

		<item>
			<title>mrkeroppi on "Querying the Gravity Form DB"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/querying-the-gravity-form-db#post-27959</link>
			<pubDate>Thu, 16 Jun 2011 14:46:57 +0000</pubDate>
			<dc:creator>mrkeroppi</dc:creator>
			<guid isPermaLink="false">27959@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks Alex, That was the push I needed.  I really appreciate the hard work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "Querying the Gravity Form DB"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/querying-the-gravity-form-db#post-27955</link>
			<pubDate>Thu, 16 Jun 2011 14:38:04 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">27955@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Try the following. It is a little long, but should get you the information you need.&#60;br /&#62;
You will need to adjust it to fit your real scenario. You might be able to do it yourself by just following the existing pattern in the query, but if you have problems doing that, just let me know and I will help you.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[sql]
SELECT person, sum(is_apple) as apples, round((sum(is_apple)/count(*))*100) as percent_apple, sum(is_mango) as mangos, round((sum(is_mango)/count(*))*100) as percent_mango FROM(

    SELECT person.value as person, fruit.value as fruit, if(fruit.value = &#38;#39;Apple&#38;#39;, 1, 0) as is_apple, if(fruit.value = &#38;#39;Mango&#38;#39;, 1, 0) as is_mango FROM
    (
        SELECT lead_id, value FROM alien_rg_lead_detail
        WHERE form_id=173 AND field_number=1
    ) person
    INNER JOIN
    (
        SELECT lead_id, value FROM alien_rg_lead_detail
        WHERE form_id=173 AND field_number=2
    ) fruit ON person.lead_id = fruit.lead_id
) stat
GROUP BY person&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>mrkeroppi on "Querying the Gravity Form DB"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/querying-the-gravity-form-db#post-27921</link>
			<pubDate>Thu, 16 Jun 2011 11:28:44 +0000</pubDate>
			<dc:creator>mrkeroppi</dc:creator>
			<guid isPermaLink="false">27921@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;After scouring various poll and survey plugins to find what I needed I have decided because of GF's flexibility it's probably best to start with it and go from there. What i'm trying to achieve is a poll of sorts.&#60;/p&#62;
&#60;p&#62;Thanks to this post (&#60;a href=&#34;http://www.gravityhelp.com/forums/topic/getting-values-from-the-database&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/forums/topic/getting-values-from-the-database&#60;/a&#62;) I was able to figure out the way GF stores the data in the wp_rg_lead_detail.&#60;/p&#62;
&#60;p&#62;Here is an example of the the results taken from a simple form that asks what type of person you are and what's your favorite fruit. (Only example material, This site would be extremely boring if this was my goal.)&#60;/p&#62;
&#60;p&#62;id	lead_id	field_number	value&#60;br /&#62;
1	1	       1	               Angry&#60;br /&#62;
2	1	       2	               Apples&#60;br /&#62;
3	2	       1	               Angry&#60;br /&#62;
4	2	       2	               Grapes&#60;br /&#62;
5	3	       1	               Happy&#60;br /&#62;
6	3	       2	               Apples&#60;br /&#62;
7	4	       1	               Sad&#60;br /&#62;
8	4	       2	               Oranges&#60;/p&#62;
&#60;p&#62;For each person type (field_number = 1) I have crated a page and would like to output fruit preferences in percentage format.  Obviously my sql skills are lacking.  Any help would be greatly appreciated.  If there is a better way of doing this please let me know.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
