Solved

Need help with MySQL Query

Posted on 2013-11-02
3
321 Views
Last Modified: 2013-11-03
Hello, I need help with a query issue I'm having.... I've added another column within the cw_ship_method table called "ship_method_exempt". The new column has some list values of...

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co

I know i could normalize the table. I did try doing that but that didn't seem to be pulling the right records as well. I would like to try solving it with the list values instead. Just because I would like to learn how to for one reason and the table won't be expanding at all. I know in normal practices normalizing is recommended though. The part I'm not focusing on is here...

AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')

	SELECT
		Min(r.ship_range_from) AS min_range_from,
		Max(r.ship_range_to) AS max_range_to,
		m.ship_method_id,
		m.ship_method_name,
		m.ship_method_rate,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_calctype,
		m.ship_method_archive
	FROM
		(cw_ship_method_countries c
		INNER JOIN cw_ship_methods m
		ON c.ship_method_country_method_id = m.ship_method_id)
		LEFT JOIN cw_ship_ranges r
		ON m.ship_method_id = r.ship_range_method_id
	<!--- if looking up price by range, return only a single range --->
	WHERE 1=1
	<cfif arguments.match_range>
	AND (r.ship_range_from <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">
		AND r.ship_range_to >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
		<cfif arguments.localcalc_only eq true>OR NOT m.ship_method_calctype = 'localcalc'</cfif>
	</cfif>
	AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')
	GROUP BY
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to
	HAVING (
			((Min(r.ship_range_from) <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (Max(r.ship_range_to) >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)
			) 
			<cfif arguments.localcalc_only eq true>OR (NOT m.ship_method_calctype = 'localcalc' AND c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)</cfif>
			)
		<cfif arguments.ship_method_id gt 0>
		AND m.ship_method_id = <cfqueryparam value="#arguments.ship_method_id#" cfsqltype="cf_sql_integer">
		</cfif>
		AND NOT (m.ship_method_archive = 1)
	ORDER BY
		m.ship_method_sort,
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		Min(r.ship_range_from),
		Max(r.ship_range_to)

Open in new window

0
Comment
Question by:brihol44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39619124
I don'r really understand your question. Can you explain what is the issue? What you would like to get?

Also if possible please minimize your query just to make a minimal example of what is wrong...
0
 

Author Comment

by:brihol44
ID: 39619149
Hello, I want to filter out shipping methods where session.customer_shipping_category eq either "po, re, co". In the newly created column in shipping methods I have the following values to use for NOT pulling shipping methods that eq true to value of session.customer_shipping_category

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co
0
 
LVL 15

Accepted Solution

by:
gplana earned 200 total points
ID: 39619189
Then I think you want something like this:

SELECT *
FROM session
WHERE customer_shipping_category LIKE '%po%' OR customer_shipping_category LIKE '%re%' OR customer_shipping_categoryLIKE '%co%';

Open in new window


Please try it and let me know if this is what you want.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
paypal ipn to mysql 3 106
Very Large data in MYSQL 7 108
what is the best way to connect my database to my new website using php and mysql ? 6 103
SQL Function 4 38
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question